Local-mode composition root (SQLite index, one JobEngine fed by a single handler registration list), keyset-paged library with thumbnail cache and hover scrub, live job list with throttled updates and the shell job bar, settings with live template validation and encoder self-test, server connection with trust-on-first-use and DPAPI token, first-run welcome, About with update check, and --capture screenshots with synthetic data. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
63 lines
2.5 KiB
C#
63 lines
2.5 KiB
C#
using System.Globalization;
|
|
using System.Resources;
|
|
using Titano.Core.Localization;
|
|
|
|
namespace Titano.App.Settings;
|
|
|
|
/// <summary>A language of the language pickers: culture code and its own name ("Italiano").</summary>
|
|
public sealed record LanguageOption(string Code, string Name);
|
|
|
|
/// <summary>
|
|
/// The languages this build ships (BRIEF §16): English plus every language of <see cref="Languages.Shipped"/> whose
|
|
/// resources are compiled in. Languages announced for later phases appear as soon as their resources exist, and
|
|
/// never before (a picker entry that shows English text would mislead).
|
|
/// </summary>
|
|
public static class LanguageCatalog
|
|
{
|
|
private static readonly Lazy<IReadOnlyList<LanguageOption>> Detected = new(Detect);
|
|
|
|
/// <summary>Available languages, English first, then by native name.</summary>
|
|
public static IReadOnlyList<LanguageOption> Available => Detected.Value;
|
|
|
|
/// <summary>True when the satellite resources of <paramref name="code"/> exist.</summary>
|
|
public static bool HasResources(string code)
|
|
{
|
|
if (code.Equals("en", StringComparison.OrdinalIgnoreCase)) return true;
|
|
var manager = new ResourceManager("Titano.Core.i18n.Common", typeof(Loc).Assembly);
|
|
try
|
|
{
|
|
return manager.GetResourceSet(CultureInfo.GetCultureInfo(code), createIfNotExists: true, tryParents: false) is not null;
|
|
}
|
|
catch (MissingManifestResourceException)
|
|
{
|
|
return false;
|
|
}
|
|
catch (CultureNotFoundException)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
/// <summary>The option matching <paramref name="culture"/> (or its parent), English when none does.</summary>
|
|
public static LanguageOption Match(CultureInfo culture)
|
|
{
|
|
for (var c = culture; !Equals(c, CultureInfo.InvariantCulture); c = c.Parent)
|
|
{
|
|
var hit = Available.FirstOrDefault(o => o.Code.Equals(c.Name, StringComparison.OrdinalIgnoreCase));
|
|
if (hit is not null) return hit;
|
|
}
|
|
return Available[0];
|
|
}
|
|
|
|
private static IReadOnlyList<LanguageOption> Detect()
|
|
{
|
|
var found = Languages.Shipped
|
|
.Where(code => !code.Equals("en", StringComparison.OrdinalIgnoreCase) && HasResources(code))
|
|
.Select(code => new LanguageOption(code, Languages.NativeName(code)))
|
|
.OrderBy(o => o.Name, StringComparer.CurrentCultureIgnoreCase)
|
|
.ToList();
|
|
found.Insert(0, new LanguageOption("en", Languages.NativeName("en")));
|
|
return found;
|
|
}
|
|
}
|