fix(i18n): plural forms for every text that counts
Findings, advisor reasons and a few UI texts put a count before a plural noun without plural forms, so English and Italian read "1 frames are black". Each such key is now a plural stem (.one/.other) whose count is its first argument; findings and reasons, which travel as data, resolve through the new Loc.Text, which picks the form from that argument (a fraction takes "other"), so stored deep reports and project reasons keep their keys and arguments. Texts with two or more counts (job log lines, "frames with a capture time: 12 of 300") read as labels, which agree with no number. A single exposure change gets its own finding instead of "1 exposure changes, typically 0 frames apart". The converted and reworded keys leave the 36 other catalogs until they are translated again; the dead plain Shell.JobBar.Ready goes too. `i18n check` now fails on an English text that counts a noun without plural forms. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
242 files changed
+348
-2036
No files matched your search
@@ -876,7 +876,7 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
|
||||
var markers = new List<TimelineMarker>(StepMarkers(content));
|
||||
foreach (var finding in Session.Advice.Findings.Where(f => f.Severity >= FindingSeverity.Warning))
|
||||
{
|
||||
var text = Loc.L(finding.Key, finding.Arguments);
|
||||
var text = Loc.Text(finding.Key, finding.Arguments);
|
||||
markers.AddRange(finding.Frames.Take(64).Select(i => new TimelineMarker(i, finding.Severity == FindingSeverity.Error ? MarkerKind.Error : MarkerKind.Warning, text)));
|
||||
}
|
||||
markers.AddRange(Session.Project.Camera.Keyframes.Select(k => new TimelineMarker(k.Frame, MarkerKind.Keyframe, Loc.L("Editor.Marker.Keyframe"))));
|
||||
|
||||
@@ -290,7 +290,7 @@ public sealed class FramesTab : EditorTab
|
||||
FindingSeverity.Warning => StatusKind.Warning,
|
||||
_ => StatusKind.NotAnalysed,
|
||||
},
|
||||
Loc.L(finding.Key, finding.Arguments),
|
||||
Loc.Text(finding.Key, finding.Arguments),
|
||||
finding.Frames.Count > 0 ? finding.Frames[0] : null);
|
||||
|
||||
private void ToggleExcluded(int index) => Editor.Session.SetExcluded([index], !IsExcluded(index));
|
||||
|
||||
@@ -364,7 +364,7 @@ public sealed class SettingsViewModel : SectionViewModel
|
||||
|
||||
public bool IsParallelismAuto => _s.Parallelism is null;
|
||||
|
||||
public string CoresText => Loc.L("Settings.Rendering.Cores", LogicalCores);
|
||||
public string CoresText => Loc.Plural("Settings.Rendering.Cores", LogicalCores);
|
||||
|
||||
public string ParallelismAutoText => Loc.L("Settings.Rendering.AutoValue", ParallelismAuto);
|
||||
|
||||
|
||||
@@ -149,7 +149,7 @@ public sealed class SyncTableViewModel : ObservableObject, IDisposable
|
||||
!IsActive ? Loc.L("Tooltips.Server.Sync.UploadAll.NotConnected")
|
||||
: !Rights.CanUpload ? Loc.L("Tooltips.Server.Sync.UploadAll.NoRight")
|
||||
: !LocalOnly.Any() ? Loc.L("Tooltips.Server.Sync.UploadAll.Nothing")
|
||||
: Loc.L("Tooltips.Server.Sync.UploadAll", Formatting.Count(LocalOnly.Count()), Formatting.Bytes(LocalOnly.Sum(e => e.Local!.TotalBytes)));
|
||||
: Loc.Plural("Tooltips.Server.Sync.UploadAll", LocalOnly.Count(), Formatting.Bytes(LocalOnly.Sum(e => e.Local!.TotalBytes)));
|
||||
|
||||
/// <summary>"Last sync 10:15 · manifest diff 0.4 s"; null before the first comparison.</summary>
|
||||
public string? LastSyncText => Host.Agent?.Snapshot is { } s
|
||||
|
||||
@@ -75,7 +75,7 @@ public static class Advisor
|
||||
public static string Explain(Recommendation recommendation)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(recommendation);
|
||||
return Loc.L(recommendation.ReasonKey, [.. recommendation.ReasonArgs]);
|
||||
return Loc.Text(recommendation.ReasonKey, [.. recommendation.ReasonArgs]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -86,6 +86,6 @@ public static class Advisor
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(reasonKey);
|
||||
var args = (reasonArgs ?? []).Select(a => double.TryParse(a, NumberStyles.Float, CultureInfo.InvariantCulture, out var number) ? (object)number : a).ToArray();
|
||||
return Loc.L(reasonKey, args);
|
||||
return Loc.Text(reasonKey, args);
|
||||
}
|
||||
}
|
||||
@@ -94,7 +94,8 @@ public static class AdvisorParameters
|
||||
/// <summary>
|
||||
/// One advisor decision (BRIEF §10.3). <see cref="Value"/> is null when data is missing; the reason then says what is
|
||||
/// missing and nothing is changed. <see cref="ReasonArgs"/> are numbers (already rounded for display) or plain tokens,
|
||||
/// formatted by the caller with its culture: <c>Loc.L(ReasonKey, [.. ReasonArgs])</c>.
|
||||
/// formatted by the caller with its culture: <c>Loc.Text(ReasonKey, [.. ReasonArgs])</c>. A reason that counts something is a
|
||||
/// plural stem whose count is the first argument.
|
||||
/// </summary>
|
||||
/// <param name="Confidence">0..1: how strongly the measurements support the value.</param>
|
||||
public sealed record Recommendation(
|
||||
|
||||
@@ -9,7 +9,9 @@ public enum FindingSeverity
|
||||
|
||||
/// <summary>
|
||||
/// One explainable analysis result. <see cref="Key"/> is a stable resource key (e.g. <c>Advisor.Finding.Gaps</c>)
|
||||
/// whose localised text is a composite format filled with <see cref="Arguments"/> (<c>Loc.L(Key, Arguments)</c>).
|
||||
/// whose localised text is a composite format filled with <see cref="Arguments"/> (<c>Loc.Text(Key, Arguments)</c>).
|
||||
/// A finding that counts frames, gaps or changes has a plural stem as its key (<c>Key.one</c>, <c>Key.other</c>, BRIEF
|
||||
/// §16) and carries that count as its first argument, which picks the form.
|
||||
/// </summary>
|
||||
/// <param name="Frames">Indices of the frames concerned (capped at <see cref="MaxFrames"/>).</param>
|
||||
public sealed record Finding(string Key, FindingSeverity Severity, object[] Arguments, IReadOnlyList<int> Frames)
|
||||
@@ -28,6 +30,7 @@ public static class FindingKeys
|
||||
public const string NonMonotonicTimestamps = "Advisor.Finding.NonMonotonicTimestamps";
|
||||
public const string ClockJumps = "Advisor.Finding.ClockJumps";
|
||||
public const string ExposureSteps = "Advisor.Finding.ExposureSteps";
|
||||
public const string ExposureStep = "Advisor.Finding.ExposureStep";
|
||||
public const string MissingExposure = "Advisor.Finding.MissingExposure";
|
||||
public const string CameraChanged = "Advisor.Finding.CameraChanged";
|
||||
public const string LensChanged = "Advisor.Finding.LensChanged";
|
||||
|
||||
@@ -259,7 +259,10 @@ public static class LightAnalyzer
|
||||
for (var i = 1; i < steps.Count; i++) distances[i - 1] = steps[i].Index - steps[i - 1].Index;
|
||||
typical = Statistics.Median(distances);
|
||||
}
|
||||
if (steps.Count > 0)
|
||||
// A single change has no spacing to report.
|
||||
if (steps.Count == 1)
|
||||
findings.Add(new Finding(FindingKeys.ExposureStep, FindingSeverity.Info, [steps[0].DeltaEv], [steps[0].Index]));
|
||||
else if (steps.Count > 1)
|
||||
{
|
||||
var total = steps.Sum(s => s.DeltaEv);
|
||||
findings.Add(new Finding(FindingKeys.ExposureSteps, FindingSeverity.Info, [steps.Count, typical ?? 0, total], Cap(steps.Select(s => s.Index))));
|
||||
|
||||
@@ -67,8 +67,7 @@ public static class Loc
|
||||
/// </summary>
|
||||
public static string Plural(string key, long count, params object?[] args)
|
||||
{
|
||||
var category = PluralRules.Select(_culture, count);
|
||||
var format = Get(key + "." + PluralRules.Suffix(category), _culture) ?? Get(key + ".other", _culture);
|
||||
var format = PluralForm(key, PluralRules.Select(_culture, count), _culture);
|
||||
if (format is null) return Missing(key);
|
||||
var all = new object?[args.Length + 1];
|
||||
all[0] = count;
|
||||
@@ -76,6 +75,24 @@ public static class Loc
|
||||
return string.Format(_culture, format, all);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Text of a key that travels as data with its arguments (analysis findings, advisor reasons): a plain key reads like
|
||||
/// <see cref="L(string, object?[])"/>; a plural stem takes the form of its count, which is always the first argument
|
||||
/// (<c>{0}</c>, as in <see cref="Plural"/>). A count with a fraction ("1.5 frames") takes the <c>other</c> form.
|
||||
/// </summary>
|
||||
public static string Text(string key, IReadOnlyList<object?> args) => Text(key, args, _culture);
|
||||
|
||||
/// <inheritdoc cref="Text(string, IReadOnlyList{object?})"/>
|
||||
public static string Text(string key, IReadOnlyList<object?> args, CultureInfo culture)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(args);
|
||||
ArgumentNullException.ThrowIfNull(culture);
|
||||
var format = Get(key, culture);
|
||||
if (format is null && args.Count > 0) format = PluralForm(key, Category(culture, args[0]), culture);
|
||||
if (format is null) return Missing(key);
|
||||
return args.Count == 0 ? format : string.Format(culture, format, [.. args]);
|
||||
}
|
||||
|
||||
/// <summary>Looks a key up in a specific culture (falls back to parents and English); null when absent.</summary>
|
||||
public static string? Get(string key, CultureInfo culture)
|
||||
{
|
||||
@@ -123,6 +140,17 @@ public static class Loc
|
||||
return result;
|
||||
}
|
||||
|
||||
private static string? PluralForm(string key, PluralCategory category, CultureInfo culture) =>
|
||||
Get(key + "." + PluralRules.Suffix(category), culture) ?? Get(key + ".other", culture);
|
||||
|
||||
/// <summary>The plural category of a count passed as data: any number type; anything else reads as <c>other</c>.</summary>
|
||||
private static PluralCategory Category(CultureInfo culture, object? count)
|
||||
{
|
||||
if (count is not IConvertible number || number.GetTypeCode() is < TypeCode.SByte or > TypeCode.Decimal) return PluralCategory.Other;
|
||||
var value = number.ToDouble(CultureInfo.InvariantCulture);
|
||||
return double.IsInteger(value) ? PluralRules.Select(culture, (long)value) : PluralCategory.Other;
|
||||
}
|
||||
|
||||
private static string Missing(string key)
|
||||
{
|
||||
MissingKey?.Invoke(key);
|
||||
|
||||
@@ -54,6 +54,8 @@ internal sealed partial class I18nCommand : ICommand
|
||||
errors.Add($"en: {key} is {entry.Value.Length} chars (budget {limit})");
|
||||
if (string.IsNullOrWhiteSpace(entry.Value))
|
||||
errors.Add($"en: {key} is empty");
|
||||
if (CountedNoun(key, entry.Value) is { } noun)
|
||||
errors.Add($"en: {key} counts {noun} but is not a plural stem: write {key}.one and {key}.other with the count as {{0}}, or a label (\"Frames: {{0}}\")");
|
||||
}
|
||||
|
||||
foreach (var (culture, strings) in catalog.Cultures)
|
||||
@@ -124,6 +126,21 @@ internal sealed partial class I18nCommand : ICommand
|
||||
warnings.Add($"{culture}: {key} is {translated.Value.Length} chars (soft budget {limit})");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The noun a plain (non-plural) English value counts with a number in front of it ("{0} frames", "{0} short gaps"):
|
||||
/// such a key reads "1 frames", and Italian or Slavic forms cannot follow the number either (BRIEF §16). Bounds the code
|
||||
/// sets ("at most {0} characters") and labels ("Frames: {0}") count nothing; null when the value counts nothing.
|
||||
/// </summary>
|
||||
internal static string? CountedNoun(string key, string value)
|
||||
{
|
||||
if (PluralSuffix().IsMatch(key[(key.LastIndexOf('.') + 1)..])) return null;
|
||||
foreach (Match m in CountedNounRegex().Matches(value))
|
||||
{
|
||||
if (!m.Groups["bound"].Success) return m.Groups["noun"].Value;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>The English <c>other</c> form when <paramref name="key"/> is a plural form of an English plural key.</summary>
|
||||
private static Entry? PluralStem(string key, Dictionary<string, Entry> en)
|
||||
{
|
||||
@@ -292,6 +309,13 @@ internal sealed partial class I18nCommand : ICommand
|
||||
[GeneratedRegex(@"^(one|few|many|other)$")]
|
||||
private static partial Regex PluralSuffix();
|
||||
|
||||
/// <summary>A placeholder, up to two describing words that are not function words, then a noun the product counts.</summary>
|
||||
[GeneratedRegex(@"(?<bound>\b(?i:at least|at most|up to|to)\s+)?\{\d+(?:[,:][^}]*)?\}(?:\s+(?!(?:and|or|of|the|a|an|to|on|in|at|by|for|with|from|is|are|was|were)\b)[a-z]+){0,2}?\s+"
|
||||
+ @"(?<noun>frames|photos|sequences|files|folders|exports|renders|jobs|times|gaps|sessions|changes|steps|warnings|cores|days|hours|minutes|"
|
||||
+ @"items|cards|tags|users|accounts|nodes|presets|characters|originals|copies|groups|issues|cameras|lenses|uploads|downloads|transfers|"
|
||||
+ @"keyframes|encoders|errors|problems|duplicates|locks|packs|flags|lines|months|years|previews|settings|versions|workers|stars|rows|chunks)\b")]
|
||||
private static partial Regex CountedNounRegex();
|
||||
|
||||
internal sealed record Entry(string File, string Value, string? Comment);
|
||||
|
||||
internal sealed class Catalog
|
||||
|
||||
Reference in new issue
Block a user