Flow.Launcher/Flow.Launcher.Core/Resource/LocalizedDescriptionAttribute.cs

31 lines
972 B
C#
Raw Permalink Normal View History

using System.ComponentModel;
2025-04-09 05:05:43 +00:00
using CommunityToolkit.Mvvm.DependencyInjection;
using Flow.Launcher.Plugin;
2022-12-21 07:51:17 +00:00
namespace Flow.Launcher.Core.Resource
{
public class LocalizedDescriptionAttribute : DescriptionAttribute
{
2025-04-09 05:05:43 +00:00
// We should not initialize API in static constructor because it will create another API instance
private static IPublicAPI api = null;
private static IPublicAPI API => api ??= Ioc.Default.GetRequiredService<IPublicAPI>();
private readonly string _resourceKey;
public LocalizedDescriptionAttribute(string resourceKey)
{
_resourceKey = resourceKey;
}
public override string Description
{
get
{
2025-04-09 05:05:43 +00:00
string description = API.GetTranslation(_resourceKey);
return string.IsNullOrWhiteSpace(description) ?
string.Format("[[{0}]]", _resourceKey) : description;
}
}
}
}