feat(i18n): add Avalonia loc:Tr markup extension and LocalizedString

This commit is contained in:
mika kuns
2026-06-03 11:44:16 +02:00
parent 3c40bb5ea3
commit 35ad1715d3
4 changed files with 81 additions and 0 deletions
@@ -0,0 +1,25 @@
using Avalonia.Data;
using Avalonia.Markup.Xaml;
using ClaudeDo.Localization;
namespace ClaudeDo.Ui.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");
return new Binding(nameof(LocalizedString.Value))
{
Source = new LocalizedString(loc, Key),
Mode = BindingMode.OneWay
};
}
}