Merge branch 'fix/app-fixes': localized error toasts, plural counts, archive and import view-model fixes
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
303 files changed
+968
-2234
No files matched your search
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user