feat(i18n): add LocaleStore folder discovery

This commit is contained in:
mika kuns
2026-06-03 11:38:02 +02:00
parent 9efde2bf88
commit a83a0c41e8
2 changed files with 69 additions and 0 deletions

View File

@@ -0,0 +1,31 @@
namespace ClaudeDo.Localization;
public sealed class LocaleStore
{
private readonly Dictionary<string, LocaleFile> _byCode;
private LocaleStore(Dictionary<string, LocaleFile> byCode) => _byCode = byCode;
public IReadOnlyList<LocaleFile> Available => _byCode.Values.ToList();
public bool TryGet(string code, out LocaleFile? file) => _byCode.TryGetValue(code, out file);
public static LocaleStore Load(string folder)
{
var byCode = new Dictionary<string, LocaleFile>(StringComparer.OrdinalIgnoreCase);
if (Directory.Exists(folder))
{
foreach (var path in Directory.EnumerateFiles(folder, "*.json"))
{
try
{
var file = LocaleJson.Parse(File.ReadAllText(path));
if (!string.IsNullOrWhiteSpace(file.Code))
byCode[file.Code] = file;
}
catch { /* skip malformed locale files */ }
}
}
return new LocaleStore(byCode);
}
}