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")
|
_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.
|
"""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
|
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
|
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
|
(IT-only) would never have caught this - #37.5's own TEST note calls out
|
||||||
the EN render specifically.
|
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 = [
|
mock_admin_api.get.side_effect = [
|
||||||
[{
|
[{
|
||||||
"id": 1, "code": "ST-DEFAULT", "name": "Default Station",
|
"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}],
|
[{"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")
|
resp = logged_in_client.get("/admin/stations")
|
||||||
assert resp.status_code == 200, resp.data[:300]
|
assert resp.status_code == 200, resp.data[:300]
|
||||||
|
|
||||||
html = resp.data.decode("utf-8")
|
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" 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)
|
scripts = _INLINE_SCRIPT_RX.findall(html)
|
||||||
for i, body in enumerate(scripts):
|
for i, body in enumerate(scripts):
|
||||||
|
|||||||
@@ -2760,3 +2760,15 @@ msgstr "Reading ignored: please wait"
|
|||||||
msgid "Lettura del calibro rifiutata: valore troppo grande"
|
msgid "Lettura del calibro rifiutata: valore troppo grande"
|
||||||
msgstr "Caliper reading refused: value too large"
|
msgstr "Caliper reading refused: value too large"
|
||||||
|
|
||||||
|
#: app.py:131 app.py:207
|
||||||
|
msgid "Sessione scaduta: effettua nuovamente l'accesso."
|
||||||
|
msgstr "Session expired: please log in again."
|
||||||
|
|
||||||
|
#: blueprints/measure.py:239 blueprints/measure.py:317 blueprints/measure.py:478
|
||||||
|
msgid "Ricetta non assegnata a questa stazione"
|
||||||
|
msgstr "Recipe not assigned to this station"
|
||||||
|
|
||||||
|
#: blueprints/measure.py:462
|
||||||
|
msgid "Codice non valido"
|
||||||
|
msgstr "Invalid code"
|
||||||
|
|
||||||
|
|||||||
@@ -2748,3 +2748,15 @@ msgstr "Lettura ignorata: attendere"
|
|||||||
msgid "Lettura del calibro rifiutata: valore troppo grande"
|
msgid "Lettura del calibro rifiutata: valore troppo grande"
|
||||||
msgstr "Lettura del calibro rifiutata: valore troppo grande"
|
msgstr "Lettura del calibro rifiutata: valore troppo grande"
|
||||||
|
|
||||||
|
#: app.py:131 app.py:207
|
||||||
|
msgid "Sessione scaduta: effettua nuovamente l'accesso."
|
||||||
|
msgstr "Sessione scaduta: effettua nuovamente l'accesso."
|
||||||
|
|
||||||
|
#: blueprints/measure.py:239 blueprints/measure.py:317 blueprints/measure.py:478
|
||||||
|
msgid "Ricetta non assegnata a questa stazione"
|
||||||
|
msgstr "Ricetta non assegnata a questa stazione"
|
||||||
|
|
||||||
|
#: blueprints/measure.py:462
|
||||||
|
msgid "Codice non valido"
|
||||||
|
msgstr "Codice non valido"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user