mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
25 lines
926 B
C#
25 lines
926 B
C#
using System;
|
|
using System.Globalization;
|
|
using System.Windows.Data;
|
|
using CommunityToolkit.Mvvm.DependencyInjection;
|
|
using Flow.Launcher.Plugin;
|
|
|
|
namespace Flow.Launcher.Core.Resource
|
|
{
|
|
public class TranslationConverter : IValueConverter
|
|
{
|
|
// 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>();
|
|
|
|
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
|
{
|
|
var key = value.ToString();
|
|
if (string.IsNullOrEmpty(key)) return key;
|
|
return API.GetTranslation(key);
|
|
}
|
|
|
|
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) =>
|
|
throw new InvalidOperationException();
|
|
}
|
|
}
|