feat(i18n): add ClaudeDo.Localization project with nested-JSON locale parser
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Using Include="Xunit" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.12.0" />
|
||||
<PackageReference Include="xunit" Version="2.9.3" />
|
||||
<PackageReference Include="xunit.runner.visualstudio" Version="3.0.1" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../../src/ClaudeDo.Localization/ClaudeDo.Localization.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
38
tests/ClaudeDo.Localization.Tests/LocaleJsonTests.cs
Normal file
38
tests/ClaudeDo.Localization.Tests/LocaleJsonTests.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using ClaudeDo.Localization;
|
||||
|
||||
namespace ClaudeDo.Localization.Tests;
|
||||
|
||||
public class LocaleJsonTests
|
||||
{
|
||||
private const string Sample = """
|
||||
{
|
||||
"metadata": { "code": "en", "name": "English" },
|
||||
"settings": { "save": "Save", "general": { "model": "Model" } },
|
||||
"tasks": { "addPlaceholder": "Add a task" }
|
||||
}
|
||||
""";
|
||||
|
||||
[Fact]
|
||||
public void Parse_reads_metadata()
|
||||
{
|
||||
var f = LocaleJson.Parse(Sample);
|
||||
Assert.Equal("en", f.Code);
|
||||
Assert.Equal("English", f.Name);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_flattens_nested_keys_to_dot_paths()
|
||||
{
|
||||
var f = LocaleJson.Parse(Sample);
|
||||
Assert.Equal("Save", f.Strings["settings.save"]);
|
||||
Assert.Equal("Model", f.Strings["settings.general.model"]);
|
||||
Assert.Equal("Add a task", f.Strings["tasks.addPlaceholder"]);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_excludes_metadata_from_strings()
|
||||
{
|
||||
var f = LocaleJson.Parse(Sample);
|
||||
Assert.False(f.Strings.ContainsKey("metadata.code"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user