26 lines
711 B
C#
26 lines
711 B
C#
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
|
|
};
|
|
}
|
|
}
|