mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
- Create Internationalization service that parses WPF XAML language files - Load translations from main Languages/ folder and all plugin Languages/ folders - Add LocalizeExtension markup extension and Translator helper for XAML/code - Fix IPublicAPI.GetTranslation to use the i18n service for plugin context menus - Update MainWindow to use localized placeholder text
28 lines
894 B
C#
28 lines
894 B
C#
using Avalonia.Data.Converters;
|
|
using System;
|
|
using System.Globalization;
|
|
|
|
namespace Flow.Launcher.Avalonia.Resource;
|
|
|
|
/// <summary>
|
|
/// Converter to translate a key to its localized string in XAML bindings.
|
|
/// Usage: Text="{Binding Key, Converter={StaticResource TranslationConverter}}"
|
|
/// Or simpler: Use the Translator.GetString(key) helper from code-behind
|
|
/// </summary>
|
|
public class TranslationConverter : IValueConverter
|
|
{
|
|
public object Convert(object? value, Type targetType, object? parameter, CultureInfo? culture)
|
|
{
|
|
if (value is string key && !string.IsNullOrEmpty(key))
|
|
{
|
|
return Translator.GetString(key);
|
|
}
|
|
|
|
return parameter?.ToString() ?? "[No Translation]";
|
|
}
|
|
|
|
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo? culture)
|
|
{
|
|
throw new NotSupportedException();
|
|
}
|
|
}
|