feat(i18n): add WPF localization primitives and Language config to installer
This commit is contained in:
@@ -46,6 +46,9 @@
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ClaudeDo.Data\ClaudeDo.Data.csproj" />
|
||||
<ProjectReference Include="..\ClaudeDo.Releases\ClaudeDo.Releases.csproj" />
|
||||
<ProjectReference Include="..\ClaudeDo.Localization\ClaudeDo.Localization.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Import Project="..\ClaudeDo.Localization\Locales.targets" />
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -77,6 +77,7 @@ public sealed class InstallerAppSettings
|
||||
{
|
||||
public string DbPath { get; set; } = "~/.todo-app/todo.db";
|
||||
public string SignalRUrl { get; set; } = "http://127.0.0.1:47821/hub";
|
||||
public string Language { get; set; } = "";
|
||||
|
||||
private static readonly JsonSerializerOptions ReadOpts = new()
|
||||
{
|
||||
|
||||
22
src/ClaudeDo.Installer/Localization/LocalizedString.cs
Normal file
22
src/ClaudeDo.Installer/Localization/LocalizedString.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System.ComponentModel;
|
||||
using ClaudeDo.Localization;
|
||||
|
||||
namespace ClaudeDo.Installer.Localization;
|
||||
|
||||
public sealed class LocalizedString : INotifyPropertyChanged
|
||||
{
|
||||
private readonly ILocalizer _localizer;
|
||||
private readonly string _key;
|
||||
|
||||
public LocalizedString(ILocalizer localizer, string key)
|
||||
{
|
||||
_localizer = localizer;
|
||||
_key = key;
|
||||
_localizer.LanguageChanged += (_, _) =>
|
||||
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(Value)));
|
||||
}
|
||||
|
||||
public string Value => _localizer[_key];
|
||||
|
||||
public event PropertyChangedEventHandler? PropertyChanged;
|
||||
}
|
||||
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