feat(i18n): add Avalonia loc:Tr markup extension and LocalizedString
This commit is contained in:
33
tests/ClaudeDo.Ui.Tests/LocalizedStringTests.cs
Normal file
33
tests/ClaudeDo.Ui.Tests/LocalizedStringTests.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using ClaudeDo.Localization;
|
||||
using ClaudeDo.Ui.Localization;
|
||||
|
||||
namespace ClaudeDo.Ui.Tests;
|
||||
|
||||
public class LocalizedStringTests
|
||||
{
|
||||
private static Localizer Make()
|
||||
{
|
||||
var dir = Path.Combine(Path.GetTempPath(), "loc_" + Guid.NewGuid().ToString("N"));
|
||||
Directory.CreateDirectory(dir);
|
||||
File.WriteAllText(Path.Combine(dir, "en.json"),
|
||||
"""{ "metadata": { "code": "en", "name": "English" }, "settings": { "save": "Save" } }""");
|
||||
File.WriteAllText(Path.Combine(dir, "de.json"),
|
||||
"""{ "metadata": { "code": "de", "name": "Deutsch" }, "settings": { "save": "Speichern" } }""");
|
||||
return new Localizer(LocaleStore.Load(dir), "en");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Value_tracks_language_change()
|
||||
{
|
||||
var loc = Make();
|
||||
var ls = new LocalizedString(loc, "settings.save");
|
||||
Assert.Equal("Save", ls.Value);
|
||||
|
||||
string? changed = null;
|
||||
ls.PropertyChanged += (_, e) => { if (e.PropertyName == nameof(LocalizedString.Value)) changed = ls.Value; };
|
||||
|
||||
loc.SetLanguage("de");
|
||||
Assert.Equal("Speichern", ls.Value);
|
||||
Assert.Equal("Speichern", changed);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user