Flow.Launcher/Flow.Launcher.Core/Resource/TranslationConverter.cs

26 lines
926 B
C#
Raw Normal View History

2022-11-07 12:04:13 +00:00
using System;
using System.Globalization;
using System.Windows.Data;
2025-04-09 05:05:43 +00:00
using CommunityToolkit.Mvvm.DependencyInjection;
using Flow.Launcher.Plugin;
2022-11-07 12:04:13 +00:00
2022-12-21 07:50:41 +00:00
namespace Flow.Launcher.Core.Resource
2022-11-07 12:04:13 +00:00
{
2022-12-21 07:50:41 +00:00
public class TranslationConverter : IValueConverter
2022-11-07 12:04:13 +00:00
{
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>();
2022-11-07 12:04:13 +00:00
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var key = value.ToString();
2025-04-09 05:05:43 +00:00
if (string.IsNullOrEmpty(key)) return key;
return API.GetTranslation(key);
2022-11-07 12:04:13 +00:00
}
2025-04-09 05:05:43 +00:00
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) =>
throw new InvalidOperationException();
2022-11-07 12:04:13 +00:00
}
}