Skip to content

A Civilization-style strategy game about governing Israel from 15 May 1948. Real ministers, real map, every fact sourced. Unity + deterministic C# sim.

fix: the Hebrew info panel gives the map-action reasons in Hebrew (Fixes #881) (#924)

Eyal Golan1f7207ea0791
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f5bdff040..5440efed6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -18,6 +18,9 @@ adds a line under **Unreleased**; CI's `Changelog` job checks this (see `CONTRIB
English UI is unchanged. The tier badge stays on the left of the pill until the owner rules on mirroring it (#880).
- End Turn now logs a throwing `Changed` or `TurnEnded` subscriber and continues notifying the remaining presenters,
so a successful turn cannot leave later UI or autosave handlers stale (#912).
+- The info panel now translates every map-action refusal from the sim's stable reason kind and invariant values. Under
+ Hebrew, the 1948 availability reason and its date are Hebrew; English, CLI diagnostics and simulation state are unchanged
+ (#881). The new Hebrew strings are flagged for native-speaker review (#564).
- The content loader now checks `name_he_review` on people rows the way it does for parties, governments,
legislatures, offices and settlements: the flag is `agent-checked` or left out, and only beside a `name_he`
(CONTENT_POLICY section 2, rule 6; #862). No people row carries the flag yet, so no row changes.
diff --git a/sim/Statecraft.Sim.Tests/MapActionTests.cs b/sim/Statecraft.Sim.Tests/MapActionTests.cs
index 393c662d8..6f9b30186 100644
--- a/sim/Statecraft.Sim.Tests/MapActionTests.cs
+++ b/sim/Statecraft.Sim.Tests/MapActionTests.cs
@@ -78,6 +78,17 @@ public class MapActionTests
Assert.Equal("Transit camps and housing projects can be placed from 1 June 1948", MapActions.Check(C, s, "housing", 2, 0));
}
+ [Fact]
+ public void AReasonHasAStableKindAndInvariantValuesBesideItsEnglishText()
+ {
+ var s = Ready();
+ s.Date = new DateTime(1948, 5, 31);
+ var reason = MapActions.CheckReason(C, s, "housing", 2, 0)!;
+ Assert.Equal("all_from", reason.Kind);
+ Assert.Equal(new[] { "1948-06-01" }, reason.Values);
+ Assert.Equal("Transit camps and housing projects can be placed from 1 June 1948", reason.Text);
+ }
+
[Fact]
public void TransitCampsNeedTheMaabarotPolicy()
{
diff --git a/sim/Statecraft.Sim/MapActions.cs b/sim/Statecraft.Sim/MapActions.cs
index 3b6eb29db..bb5d3a198 100644
--- a/sim/Statecraft.Sim/MapActions.cs
+++ b/sim/Statecraft.Sim/MapActions.cs
@@ -14,6 +14,18 @@ namespace Statecraft.Sim
public Placement(string action, int q, int r, DateTime date) { Action = action; Q = q; R = r; Date = date; }
}
+ /// <summary>A map-action refusal's stable UI kind and invariant values, beside the English text used by the CLI.</summary>
+ public sealed class MapActionReason
+ {
+ public string Kind { get; }
+ public IReadOnlyList<string> Values { get; }
+ public string Text { get; }
+ public MapActionReason(string kind, string text, params string[] values)
+ {
+ Kind = kind; Text = text; Values = values;
+ }
+ }
+
/// <summary>Map actions (M3 scope: absorption from 1950). A transit camp (ma'abara) or a housing project goes on a land
/// hex within rules map_action_max_distance of a hex that owns a settlement (content/map/settlement_hexes.yaml). It
/// costs treasury (a shortfall is borrowed, as in EconomySystem) and moves housing (absorption) and morale (support).
@@ -35,39 +47,50 @@ namespace Statecraft.Sim
static int ActionsThisTurn(GameState s) => s.MapActionsTurnDate == s.Date ? s.MapActionsThisTurn : 0;
-
/// <summary>Null when <paramref name="action"/> may be placed on (q, r) now, else the reason shown to the player.</summary>
- public static string? Check(Content c, GameState s, string action, int q, int r)
+ public static string? Check(Content c, GameState s, string action, int q, int r) => CheckReason(c, s, action, q, r)?.Text;
+
+ /// <summary>Null when the action may be placed, else a stable kind and invariant values for a UI, plus English text.</summary>
+ public static MapActionReason? CheckReason(Content c, GameState s, string action, int q, int r)
{
// No id in either reason: a command from an old save or a stale UI may name an action this content lacks; the
// replay refuses it here, before anything is formatted, so a placement always has its rule (fix round 3, m-6).
- if (!Actions.Contains(action)) return "There is no such map action";
+ if (!Actions.Contains(action)) return new MapActionReason("unknown", "There is no such map action");
// eras.yaml systems.map_actions: the actions this era allows
- if (!c.SystemsAt(s.Date).MapActions.Contains(action)) return "That map action is not available in this chapter";
+ if (!c.SystemsAt(s.Date).MapActions.Contains(action)) return new MapActionReason("chapter", "That map action is not available in this chapter");
var rules = c.RulesAt(s.Date); // the era the turn starts in
var rule = rules.MapActions.TryGetValue(action, out var x) ? x : null;
- if (rule == null) return "That map action is not available in this game";
+ if (rule == null) return new MapActionReason("game", "That map action is not available in this game");
// rules.yaml map_actions from/to (chapters spec 3.2): [from, to), like every content window. The reason names the day.
if (!Window.Active(rule.From, rule.To, s.Date))
- return s.Date < rule.From.GetValueOrDefault()
- ? $"{PlayerText.Capitalised(PlayerText.MapAction(c, action))} can be placed from {PlayerText.Date(rule.From!.Value)}"
- : $"{PlayerText.Capitalised(PlayerText.MapAction(c, action))} could be placed until {PlayerText.Date(rule.To!.Value.AddDays(-1))}";
+ {
+ var before = s.Date < rule.From.GetValueOrDefault();
+ var date = before ? rule.From!.Value : rule.To!.Value.AddDays(-1);
+ var words = before
+ ? $"{PlayerText.Capitalised(PlayerText.MapAction(c, action))} can be placed from {PlayerText.Date(date)}"
+ : $"{PlayerText.Capitalised(PlayerText.MapAction(c, action))} could be placed until {PlayerText.Date(date)}";
+ return new MapActionReason(before ? "action_from" : "action_until", words, action,
+ date.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));
+ }
if (s.Date < rules.MapActionsFrom)
- return $"Transit camps and housing projects can be placed from {PlayerText.Date(rules.MapActionsFrom)}";
+ return new MapActionReason("all_from", $"Transit camps and housing projects can be placed from {PlayerText.Date(rules.MapActionsFrom)}",
+ rules.MapActionsFrom.ToString("yyyy-MM-dd", System.Globalization.CultureInfo.InvariantCulture));
if (action == TransitCamp && !(s.Policies.TryGetValue(MaabarotPolicy, out var m) && m >= 0.5))
- return "Transit camps need the ma'abarot policy";
+ return new MapActionReason("maabarot_policy", "Transit camps need the ma'abarot policy");
var hex = c.HexAt(q, r);
- if (hex == null || !hex.Land) return "This hex is not land";
+ if (hex == null || !hex.Land) return new MapActionReason("not_land", "This hex is not land");
var max = rules.MapActionMaxDistance;
if (!c.SettlementHexes.Any(sh => Distance(q, r, sh.Q, sh.R) <= max))
- return FormattableString.Invariant($"This hex is more than {max} {(max == 1 ? "hex" : "hexes")} from a settlement");
+ return new MapActionReason("too_far", FormattableString.Invariant($"This hex is more than {max} {(max == 1 ? "hex" : "hexes")} from a settlement"),
+ max.ToString(System.Globalization.CultureInfo.InvariantCulture));
var here = At(s, q, r);
if (here != null && !(action == Housing && here.Action == TransitCamp))
- return $"This hex already has {PlayerText.MapAction(c, here.Action)}";
+ return new MapActionReason("occupied", $"This hex already has {PlayerText.MapAction(c, here.Action)}", here.Action);
// The cap comes last so a player who is over it still sees the specific reason an order is illegal. It counts
// accepted actions (not surviving placements): housing on a camp removes the camp but still used an action.
if (ActionsThisTurn(s) >= rules.MapActionsPerTurn)
- return FormattableString.Invariant($"No more than {rules.MapActionsPerTurn} map actions in one turn");
+ return new MapActionReason("turn_cap", FormattableString.Invariant($"No more than {rules.MapActionsPerTurn} map actions in one turn"),
+ rules.MapActionsPerTurn.ToString(System.Globalization.CultureInfo.InvariantCulture));
return null;
}
diff --git a/tools/tests/test_hebrew_ui.py b/tools/tests/test_hebrew_ui.py
index 200e4dc6e..f5912670e 100644
--- a/tools/tests/test_hebrew_ui.py
+++ b/tools/tests/test_hebrew_ui.py
@@ -17,6 +17,20 @@ def test_hebrew_keys_match_english_and_every_value_is_nonempty():
assert all(isinstance(v, str) and v.strip() for v in he.values())
+def test_map_action_reasons_are_hebrew_and_their_english_action_names_are_the_rules_names():
+ """#881: the info panel builds the refusal from these strings; English must keep the sim's wording, which names
+ each action by its rules.yaml name."""
+ en, he = strings('strings.en.yaml'), strings('strings.he.yaml')
+ keys = [key for key in en if key.startswith('info.map_action')]
+ assert len(keys) == 14 # 2 action names and 12 reasons
+ assert all(not re.search('[A-Za-z]', he[key]) for key in keys)
+ rules = yaml12.load((ROOT / 'content/rules.yaml').read_text(encoding='utf-8'))
+ actions = rules['map_actions']
+ assert {k.split('.')[-1] for k in keys if k.startswith('info.map_action.')} == set(actions)
+ for action, rule in actions.items():
+ assert en['info.map_action.' + action] == rule['name']
+
+
def test_hebrew_keeps_complete_format_tokens_and_logical_text_order():
en, he = strings('strings.en.yaml'), strings('strings.he.yaml')
for key in en:
diff --git a/unity/Assets/Scripts/UI/InfoPanelPresenter.cs b/unity/Assets/Scripts/UI/InfoPanelPresenter.cs
index 83d458c7d..4517d14be 100644
--- a/unity/Assets/Scripts/UI/InfoPanelPresenter.cs
+++ b/unity/Assets/Scripts/UI/InfoPanelPresenter.cs
@@ -1,5 +1,6 @@
#nullable enable
using System.Collections.Generic;
+using System.Globalization;
using System.Linq;
using Statecraft.Game.Map;
using Statecraft.Game.Map.Units;
@@ -258,8 +259,10 @@ namespace Statecraft.Game.UI
placement.text = queued != null ? text.Format("info.queued", PlayerText.Capitalised(PlayerText.MapAction(c, queued.Action)))
: here != null ? text.Format("info.built", PlayerText.Capitalised(PlayerText.MapAction(c, here.Action)),
Control1948.LineDateText(here.Date.ToString("yyyy-MM", System.Globalization.CultureInfo.InvariantCulture), k => text[k])) : ""; // PlayerText.Month is always English (#701)
- var campWhy = MapActions.Check(c, s, MapActions.TransitCamp, q, r);
- var housingWhy = MapActions.Check(c, s, MapActions.Housing, q, r);
+ var campReason = MapActions.CheckReason(c, s, MapActions.TransitCamp, q, r);
+ var housingReason = MapActions.CheckReason(c, s, MapActions.Housing, q, r);
+ var campWhy = campReason == null ? null : MapActionReasonText(campReason, text);
+ var housingWhy = housingReason == null ? null : MapActionReasonText(housingReason, text);
// eras.yaml systems.map_actions (#58): an action the era does not allow has no button and no reason
var allowed = c.SystemsAt(s.Date).MapActions;
bool campOn = allowed.Contains(MapActions.TransitCamp), housingOn = allowed.Contains(MapActions.Housing);
@@ -276,5 +279,24 @@ namespace Statecraft.Game.UI
housing.text = c.RulesAt(s.Date).MapActions.TryGetValue(MapActions.Housing, out var hr) ? text.Format("info.build_housing", PlayerText.Money(c, "treasury", hr.Cost)) : text["info.build_housing_plain"];
reason.text = string.Join("\n", new[] { campWhy, housingWhy }.Where(x => x != null).Distinct()); // the sim's reasons, each once
}
+
+ static string MapActionReasonText(MapActionReason reason, UiText text)
+ {
+ string Action(string id) => text["info.map_action." + id];
+ string Date(string iso) => Control1948.DateText(System.DateTime.ParseExact(iso, "yyyy-MM-dd", CultureInfo.InvariantCulture), k => text[k]);
+ var key = "info.map_action_reason." + reason.Kind;
+ switch (reason.Kind)
+ {
+ case "action_from": case "action_until": return text.Format(key, PlayerText.Capitalised(Action(reason.Values[0])), Date(reason.Values[1]));
+ case "all_from": return text.Format(key, Date(reason.Values[0]));
+ case "too_far": {
+ var distance = int.Parse(reason.Values[0], CultureInfo.InvariantCulture);
+ return text.Format(key + (distance == 1 ? "_one" : "_many"), distance);
+ }
+ case "turn_cap": return text.Format(key, int.Parse(reason.Values[0], CultureInfo.InvariantCulture));
+ case "occupied": return text.Format(key, Action(reason.Values[0]));
+ default: return text[key];
+ }
+ }
}
}
diff --git a/unity/Assets/Tests/EditMode/MapActionUiTests.cs b/unity/Assets/Tests/EditMode/MapActionUiTests.cs
index da2d3b255..970c23c2b 100644
--- a/unity/Assets/Tests/EditMode/MapActionUiTests.cs
+++ b/unity/Assets/Tests/EditMode/MapActionUiTests.cs
@@ -67,6 +67,20 @@ public class MapActionUiTests
Assert.AreEqual("Transit camps and housing projects can be placed from 1 January 1950", ui.Q<Label>("info-reason").text);
}
+ /// <summary>#881: the sim supplies a refusal kind and ISO date; the Hebrew UI supplies both the words and Hebrew date.</summary>
+ [Test]
+ public void BeforeTheMaabarotTheHebrewPanelSaysWhyInHebrew()
+ {
+ var he = UiText.Parse(AssetDatabase.LoadAssetAtPath<TextAsset>(UiPaths.StringsHebrew).text, "strings.he.yaml");
+ using var ui = new UiTestKit();
+ var g = GameSession.New(C, GoldenRun.Seed, Mode.Historical);
+ var bridge = new SimBridge(g, he);
+ var info = new InfoPanelPresenter(ui.Root, bridge, he, Towns.ToDictionary(t => t.Id, t => t.Name));
+ var tlv = C.SettlementHexes.Single(s => s.Id == "tel_aviv");
+ info.Show(tlv.Q, tlv.R);
+ Assert.AreEqual("אפשר להקים מעברות ומיזמי דיור החל מ־1 בינואר 1950", ui.Q<Label>("info-reason").text);
+ }
+
[Test]
public void ATransitCampIsOrderedAndBuiltAtEndTurn()
{
diff --git a/unity/Assets/UI/strings.en.yaml b/unity/Assets/UI/strings.en.yaml
index d902d3ac5..6b00bc097 100644
--- a/unity/Assets/UI/strings.en.yaml
+++ b/unity/Assets/UI/strings.en.yaml
@@ -250,6 +250,20 @@ info.build_camp: "Place a transit camp ({0})"
info.build_housing: "Build housing ({0})"
info.build_camp_plain: "Place a transit camp"
info.build_housing_plain: "Build housing"
+info.map_action.transit_camp: "a transit camp"
+info.map_action.housing: "a housing project"
+info.map_action_reason.unknown: "There is no such map action"
+info.map_action_reason.chapter: "That map action is not available in this chapter"
+info.map_action_reason.game: "That map action is not available in this game"
+info.map_action_reason.action_from: "{0} can be placed from {1}"
+info.map_action_reason.action_until: "{0} could be placed until {1}"
+info.map_action_reason.all_from: "Transit camps and housing projects can be placed from {0}"
+info.map_action_reason.maabarot_policy: "Transit camps need the ma'abarot policy"
+info.map_action_reason.not_land: "This hex is not land"
+info.map_action_reason.too_far_one: "This hex is more than {0} hex from a settlement"
+info.map_action_reason.too_far_many: "This hex is more than {0} hexes from a settlement"
+info.map_action_reason.occupied: "This hex already has {0}"
+info.map_action_reason.turn_cap: "No more than {0} map actions in one turn"
info.biome.sea: "Sea"
info.biome.lake: "Lake"
info.biome.coastal_plain: "Coastal plain"
diff --git a/unity/Assets/UI/strings.he.yaml b/unity/Assets/UI/strings.he.yaml
index bc46784cd..b81e327cc 100644
--- a/unity/Assets/UI/strings.he.yaml
+++ b/unity/Assets/UI/strings.he.yaml
@@ -247,6 +247,22 @@ info.build_camp: "הקמת מעברה ({0})"
info.build_housing: "בניית דיור ({0})"
info.build_camp_plain: "הקמת מעברה"
info.build_housing_plain: "בניית דיור"
+# Map-action refusal text (#881). info.map_action.* are nouns ("מעברה", "מיזם דיור"), so every sentence they go into
+# uses a verb or "יש" that does not agree with their gender ("אפשר להקים {0}", "כבר יש {0}"). For the native reviewer (#564).
+info.map_action.transit_camp: "מעברה"
+info.map_action.housing: "מיזם דיור"
+info.map_action_reason.unknown: "פעולת מפה כזאת אינה קיימת"
+info.map_action_reason.chapter: "פעולת המפה הזאת אינה זמינה בפרק זה"
+info.map_action_reason.game: "פעולת המפה הזאת אינה זמינה במשחק זה"
+info.map_action_reason.action_from: "אפשר להקים {0} החל מ־{1}"
+info.map_action_reason.action_until: "אפשר היה להקים {0} עד {1}"
+info.map_action_reason.all_from: "אפשר להקים מעברות ומיזמי דיור החל מ־{0}"
+info.map_action_reason.maabarot_policy: "הקמת מעברות מחייבת את מדיניות המעברות"
+info.map_action_reason.not_land: "המשושה הזה אינו יבשה"
+info.map_action_reason.too_far_one: "המשושה הזה נמצא במרחק של יותר מ־{0} משושה מיישוב"
+info.map_action_reason.too_far_many: "המשושה הזה נמצא במרחק של יותר מ־{0} משושים מיישוב"
+info.map_action_reason.occupied: "במשושה הזה כבר יש {0}"
+info.map_action_reason.turn_cap: "אי אפשר לבצע יותר מ־{0} פעולות מפה בתור אחד"
info.biome.sea: "ים"
info.biome.lake: "אגם"
info.biome.coastal_plain: "מישור החוף"