feat(i18n): add WPF localization primitives and Language config to installer
This commit is contained in:
27
src/ClaudeDo.Installer/Localization/TrExtension.cs
Normal file
27
src/ClaudeDo.Installer/Localization/TrExtension.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Markup;
|
||||
using ClaudeDo.Localization;
|
||||
|
||||
namespace ClaudeDo.Installer.Localization;
|
||||
|
||||
public sealed class TrExtension : MarkupExtension
|
||||
{
|
||||
public TrExtension() { }
|
||||
public TrExtension(string key) => Key = key;
|
||||
|
||||
public string Key { get; set; } = "";
|
||||
|
||||
public static ILocalizer? Localizer { get; set; }
|
||||
|
||||
public override object ProvideValue(IServiceProvider serviceProvider)
|
||||
{
|
||||
var loc = Localizer ?? throw new InvalidOperationException("TrExtension.Localizer not initialized");
|
||||
var binding = new Binding(nameof(LocalizedString.Value))
|
||||
{
|
||||
Source = new LocalizedString(loc, Key),
|
||||
Mode = BindingMode.OneWay
|
||||
};
|
||||
return binding.ProvideValue(serviceProvider);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user