A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.
UI: read a translations/ language's UI strings, Romanian not offered yet (Refs #1606) (#2346)
Berie7eb1f22c4dd
diff --git a/changelog.d/1606-romanian-picker.md b/changelog.d/1606-romanian-picker.mdnew file mode 100644index 000000000..bc9cc956b--- /dev/null+++ b/changelog.d/1606-romanian-picker.md@@ -0,0 +1,5 @@+- The game can now show a language from `translations/` (#1606): its UI strings are its `ui.yaml` over the English, one+ string at a time, and a stored choice of it is kept like English and Hebrew. Romanian is not offered yet: it stays out+ of the language buttons until more of it is translated.+- A new language's `ui.yaml` may not translate the encyclopedia (`encyclopedia.*`) either: like the advisors, it stays+ English or Hebrew for now (#1606).diff --git a/sim/Statecraft.Sim.Tests/TranslationLoaderTests.cs b/sim/Statecraft.Sim.Tests/TranslationLoaderTests.csindex 1186c1bb9..152fb4ecb 100644--- a/sim/Statecraft.Sim.Tests/TranslationLoaderTests.cs+++ b/sim/Statecraft.Sim.Tests/TranslationLoaderTests.cs@@ -171,6 +171,7 @@ public class TranslationLoaderTests[Theory][InlineData("advisor.defeat_economy")][InlineData("how_to_play.title")]+ [InlineData("encyclopedia.title")]public void OnlyHebrewTranslatesTheAdvisorsAndHowToPlay(string key){var e = Refused(new Dictionary<string, string> { ["ro/ui.yaml"] = Ro + $"{key}: \"x\"\n" });diff --git a/sim/Statecraft.Sim/TranslationLoader.cs b/sim/Statecraft.Sim/TranslationLoader.csindex 71dc881e3..187c2f3d3 100644--- a/sim/Statecraft.Sim/TranslationLoader.cs+++ b/sim/Statecraft.Sim/TranslationLoader.cs@@ -17,8 +17,10 @@ namespace Statecraft.Simstatic readonly string[] LanguageFiles = { Translations.UiFile, Translations.EventsFile, Translations.ContentFile };- /// <summary>UI keys only Hebrew may translate, for now (owner, 24 October 2026, #1604): the advisors and How to play.</summary>- public static readonly IReadOnlyList<string> HebrewOnlyUi = new[] { "advisor.", "how_to_play." };+ /// <summary>UI keys only Hebrew may translate, for now (owner, 24 October 2026, #1604): the advisors and How to play, and+ /// the encyclopedia that replaced How to play (#1606: once the game shows a translated ui.yaml, this is what keeps it+ /// English or Hebrew, as translations/README.md and tools/translate.py already treat it).</summary>+ public static readonly IReadOnlyList<string> HebrewOnlyUi = new[] { "advisor.", "how_to_play.", "encyclopedia." };/// <summary>translations/ beside a folder named content: the repository's beside content/, StreamingAssets/translations/// beside StreamingAssets/content. Null for a content folder with another name, such as a test fixture, so a fixturediff --git a/unity/Assets/Scripts/UI/GameRoot.cs b/unity/Assets/Scripts/UI/GameRoot.csindex ab9b5c596..ddfbf28ee 100644--- a/unity/Assets/Scripts/UI/GameRoot.cs+++ b/unity/Assets/Scripts/UI/GameRoot.cs@@ -188,9 +188,17 @@ namespace Statecraft.Game.UIline.languageDirection = !hebrew ? LanguageDirection.Inherit : UiDirection.RightToLeft(words) ? LanguageDirection.RTL : LanguageDirection.LTR;}- /// <summary>The strings of the UI's language (UiLanguage): strings.he.yaml when Hebrew is asked for or chosen, else English.</summary>- UiText Strings() => (Language ?? UiLanguage.AtStart(SettingsFile()?.Read(SettingsPresenter.LanguageKey))) == UiLanguage.Hebrew- ? UiText.Parse(stringsHe.text, "strings.he.yaml") : UiText.Parse(strings.text);+ /// <summary>The strings of the UI's language (UiLanguage): strings.he.yaml when Hebrew is asked for or chosen; a language+ /// from translations/ (#1606) as its ui.yaml over the English, per string, once <paramref name="content"/> carries it+ /// (before the content loads, the loading line is English); else English.</summary>+ UiText Strings(Content? content = null)+ {+ var language = Language ?? UiLanguage.AtStart(SettingsFile()?.Read(SettingsPresenter.LanguageKey));+ if (language == UiLanguage.Hebrew) return UiText.Parse(stringsHe.text, "strings.he.yaml");+ var english = UiText.Parse(strings.text);+ var set = language == UiLanguage.English ? null : content?.Translations.Find(t => t.Lang == language);+ return set == null ? english : english.Over(set.Ui, $"translations/{language}/ui.yaml");+ }void OnDisable(){@@ -262,7 +270,7 @@ namespace Statecraft.Game.UIShutdown(keepCompanionPage: companion != null && CompanionWanted());smokeRun = smoke > 0;- var text = Strings();+ var text = Strings(inputs.Content);var store = Store ?? SaveStore.ForPlatform();var notes = new List<string>();// A smoke run is reproducible: a fresh game with the golden seed, never the player's autosave.diff --git a/unity/Assets/Scripts/UI/LanguageButtons.cs b/unity/Assets/Scripts/UI/LanguageButtons.csindex efde318b9..1e4d5f1ce 100644--- a/unity/Assets/Scripts/UI/LanguageButtons.cs+++ b/unity/Assets/Scripts/UI/LanguageButtons.cs@@ -13,7 +13,9 @@ namespace Statecraft.Game.UI/// new language is one more entry in All and a button named for it in each place in Game.uxml.</summary>public sealed class LanguageButtons : IDisposable{- /// <summary>Each language's code and its name in itself.</summary>+ /// <summary>Each language's code and its name in itself. Romanian (translations/ro) is left out on purpose until more of+ /// it is translated (owner, 3 Nov 2026, #1606: "Hide until more is translated"). The game already reads its strings+ /// (GameRoot.Strings), so offering it is ("ro", "Română") here and a button for it in each place in Game.uxml.</summary>public static readonly (string language, string name)[] All = { (UiLanguage.English, "English"), (UiLanguage.Hebrew, "עברית") };readonly (Button button, string language, Action pick)[] buttons;diff --git a/unity/Assets/Scripts/UI/UiLanguage.cs b/unity/Assets/Scripts/UI/UiLanguage.csindex ce5d22801..96526daac 100644--- a/unity/Assets/Scripts/UI/UiLanguage.cs+++ b/unity/Assets/Scripts/UI/UiLanguage.cs@@ -7,7 +7,9 @@ namespace Statecraft.Game.UI{/// <summary>The UI's language (#193): English unless Hebrew is asked for, "?lang=he" in the page URL on WebGL or/// "-lang he" on the desktop command line, or chosen in Settings (#1036, kept in settings.txt). The content text- /// (events, names) is English only until #55. Any other value, or a bare flag, is English.</summary>+ /// (events, names) is English only until #55. Any other value, or a bare flag, is English. A language from translations/+ /// (#1606) is kept like the others once the language buttons offer it (LanguageButtons.All); its UI strings come from+ /// its translations/<lang>/ui.yaml over the English, per string (GameRoot.Strings).</summary>public static class UiLanguage{public const string Flag = "lang";@@ -23,11 +25,12 @@ namespace Statecraft.Game.UIstatic readonly Regex AnyQuery = new Regex(@"[?&]" + Flag + @"(?:=[^&#]*)?(?=&|#|$)", RegexOptions.CultureInvariant);/// <summary>The language at start (#1036): a flag in the address or on the command line (the store page's "?lang=he"- /// link) holds for that visit, over the choice <paramref name="stored"/> in Settings; with neither, English.</summary>+ /// link) holds for that visit, over the choice <paramref name="stored"/> in Settings; with neither, English. A stored+ /// value the language buttons do not offer is English too.</summary>public static string AtStart(string? stored, string? url, string[] args, bool webgl){bool flag = webgl ? AnyQuery.IsMatch(Boot.UrlFlags.BeforeFragment(url)) : Array.IndexOf(args, "-" + Flag) >= 0;- return flag ? Requested(url, args, webgl) : stored == Hebrew ? Hebrew : English;+ return flag ? Requested(url, args, webgl) : Array.Exists(LanguageButtons.All, l => l.language == stored) ? stored! : English;}public static string Requested(string? url, string[] args, bool webgl)diff --git a/unity/Assets/Scripts/UI/UiText.cs b/unity/Assets/Scripts/UI/UiText.csindex 438cb568a..d58312536 100644--- a/unity/Assets/Scripts/UI/UiText.cs+++ b/unity/Assets/Scripts/UI/UiText.cs@@ -33,6 +33,15 @@ namespace Statecraft.Game.UIreturn new UiText(m, file);}+ /// <summary>These strings with <paramref name="lines"/> (a translations/<lang>/ui.yaml, #1606) over them: a key the+ /// translation has reads its text, every other key the text here, so a new language falls back to English per string.</summary>+ public UiText Over(IEnumerable<KeyValuePair<string, string>> lines, string file)+ {+ var m = new Dictionary<string, string>(map);+ foreach (var line in lines) m[line.Key] = line.Value;+ return new UiText(m, file);+ }+/// <summary>True when the strings have <paramref name="key"/> (a lookup that must not throw, as GameStart's fallback).</summary>public bool Has(string key) => map.ContainsKey(key);diff --git a/unity/Assets/Tests/EditMode/HebrewUiTests.cs b/unity/Assets/Tests/EditMode/HebrewUiTests.csindex f8c40083a..b53f4f9e3 100644--- a/unity/Assets/Tests/EditMode/HebrewUiTests.cs+++ b/unity/Assets/Tests/EditMode/HebrewUiTests.cs@@ -884,6 +884,67 @@ public class HebrewUiTestsfinally { Object.DestroyImmediate(go); Object.DestroyImmediate(ps); rt.Release(); Object.DestroyImmediate(rt); }}+ // --- A language from translations/ (#1606) --------------------------------------------------------------------------++ /// <summary>Romanian (translations/ro, from #1604) is not offered yet (owner, 3 Nov 2026: "Hide until more is+ /// translated"): no button for it on the start screen or in Settings, and a stored "ro" reads as English at the next+ /// start, since only a language the buttons offer is kept. A flag still wins.</summary>+ [Test]+ public void RomanianIsNotOfferedYet()+ {+ CollectionAssert.AreEqual(new[] { UiLanguage.English, UiLanguage.Hebrew }, LanguageButtons.All.Select(l => l.language).ToArray(),+ "English and Hebrew only");+ const string page = "http://localhost:8000/index.html";+ var none = new string[0];+ Assert.AreEqual(UiLanguage.English, UiLanguage.AtStart("ro", page, none, webgl: true), "a stored ro is not offered");+ Assert.AreEqual(UiLanguage.English, UiLanguage.AtStart("ro", null, none, webgl: false));+ Assert.AreEqual(UiLanguage.Hebrew, UiLanguage.AtStart("ro", page + "?lang=he", none, webgl: true), "a flag wins");++ var settings = new SettingsStore(Path.Combine(saveDir, "settings"));+ BootWithStartScreen(settings, null);+ Assert.IsTrue(StartOpen, "precondition: the start screen shows");+ Assert.IsNull(Ui.Q<Button>("start-language-ro"), "no Romanian on the start screen");+ Assert.IsNull(Ui.Q<Button>("settings-language-ro"), "nor in Settings");+ }++ /// <summary>A new language's strings: each key its translations/<lang>/ui.yaml has reads the translation, every+ /// other key the English (the per-string fallback of #1606).</summary>+ [Test]+ public void ANewLanguageFallsBackToTheEnglishPerString()+ {+ var text = En.Over(new[] { new KeyValuePair<string, string>("ui.lang", "xx"), new KeyValuePair<string, string>("start.new_game", "[xx] start.new_game") }, "translations/xx/ui.yaml");+ Assert.AreEqual("xx", text["ui.lang"]);+ Assert.AreEqual("[xx] start.new_game", text["start.new_game"], "a key the translation has");+ Assert.AreEqual(En["hud.turn"], text["hud.turn"], "a key it lacks: the English");+ Assert.AreEqual("en", En["ui.lang"], "the English strings are left as they were");+ }++ /// <summary>The way in for a language once it is offered: GameRoot builds the UI from its translations/<lang>/ui.yaml+ /// (Content.Translations, #2124) over the English, left to right in the Latin face. A key the translation adds (a marker+ /// here, not Romanian) shows; the rest is English.</summary>+ [Test]+ public void ATranslatedLanguagesStringsFallBackToEnglish()+ {+ var translations = Inputs.Content.Translations;+ var i = translations.FindIndex(t => t.Lang == "ro");+ Assert.GreaterOrEqual(i, 0, "precondition: translations/ro loads with the content");+ var real = translations[i];+ const string marker = "[ro] start.new_game";+ translations[i] = new Statecraft.Sim.TranslationSet+ {+ Lang = real.Lang, Events = real.Events, Content = real.Content,+ Ui = real.Ui.Append(new KeyValuePair<string, string>("start.new_game", marker)).ToList(),+ };+ try+ {+ var game = BootWithStartScreen(new SettingsStore(Path.Combine(saveDir, "settings")), "ro");+ Assert.AreEqual(marker, Ui.Q<Button>("start-new-game").text, "a key translations/ro has");+ Assert.AreEqual(En.Format("hud.turn", game.Bridge!.State.Turn), Ui.Q<Label>("turn").text, "a key it lacks: the English");+ Assert.IsFalse(Ui.Q("root").ClassListContains(UiLanguage.HebrewClass), "left to right, the Latin face");+ }+ finally { translations[i] = real; }+ }+/// <summary>#1210: the one rule the event card and the outcome caption share. In Hebrew a text with a Hebrew form shows/// it, a text without one falls back to the English (fail open); in English the English always.</summary>[Test]