28 lines
800 B
C#
28 lines
800 B
C#
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);
|
|
}
|
|
}
|