i18n: voci .po per le 3 nuove stringhe del lotto B2, test EN reso significativo
Aggiunte a mano in coda a it/en messages.po (nessuna rigenerazione): "Sessione scaduta: effettua nuovamente l'accesso." (#12/#25), "Ricetta non assegnata a questa stazione" (#24), "Codice non valido" (#37.4). test_admin_stations_inline_js_is_valid_in_english (#37.5): i .mo sono gitignored e compilati solo in Docker, non in questo run - impostare session["language"]="en" da solo non aveva alcun effetto e il test passava senza esercitare il bug EN reale. Ora patcha jinja_env.globals["_"] con la traduzione nota per quella stringa, verificato che fallisca davvero sul codice pre-fix (ripristinato subito dopo) prima di lasciarlo verde. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -197,7 +197,9 @@ def test_admin_stations_inline_js_is_valid(logged_in_client, mock_admin_api):
|
||||
_check_alpine_attributes(html, "/admin/stations")
|
||||
|
||||
|
||||
def test_admin_stations_inline_js_is_valid_in_english(logged_in_client, mock_admin_api):
|
||||
def test_admin_stations_inline_js_is_valid_in_english(
|
||||
logged_in_client, mock_admin_api, flask_app,
|
||||
):
|
||||
"""gitea#37.5: the EN catalog is where this page's apostrophe actually is.
|
||||
|
||||
translations/en/LC_MESSAGES/messages.po: msgid "Azzera le ricette della
|
||||
@@ -205,7 +207,25 @@ def test_admin_stations_inline_js_is_valid_in_english(logged_in_client, mock_adm
|
||||
The IT source string has no apostrophe, so test_admin_stations_inline_js_is_valid
|
||||
(IT-only) would never have caught this - #37.5's own TEST note calls out
|
||||
the EN render specifically.
|
||||
|
||||
The .mo catalogs are gitignored and compiled only at Docker build time
|
||||
(compile_translations.py) - not part of this test run - so setting
|
||||
session["language"] = "en" alone has no effect here: flask_babel falls
|
||||
back to the (Italian) msgid with no compiled catalog to translate from.
|
||||
The Jinja "_" global is patched directly instead, standing in for what a
|
||||
compiled EN catalog would return for this one string; everything else
|
||||
round-trips unchanged, same as gettext's own fallback.
|
||||
"""
|
||||
EN_TRANSLATIONS = {
|
||||
"Azzera le ricette della stazione": "Clear the station's recipes",
|
||||
}
|
||||
|
||||
def fake_gettext(msgid, **kwargs):
|
||||
text = EN_TRANSLATIONS.get(msgid, msgid)
|
||||
return text % kwargs if kwargs else text
|
||||
|
||||
flask_app.jinja_env.globals["_"] = fake_gettext
|
||||
|
||||
mock_admin_api.get.side_effect = [
|
||||
[{
|
||||
"id": 1, "code": "ST-DEFAULT", "name": "Default Station",
|
||||
@@ -215,13 +235,18 @@ def test_admin_stations_inline_js_is_valid_in_english(logged_in_client, mock_adm
|
||||
[{"id": 1, "code": "DEMO-001", "name": "Demo Recipe", "active": True}],
|
||||
]
|
||||
|
||||
with logged_in_client.session_transaction() as sess:
|
||||
sess["language"] = "en"
|
||||
resp = logged_in_client.get("/admin/stations")
|
||||
assert resp.status_code == 200, resp.data[:300]
|
||||
|
||||
html = resp.data.decode("utf-8")
|
||||
# The fix (#37.5) is exactly why the apostrophe shows up escaped
|
||||
# (tojson_attr) rather than literal - that is what keeps it from
|
||||
# breaking the surrounding JS string.
|
||||
assert "station" in html.lower(), "sanity check: the EN string did render"
|
||||
assert "station\\u0027s recipes" in html or "station's recipes" in html, (
|
||||
"expected the EN string's apostrophe to reach the page only as an "
|
||||
"escaped token (tojson_attr), not literally"
|
||||
)
|
||||
|
||||
scripts = _INLINE_SCRIPT_RX.findall(html)
|
||||
for i, body in enumerate(scripts):
|
||||
|
||||
Reference in New Issue
Block a user