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.

13.0 KB
Raw Blame
"""Partial #12: translation data must keep UiText's format contract."""
from pathlib import Path
import re
from collections import Counter
import yaml12
ROOT = Path(__file__).resolve().parents[2]
UI = ROOT / 'unity/Assets/UI'


def strings(name):
    return yaml12.load((UI / name).read_text(encoding='utf-8'))


def test_hebrew_keys_match_english_and_every_value_is_nonempty():
    en, he = strings('strings.en.yaml'), strings('strings.he.yaml')
    assert en.keys() == he.keys()
    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) == 15             # 2 action names and 13 reasons (depopulated, #2573)
    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:
        tokens = lambda v: Counter(re.findall(r'\{[^{}]+\}', v))
        assert tokens(en[key]) == tokens(he[key]), key
        assert not any(c in he[key] for c in '\u202a\u202b\u202c\u202d\u202e'), key
    assert 'תור' in he['hud.turn']
    assert 'תשומת לב' in he['hud.attention']


def test_hebrew_is_not_enabled_without_runtime_review():
    paths = (ROOT / 'unity/Assets/Scripts/UI/UiPaths.cs').read_text()
    assert 'public const string Strings = Folder + "/strings.en.yaml";' in paths
    # The translation is data only; no language-switch or RTL implementation in this PR.
    meta = (UI / 'strings.he.yaml.meta').read_text()
    english_meta = (UI / 'strings.en.yaml.meta').read_text()
    guid = re.search(r'^guid: ([0-9a-f]{32})$', meta, re.M).group(1)
    assert guid not in english_meta
    assert 'TextScriptImporter:' in meta


def test_hebrew_review_wording_is_count_neutral_and_uses_knesset_terms():
    he = strings('strings.he.yaml')
    assert he['event.more'] == 'החלטות ממתינות נוספות: {0}'
    assert he['budget.no_vote'] == '{0} אינה מצביעה על התקציב'
    assert he['budget.vote_advisory'] == '{0} מצביעה על התקציב, אך ההצבעה אינה מחייבת: לקואליציה יש {1} מתוך {2} {3}'
    assert he['cabinet.legislature_advisory'] == 'מתייעצת עם {0} · {1} חברים · ההצבעות אינן מחייבות'
    # A seat count's unit is its own string, by the body (CabinetPresenter.SeatUnit): the Knesset's seats are
    # "מנדטים", the appointed Provisional State Council's members "חברים"; no template hard-codes either.
    assert he['cabinet.seats'] == 'מנדטים'
    assert he['cabinet.seats_appointed'] == 'חברים'
    for key in ('budget.vote_needed', 'budget.vote_advisory', 'cabinet.coalition', 'cabinet.opposition',
                'cabinet.majority', 'cabinet.largest'):
        assert 'מנדטים' not in he[key] and 'חברים' not in he[key], key
    assert he['order.no_attention'] == 'אין מספיק תשומת לב (נדרש {0:0.0}, יש {1:0.0})'
    assert he['defence.rung5'] == '5  מלחמה כוללת'


def test_an_order_refusal_shows_no_raw_id_or_exception_text():
    # #622 finding 1: the toast showed a content id ("Unknown policy 'curfew'") or the exception's message after
    # "Not done:". The kind word stays ({0}, #595); the id and the message go to the log only (SimBridge).
    for name in ('strings.en.yaml', 'strings.he.yaml'):
        s = strings(name)
        assert re.findall(r'\{[^{}]+\}', s['order.unknown']) == ['{0}'], name
        assert re.findall(r'\{[^{}]+\}', s['order.failed']) == [], name


def test_a_failed_turn_gives_the_next_step_in_both_languages():
    # #622 (maintainer, 15 October 2026): SimBridge.EndTurn clears the queue when the turn fails, so the refusal says so
    # and tells the player to give the orders again. The Hebrew waits for the native reviewer (#564).
    en, he = strings('strings.en.yaml'), strings('strings.he.yaml')
    assert en['order.failed'] == 'The turn could not run. Your orders were cleared. Give them again.'
    assert he['order.failed'].count('.') == 3, he['order.failed']
    assert not re.search('[A-Za-z]', he['order.failed']), he['order.failed']

def test_the_top_bar_and_start_labels_are_in_sentence_case():
    # #622 finding 2: the six Title Case labels match the file's sentence case, and so do the lines that name the two
    # buttons, written as the button shows them. Game.uxml keeps the same texts (HebrewUiTests).
    en = strings('strings.en.yaml')
    assert [en[k] for k in ('hud.caption.support', 'hud.caption.standing', 'hud.caption.fx', 'hud.new_game',
                            'hud.end_turn', 'start.new_game')] == [
        'Public support', 'International support', 'Foreign currency', 'New game', 'End turn', 'New game']
    for key, value in en.items():
        assert 'End Turn' not in value and 'New Game' not in value, key
    uxml = (UI / 'Game.uxml').read_text(encoding='utf-8')
    for title in ('Public Support', 'International Standing', 'International standing', 'International Support',
                  'Foreign Currency', 'New Game', 'End Turn'):
        assert f'text="{title}"' not in uxml, title


def test_the_international_meter_is_named_support_in_both_languages():
    # #622 decision 3 (maintainer, 15 October 2026): "International support". The Hebrew is the owner's word for
    # International Support, תמיכה בינלאומית (Q-HUD-3, decided 15 October 2026, #375), replacing מעמד בינלאומי.
    en, he = strings('strings.en.yaml'), strings('strings.he.yaml')
    assert en['hud.caption.standing'] == 'International support'
    assert he['hud.caption.standing'] == 'תמיכה בינלאומית'
    assert 'text="International support"' in (UI / 'Game.uxml').read_text(encoding='utf-8')


HEBREW_ACRONYM_STRAIGHT_QUOTE = re.compile('[א-ת]"[א-ת]')


def test_hebrew_acronyms_use_the_gershayim_character():
    # #622 finding 4: the strings write gershayim as U+05F4 ("הרמטכ״ל"); the Hebrew names in content follow them, not a
    # straight quote. Only values are checked: comments may quote a source verbatim.
    for name, text in strings('strings.he.yaml').items():
        assert not HEBREW_ACRONYM_STRAIGHT_QUOTE.search(text), name
    content = ROOT / 'content'
    for file, key, field in (('offices.yaml', 'offices', 'title_he'), ('parties.yaml', 'parties', 'name_he'),
                             ('people.yaml', 'people', 'name_he'), ('map/units_1948.yaml', 'units', 'name_he')):
        rows = yaml12.load((content / file).read_text(encoding='utf-8'))[key]
        values = [r[f] for r in rows for f in (field, field + '_f') if r.get(f)]
        assert values, file
        for value in values:
            assert not HEBREW_ACRONYM_STRAIGHT_QUOTE.search(value), (file, value)


def test_event_hebrew_acronyms_use_the_gershayim_character():
    # #2537, HE-06 (docs/WRITING_UI_HE.md, settled in #630): event titles, texts and option labels write gershayim as
    # U+05F4 too. Every value under a key ending in _he is checked; comments may quote a source verbatim and are not.
    def hebrew_values(node, path):
        if isinstance(node, dict):
            for key, value in node.items():
                if isinstance(value, str) and str(key).endswith('_he'):
                    yield path + (key,), value
                else:
                    yield from hebrew_values(value, path + (key,))
        elif isinstance(node, list):
            for i, item in enumerate(node):
                yield from hebrew_values(item, path + (i,))

    files = sorted((ROOT / 'content/events').glob('*.yaml'))
    assert files
    checked = 0
    for file in files:
        for path, value in hebrew_values(yaml12.load(file.read_text(encoding='utf-8')), ()):
            checked += 1
            assert not HEBREW_ACRONYM_STRAIGHT_QUOTE.search(value), (file.name, path, value)
    assert checked > 100


def test_every_cabinet_refusal_has_both_strings_and_the_english_is_the_sims_wording():
    """#901: every return path of Cabinet.CheckReason names a kind; the Cabinet screen formats it from
    cabinet.reason.<kind>. Each kind needs a key in both files, and the English key must be the sim's own English text
    (its interpolations as {0}, {1}, ... in order), so the English player sees what the sim says."""
    en, he = strings('strings.en.yaml'), strings('strings.he.yaml')
    src = (ROOT / 'sim/Statecraft.Sim/Cabinet.cs').read_text(encoding='utf-8')
    # #2707: each path's English is a Refused* constant, already in {0}, {1}, ... form (Say formats it).
    consts = dict(re.findall(r'public const string (Refused\w+) = "((?:[^"\\]|\\.)*)";', src))
    paths = re.findall(r'new CabinetReason\("(\w+)",\s*(?:Say\()?(Refused\w+)', src)
    assert len(paths) == 15
    assert len({kind for kind, _ in paths}) == len(paths)   # one kind per return path
    for kind, const in paths:
        key = 'cabinet.reason.' + kind
        assert key in en and key in he, key
        assert en[key] == consts[const], key
        assert not re.search('[A-Za-z]', he[key]), key
    assert sorted(k for k in en if k.startswith('cabinet.reason.')) == sorted('cabinet.reason.' + k for k, _ in paths)


def test_the_cause_line_names_are_contents_names_in_english_and_hebrew_without_latin():
    """B1: CauseText names indicators, policies, money, effects, situations and origin groups from
    why.name/effect/situation/region (policies since the event_policy line in #1680, as PlayerText.Target names them).
    English must be content's own name (the line is the sim's Message word for word), every content row has one, and the
    Hebrew has no Latin letters."""
    en, he = strings('strings.en.yaml'), strings('strings.he.yaml')
    model = yaml12.load((ROOT / 'content/model.yaml').read_text(encoding='utf-8'))
    aliyah = yaml12.load((ROOT / 'content/aliyah.yaml').read_text(encoding='utf-8'))
    rows = {'why.name.': model['indicators'] + model['policies'] + model['money'], 'why.effect.': model['effects'],
            'why.situation.': model['situations'], 'why.region.': aliyah['regions']}
    for prefix, items in rows.items():
        assert {k[len(prefix):] for k in en if k.startswith(prefix)} == {r['id'] for r in items}, prefix
        for r in items:
            assert en[prefix + r['id']] == r['name'], prefix + r['id']
            assert not re.search('[A-Za-z]', he[prefix + r['id']]), prefix + r['id']
    assert all(not re.search('[A-Za-z]', re.sub(r'\{[^}]*\}', '', he[k])) for k in he if k.startswith('why.cause.'))   # {0:N0} aside


def test_the_hebrew_plural_of_a_turn_is_torot_never_torim():
    """The owner's ruling (24 Oct 2026, #1589): the plural of תור (a game turn) is תורות. #1589 changed it to תורים by
    mistake and #1612 changed it back; this keeps it from drifting again. Every string that counts turns must say
    תורות, and no Hebrew string may say תורים."""
    he = strings('strings.he.yaml')
    assert [key for key, value in he.items() if 'תורים' in value] == []
    for key in ('advisor.page.training.text', 'capture.about.occupy', 'unit.go_to_given', 'city.turns',
                'defence.turn_quarter', 'defence.turn_month', 'defence.turn_week',
                'advisor.opening.move.text', 'advisor.opening.move.cue.2', 'advisor.ben_gurion.defeat_economy.text'):
        assert 'תורות' in he[key], key


def test_the_money_and_cohesion_meter_tips_name_the_debt_ceiling_and_event_cards():
    """#2459: Money's tip says a cost past what we have becomes debt, but an Arms purchase that would take the debt past
    mvp.debt_ceiling is refused (Pools.BuyArms, RefusedDebtCeiling, R-ARMS-002). The tip shows in every ruleset, so it
    must not name the arms workshop's waiting cycle (Workshops.Produce, R-ARMS-006), which runs only under gdd-0.3. Event cards move Social cohesion directly (EventSystem's
    effects through EffectsSystem.Shift on morale, e.g. altalena), as the Security and International support tips
    already say. Both tips must say so, in English and in Hebrew (the same words as arms.refused_debt_ceiling and
    hud.tip.security)."""
    en, he = strings('strings.en.yaml'), strings('strings.he.yaml')
    assert 'debt ceiling' in en['hud.tip.treasury']
    assert 'Arms purchase' in en['hud.tip.treasury'] and 'workshop' not in en['hud.tip.treasury']
    assert 'תקרת החוב' in he['hud.tip.treasury']
    assert 'רכישת נשק' in he['hud.tip.treasury'] and 'סדנ' not in he['hud.tip.treasury']
    assert 'event cards' in en['hud.tip.cohesion']
    assert 'כרטיסי האירוע' in he['hud.tip.cohesion']