feat(i18n): export, render and encoder messages; check keys passed as data

Adds the Export catalog (en, it) for preset names, plan and render
warnings and encoder notices. i18n check now treats C# string literals
shaped Area.Group.Name with an existing area as used keys, which is how
these 53 keys had gone unnoticed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-02 12:26:18 +00:00
1 parent f78a76513c
commit 87c70eef4e
3 files changed
+136 -3

No files matched your search

+16 -3
View File
@@ -80,7 +80,8 @@ internal sealed partial class I18nCommand : ICommand
errors.Add($"{culture}: orphan key {key}");
}
foreach (var (file, key) in UsedKeys(root))
var areas = en.Keys.Select(k => k[..k.IndexOf('.')]).ToHashSet(StringComparer.Ordinal);
foreach (var (file, key) in UsedKeys(root, areas))
{
if (en.ContainsKey(key)) continue;
// Prefix lookups such as L("Settings.Page." + page) are satisfied by any key under the prefix.
@@ -133,8 +134,12 @@ internal sealed partial class I18nCommand : ICommand
private static HashSet<string> Placeholders(string s) =>
[.. PlaceholderRegex().Matches(s).Select(m => m.Groups[1].Value)];
/// <summary>Keys referenced from C# (<c>L("…")</c>, <c>Plural("…")</c>, <c>Loc.Get("…")</c>), XAML (<c>{l:Loc …}</c>) and admin JS (<c>t("…")</c>).</summary>
private static IEnumerable<(string File, string Key)> UsedKeys(string root)
/// <summary>
/// Keys referenced from C# (<c>L("…")</c>, <c>Plural("…")</c>, <c>Loc.Get("…")</c>, and any string literal shaped
/// <c>Area.Group.Name</c> whose area has a catalog, since reason and warning keys travel as data), XAML
/// (<c>{l:Loc …}</c>) and admin JS (<c>t("…")</c>).
/// </summary>
private static IEnumerable<(string File, string Key)> UsedKeys(string root, IReadOnlySet<string> areas)
{
var src = Path.Combine(root, "src");
foreach (var file in Directory.EnumerateFiles(src, "*.*", SearchOption.AllDirectories))
@@ -152,6 +157,11 @@ internal sealed partial class I18nCommand : ICommand
if (regex is null) continue;
var text = File.ReadAllText(file);
foreach (Match m in regex.Matches(text)) yield return (file, m.Groups[1].Value);
if (ext != ".cs") continue;
foreach (Match m in CsKeyLiteralRegex().Matches(text))
{
if (areas.Contains(m.Groups[2].Value)) yield return (file, m.Groups[1].Value);
}
}
}
@@ -161,6 +171,9 @@ internal sealed partial class I18nCommand : ICommand
[GeneratedRegex(@"\b(?:L|Plural|Loc\.Get|LocKey)\(\s*""([A-Z][A-Za-z0-9]*\.[A-Za-z0-9_.]+)""")]
private static partial Regex CsKeyRegex();
[GeneratedRegex(@"(?<![@$\w])""(([A-Z][A-Za-z0-9]*)\.[A-Z][A-Za-z0-9]*\.[A-Za-z0-9_.]+)""")]
private static partial Regex CsKeyLiteralRegex();
[GeneratedRegex(@"\{(?:l|loc):Loc\s+(?:Key=)?([A-Z][A-Za-z0-9]*\.[A-Za-z0-9_.]+)")]
private static partial Regex XamlKeyRegex();