Merge pull request #1342 from OffbandMesh/build/1323-l10n-check
build(#1323): check every translation in CIpull/1346/head
commit
be17c94bbd
@ -0,0 +1,342 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
"""Fail the build when a translation would break or show the wrong text (#1323).
|
||||||
|
|
||||||
|
Compares every lib/l10n/app_<locale>.arb with the template, app_en.arb.
|
||||||
|
|
||||||
|
Fails on:
|
||||||
|
- a placeholder dropped, renamed or added compared with English;
|
||||||
|
- a broken plural or select (unbalanced braces, no `other` case, a repeated
|
||||||
|
case, an unknown plural category, or a plural over a placeholder English
|
||||||
|
does not declare as a number);
|
||||||
|
- an empty translation of a non-empty English string;
|
||||||
|
- a key, or its @metadata, that app_en.arb no longer has;
|
||||||
|
- a duplicate key, or an @@locale that does not match the file name;
|
||||||
|
- a translation identical to English (ignoring spacing), unless
|
||||||
|
it is allowed by
|
||||||
|
tools/l10n/l10n_check.json: `allow_identical` (reviewed, permanent) or
|
||||||
|
`pending_identical` (known untranslated, for the language batches of #1322).
|
||||||
|
A pending entry that is no longer identical fails too, so the list only
|
||||||
|
shrinks.
|
||||||
|
|
||||||
|
Reports, without failing, keys missing from a locale. `fail_on_missing` in the
|
||||||
|
config turns that into a failure once every locale is complete.
|
||||||
|
|
||||||
|
Parses messages the way `flutter gen-l10n` does with `use-escaping` off (the
|
||||||
|
l10n.yaml default): every brace is syntax. Fails outright if l10n.yaml turns
|
||||||
|
escaping on, rather than misreading quoted text.
|
||||||
|
|
||||||
|
Exit status: 0 when clean, 1 on any failure.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
from dataclasses import dataclass, field
|
||||||
|
|
||||||
|
L10N_DIR = os.path.join("lib", "l10n")
|
||||||
|
TEMPLATE = "app_en.arb"
|
||||||
|
CONFIG = os.path.join(os.path.dirname(os.path.abspath(__file__)), "l10n_check.json")
|
||||||
|
ICU_TYPES = ("plural", "select", "selectordinal")
|
||||||
|
PLURAL_CATEGORIES = {"zero", "one", "two", "few", "many", "other"}
|
||||||
|
NUMBER_TYPES = {"int", "num", "double"}
|
||||||
|
|
||||||
|
|
||||||
|
class MessageError(ValueError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class Message:
|
||||||
|
"""What a message references: every argument name, and its ICU blocks."""
|
||||||
|
|
||||||
|
names: set[str] = field(default_factory=set)
|
||||||
|
blocks: list[tuple[str, str, list[str]]] = field(default_factory=list)
|
||||||
|
text: str = ""
|
||||||
|
|
||||||
|
|
||||||
|
def parse_message(source: str) -> Message:
|
||||||
|
"""Parses one ARB message, raising MessageError when it is malformed."""
|
||||||
|
msg = Message()
|
||||||
|
end = _parse_body(source, 0, msg, nested=False)
|
||||||
|
if end != len(source):
|
||||||
|
raise MessageError(f"unexpected '}}' at {end}")
|
||||||
|
return msg
|
||||||
|
|
||||||
|
|
||||||
|
def _parse_body(s: str, i: int, msg: Message, nested: bool) -> int:
|
||||||
|
while i < len(s):
|
||||||
|
c = s[i]
|
||||||
|
if c == "{":
|
||||||
|
i = _parse_argument(s, i, msg)
|
||||||
|
elif c == "}":
|
||||||
|
if nested:
|
||||||
|
return i
|
||||||
|
raise MessageError(f"unexpected '}}' at {i}")
|
||||||
|
else:
|
||||||
|
msg.text += c
|
||||||
|
i += 1
|
||||||
|
if nested:
|
||||||
|
raise MessageError("unclosed '{'")
|
||||||
|
return i
|
||||||
|
|
||||||
|
|
||||||
|
def _skip_ws(s: str, i: int) -> int:
|
||||||
|
while i < len(s) and s[i].isspace():
|
||||||
|
i += 1
|
||||||
|
return i
|
||||||
|
|
||||||
|
|
||||||
|
def _read_word(s: str, i: int) -> tuple[str, int]:
|
||||||
|
start = i
|
||||||
|
while i < len(s) and (s[i].isalnum() or s[i] in "_="):
|
||||||
|
i += 1
|
||||||
|
return s[start:i], i
|
||||||
|
|
||||||
|
|
||||||
|
def _parse_argument(s: str, i: int, msg: Message) -> int:
|
||||||
|
open_at = i
|
||||||
|
i = _skip_ws(s, i + 1)
|
||||||
|
name, i = _read_word(s, i)
|
||||||
|
if not name or not (name[0].isalpha() or name[0] == "_"):
|
||||||
|
raise MessageError(f"bad argument name at {open_at}")
|
||||||
|
msg.names.add(name)
|
||||||
|
i = _skip_ws(s, i)
|
||||||
|
if i < len(s) and s[i] == "}":
|
||||||
|
return i + 1
|
||||||
|
if i >= len(s) or s[i] != ",":
|
||||||
|
raise MessageError(f"unclosed '{{{name}'")
|
||||||
|
i = _skip_ws(s, i + 1)
|
||||||
|
kind, i = _read_word(s, i)
|
||||||
|
if kind not in ICU_TYPES:
|
||||||
|
raise MessageError(f"'{{{name}, {kind}' is not plural, select or selectordinal")
|
||||||
|
i = _skip_ws(s, i)
|
||||||
|
if i >= len(s) or s[i] != ",":
|
||||||
|
raise MessageError(f"'{{{name}, {kind}' needs a ',' before its cases")
|
||||||
|
i += 1
|
||||||
|
cases: list[str] = []
|
||||||
|
while True:
|
||||||
|
i = _skip_ws(s, i)
|
||||||
|
if i >= len(s):
|
||||||
|
raise MessageError(f"unclosed '{{{name}, {kind}'")
|
||||||
|
if s[i] == "}":
|
||||||
|
i += 1
|
||||||
|
break
|
||||||
|
case, i = _read_word(s, i)
|
||||||
|
if not case:
|
||||||
|
raise MessageError(f"'{{{name}, {kind}' has a case with no name")
|
||||||
|
i = _skip_ws(s, i)
|
||||||
|
if i >= len(s) or s[i] != "{":
|
||||||
|
raise MessageError(f"case '{case}' of '{{{name}' has no '{{'")
|
||||||
|
i = _parse_body(s, i + 1, msg, nested=True) + 1
|
||||||
|
cases.append(case)
|
||||||
|
msg.blocks.append((name, kind, cases))
|
||||||
|
return i
|
||||||
|
|
||||||
|
|
||||||
|
def check_message(english: str, translated: str, placeholder_types: dict | None = None) -> list[str]:
|
||||||
|
"""Problems with one translated message, compared with its English source.
|
||||||
|
|
||||||
|
`placeholder_types` maps a placeholder to its type in app_en.arb's metadata.
|
||||||
|
"""
|
||||||
|
if english and not translated:
|
||||||
|
return ["empty translation"]
|
||||||
|
try:
|
||||||
|
en = parse_message(english)
|
||||||
|
except MessageError as e:
|
||||||
|
return [f"English message itself does not parse: {e}"]
|
||||||
|
try:
|
||||||
|
tr = parse_message(translated)
|
||||||
|
except MessageError as e:
|
||||||
|
return [f"does not parse: {e}"]
|
||||||
|
problems = []
|
||||||
|
dropped = sorted(en.names - tr.names)
|
||||||
|
added = sorted(tr.names - en.names)
|
||||||
|
if dropped:
|
||||||
|
problems.append("drops " + ", ".join("{" + n + "}" for n in dropped))
|
||||||
|
if added:
|
||||||
|
problems.append("adds " + ", ".join("{" + n + "}" for n in added))
|
||||||
|
english_blocks = {(name, kind) for name, kind, _ in en.blocks}
|
||||||
|
types = placeholder_types or {}
|
||||||
|
for name, kind, cases in tr.blocks:
|
||||||
|
if "other" not in cases:
|
||||||
|
problems.append(f"'{{{name}, {kind}' has no 'other' case")
|
||||||
|
repeated = sorted({c for c in cases if cases.count(c) > 1})
|
||||||
|
if repeated:
|
||||||
|
problems.append(f"'{{{name}, {kind}' repeats cases: {', '.join(repeated)}")
|
||||||
|
if kind != "select":
|
||||||
|
bad = [c for c in cases if c not in PLURAL_CATEGORIES and not _is_exact(c)]
|
||||||
|
if bad:
|
||||||
|
problems.append(f"'{{{name}, {kind}' has unknown cases: {', '.join(bad)}")
|
||||||
|
if (name, kind) not in english_blocks and types.get(name) not in NUMBER_TYPES:
|
||||||
|
problems.append(
|
||||||
|
f"'{{{name}, {kind}' counts a placeholder English does not declare as a number"
|
||||||
|
)
|
||||||
|
return problems
|
||||||
|
|
||||||
|
|
||||||
|
def same_text(a: str, b: str) -> bool:
|
||||||
|
"""True if two strings differ only in spacing. Case counts: German
|
||||||
|
capitalizes nouns, so "Min." can be the right translation of "min."."""
|
||||||
|
return " ".join(a.split()) == " ".join(b.split())
|
||||||
|
|
||||||
|
|
||||||
|
def _is_exact(case: str) -> bool:
|
||||||
|
return case.startswith("=") and case[1:].isdigit()
|
||||||
|
|
||||||
|
|
||||||
|
def has_words(message: str) -> bool:
|
||||||
|
"""True if the message has text a translator could change."""
|
||||||
|
try:
|
||||||
|
msg = parse_message(message)
|
||||||
|
except MessageError:
|
||||||
|
return True
|
||||||
|
return any(c.isalpha() for c in msg.text)
|
||||||
|
|
||||||
|
|
||||||
|
def load_arb(path: str) -> tuple[dict, list[str]]:
|
||||||
|
"""Loads an ARB, returning its entries and any duplicate keys."""
|
||||||
|
duplicates: list[str] = []
|
||||||
|
|
||||||
|
def pairs(items):
|
||||||
|
seen: dict = {}
|
||||||
|
for k, v in items:
|
||||||
|
if k in seen:
|
||||||
|
duplicates.append(k)
|
||||||
|
seen[k] = v
|
||||||
|
return seen
|
||||||
|
|
||||||
|
with open(path, encoding="utf-8") as fh:
|
||||||
|
return json.load(fh, object_pairs_hook=pairs), duplicates
|
||||||
|
|
||||||
|
|
||||||
|
def load_config(path: str = CONFIG) -> dict:
|
||||||
|
with open(path, encoding="utf-8") as fh:
|
||||||
|
config = json.load(fh)
|
||||||
|
return {
|
||||||
|
"allow_identical": config.get("allow_identical", {}),
|
||||||
|
"pending_identical": config.get("pending_identical", {}),
|
||||||
|
"fail_on_missing": bool(config.get("fail_on_missing", False)),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def _placeholder_types(template: dict, key: str) -> dict:
|
||||||
|
meta = template.get("@" + key)
|
||||||
|
placeholders = meta.get("placeholders", {}) if isinstance(meta, dict) else {}
|
||||||
|
return {name: spec.get("type") for name, spec in placeholders.items() if isinstance(spec, dict)}
|
||||||
|
|
||||||
|
|
||||||
|
def escaping_is_on(l10n_yaml: str) -> bool:
|
||||||
|
"""True if l10n.yaml turns on use-escaping, which this parser does not model."""
|
||||||
|
if not os.path.exists(l10n_yaml):
|
||||||
|
return False
|
||||||
|
with open(l10n_yaml, encoding="utf-8") as fh:
|
||||||
|
for line in fh:
|
||||||
|
key, _, value = line.partition(":")
|
||||||
|
setting = value.split("#")[0].strip().strip("'\"").lower()
|
||||||
|
if key.strip() == "use-escaping" and setting == "true":
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def _allowed(table: dict, key: str, locale: str) -> bool:
|
||||||
|
locales = table.get(key)
|
||||||
|
return locales == "*" or (isinstance(locales, list) and locale in locales)
|
||||||
|
|
||||||
|
|
||||||
|
def check_locale(locale: str, data: dict, duplicates: list[str], template: dict, config: dict):
|
||||||
|
"""Returns (failures, missing keys) for one locale."""
|
||||||
|
failures = [f"duplicate key '{k}'" for k in duplicates]
|
||||||
|
if data.get("@@locale") != locale:
|
||||||
|
failures.append(f"@@locale is {data.get('@@locale')!r}, the file name says {locale!r}")
|
||||||
|
|
||||||
|
pending = set(config["pending_identical"].get(locale, []))
|
||||||
|
for key, value in data.items():
|
||||||
|
if key == "@@locale":
|
||||||
|
continue
|
||||||
|
if key.startswith("@"):
|
||||||
|
if key[1:] not in template:
|
||||||
|
failures.append(f"'{key}' is metadata for a key app_en.arb no longer has")
|
||||||
|
continue
|
||||||
|
if key not in template:
|
||||||
|
failures.append(f"'{key}' is not in app_en.arb")
|
||||||
|
continue
|
||||||
|
english = template[key]
|
||||||
|
if not isinstance(english, str):
|
||||||
|
continue
|
||||||
|
if not isinstance(value, str):
|
||||||
|
failures.append(f"'{key}' is not a string")
|
||||||
|
continue
|
||||||
|
for problem in check_message(english, value, _placeholder_types(template, key)):
|
||||||
|
failures.append(f"'{key}': {problem}")
|
||||||
|
if same_text(value, english) and has_words(english):
|
||||||
|
if key in pending:
|
||||||
|
continue
|
||||||
|
if not _allowed(config["allow_identical"], key, locale):
|
||||||
|
failures.append(
|
||||||
|
f"'{key}' is identical to English ({english!r}). Translate it, or add it "
|
||||||
|
"to allow_identical in tools/l10n/l10n_check.json if English is right here"
|
||||||
|
)
|
||||||
|
|
||||||
|
for key in sorted(pending):
|
||||||
|
if not isinstance(data.get(key), str) or not same_text(data[key], template.get(key, "")):
|
||||||
|
failures.append(
|
||||||
|
f"'{key}' is listed in pending_identical but is no longer identical to "
|
||||||
|
"English: remove it from tools/l10n/l10n_check.json"
|
||||||
|
)
|
||||||
|
|
||||||
|
missing = [k for k in template if not k.startswith("@") and k not in data]
|
||||||
|
return failures, missing
|
||||||
|
|
||||||
|
|
||||||
|
def run(l10n_dir: str = L10N_DIR, config_path: str = CONFIG, out=sys.stdout) -> int:
|
||||||
|
l10n_yaml = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(l10n_dir))), "l10n.yaml")
|
||||||
|
if escaping_is_on(l10n_yaml):
|
||||||
|
print(
|
||||||
|
"FAIL l10n.yaml: use-escaping is on, and this check parses messages as if it "
|
||||||
|
"were off. Teach tools/l10n/check_arb.py about quoted text first.",
|
||||||
|
file=out,
|
||||||
|
)
|
||||||
|
return 1
|
||||||
|
config = load_config(config_path)
|
||||||
|
template, template_dups = load_arb(os.path.join(l10n_dir, TEMPLATE))
|
||||||
|
failed = False
|
||||||
|
if template_dups:
|
||||||
|
failed = True
|
||||||
|
print(f"FAIL {TEMPLATE}: duplicate keys {', '.join(template_dups)}", file=out)
|
||||||
|
for key, value in template.items():
|
||||||
|
if key.startswith("@"):
|
||||||
|
continue
|
||||||
|
if not isinstance(value, str):
|
||||||
|
failed = True
|
||||||
|
print(f"FAIL {TEMPLATE}: '{key}' is not a string", file=out)
|
||||||
|
continue
|
||||||
|
try:
|
||||||
|
parse_message(value)
|
||||||
|
except MessageError as e:
|
||||||
|
failed = True
|
||||||
|
print(f"FAIL {TEMPLATE}: '{key}' does not parse: {e}", file=out)
|
||||||
|
|
||||||
|
names = sorted(f for f in os.listdir(l10n_dir) if f.startswith("app_") and f.endswith(".arb"))
|
||||||
|
for name in names:
|
||||||
|
if name == TEMPLATE:
|
||||||
|
continue
|
||||||
|
locale = name[len("app_") : -len(".arb")]
|
||||||
|
data, dups = load_arb(os.path.join(l10n_dir, name))
|
||||||
|
failures, missing = check_locale(locale, data, dups, template, config)
|
||||||
|
if missing and config["fail_on_missing"]:
|
||||||
|
failures.append(f"{len(missing)} keys missing: {', '.join(missing[:10])}")
|
||||||
|
for f in failures:
|
||||||
|
print(f"FAIL {name}: {f}", file=out)
|
||||||
|
failed = failed or bool(failures)
|
||||||
|
if missing and not config["fail_on_missing"]:
|
||||||
|
print(f"note {name}: {len(missing)} keys not translated yet", file=out)
|
||||||
|
|
||||||
|
print("check_arb: FAILED" if failed else "check_arb: OK", file=out)
|
||||||
|
return 1 if failed else 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
sys.stdout.reconfigure(encoding="utf-8")
|
||||||
|
raise SystemExit(run(*sys.argv[1:2]))
|
||||||
@ -0,0 +1,589 @@
|
|||||||
|
{
|
||||||
|
"fail_on_missing": false,
|
||||||
|
"allow_identical": {
|
||||||
|
"appTitle": "*",
|
||||||
|
"scanner_title": "*",
|
||||||
|
"settings_aboutVersion": "*",
|
||||||
|
"device_meshcore": "*",
|
||||||
|
"connectionChoiceBluetoothLabel": "*",
|
||||||
|
"connectionChoiceTcpLabel": "*",
|
||||||
|
"connectionChoiceUsbLabel": "*",
|
||||||
|
"telemetry_gpsLabel": "*",
|
||||||
|
"debugFrame_textTypeCli": "*",
|
||||||
|
"repeater_cli": "*",
|
||||||
|
"channels_pskHex": "*",
|
||||||
|
"settings_infoId": "*",
|
||||||
|
"common_voltageValue": "*",
|
||||||
|
"telemetry_altitudeValue": "*",
|
||||||
|
"telemetry_batteryValue": "*",
|
||||||
|
"telemetry_concentrationValue": "*",
|
||||||
|
"telemetry_currentValue": "*",
|
||||||
|
"telemetry_distanceValue": "*",
|
||||||
|
"telemetry_energyValue": "*",
|
||||||
|
"telemetry_frequencyValue": "*",
|
||||||
|
"telemetry_luminosityValue": "*",
|
||||||
|
"telemetry_powerValue": "*",
|
||||||
|
"telemetry_pressureValue": "*",
|
||||||
|
"telemetry_temperatureValue": "*",
|
||||||
|
"telemetry_voltageValue": "*",
|
||||||
|
"repeater_txPowerHelper": "*",
|
||||||
|
"repeater_frequencyHelper": "*",
|
||||||
|
"appSettings_batteryLifepo4": "*",
|
||||||
|
"appSettings_batteryLipo": "*",
|
||||||
|
"appSettings_batteryNmc": "*",
|
||||||
|
"appSettings_languageBg": "*",
|
||||||
|
"appSettings_languageDe": "*",
|
||||||
|
"appSettings_languageEn": "*",
|
||||||
|
"appSettings_languageEs": "*",
|
||||||
|
"appSettings_languageFr": "*",
|
||||||
|
"appSettings_languageHu": "*",
|
||||||
|
"appSettings_languageIt": "*",
|
||||||
|
"appSettings_languageJa": "*",
|
||||||
|
"appSettings_languageKo": "*",
|
||||||
|
"appSettings_languageNl": "*",
|
||||||
|
"appSettings_languagePl": "*",
|
||||||
|
"appSettings_languagePt": "*",
|
||||||
|
"appSettings_languageRu": "*",
|
||||||
|
"appSettings_languageSk": "*",
|
||||||
|
"appSettings_languageSl": "*",
|
||||||
|
"appSettings_languageSv": "*",
|
||||||
|
"appSettings_languageUk": "*",
|
||||||
|
"appSettings_languageZh": "*"
|
||||||
|
},
|
||||||
|
"pending_identical": {
|
||||||
|
"bg": [
|
||||||
|
"appSettings_translationModelDeleteFailed",
|
||||||
|
"appSettings_translationModelDeleted",
|
||||||
|
"background_serviceText",
|
||||||
|
"background_serviceTitle",
|
||||||
|
"channels_channelUpdateFailed",
|
||||||
|
"channels_via",
|
||||||
|
"chat_score",
|
||||||
|
"common_done",
|
||||||
|
"contact_typeChat",
|
||||||
|
"contact_typeRepeater",
|
||||||
|
"contact_typeRoom",
|
||||||
|
"contact_typeSensor",
|
||||||
|
"contact_typeUnknown",
|
||||||
|
"losSelectedObstructionDetails",
|
||||||
|
"map_estLocation",
|
||||||
|
"map_location",
|
||||||
|
"map_path",
|
||||||
|
"map_publicKey",
|
||||||
|
"map_publicKeyPrefixHint",
|
||||||
|
"map_type",
|
||||||
|
"repeater_actionFailed",
|
||||||
|
"repeater_actionSucceeded",
|
||||||
|
"repeater_rxAirtime",
|
||||||
|
"repeater_txAirtime",
|
||||||
|
"repeater_txPower",
|
||||||
|
"settings_deleteAllPaths",
|
||||||
|
"settings_deleteAllPathsSubtitle"
|
||||||
|
],
|
||||||
|
"de": [
|
||||||
|
"appSettings_translationModelDeleteFailed",
|
||||||
|
"appSettings_translationModelDeleted",
|
||||||
|
"background_serviceText",
|
||||||
|
"background_serviceTitle",
|
||||||
|
"channelPath_senderLabel",
|
||||||
|
"channels_channelUpdateFailed",
|
||||||
|
"channels_via",
|
||||||
|
"chat_score",
|
||||||
|
"common_done",
|
||||||
|
"contact_typeChat",
|
||||||
|
"contact_typeRepeater",
|
||||||
|
"contact_typeRoom",
|
||||||
|
"contact_typeSensor",
|
||||||
|
"contact_typeUnknown",
|
||||||
|
"debugFrame_text",
|
||||||
|
"mapCache_boundsLabel",
|
||||||
|
"map_estLocation",
|
||||||
|
"map_location",
|
||||||
|
"map_path",
|
||||||
|
"map_publicKey",
|
||||||
|
"map_publicKeyPrefixHint",
|
||||||
|
"map_sensor",
|
||||||
|
"map_type",
|
||||||
|
"repeater_cliQuickVersion",
|
||||||
|
"repeater_loopDetectMinimal",
|
||||||
|
"repeater_rxAirtime",
|
||||||
|
"repeater_status",
|
||||||
|
"repeater_txAirtime",
|
||||||
|
"repeater_txPower",
|
||||||
|
"settings_deleteAllPaths",
|
||||||
|
"settings_deleteAllPathsSubtitle",
|
||||||
|
"settings_infoName",
|
||||||
|
"settings_infoStatus"
|
||||||
|
],
|
||||||
|
"es": [
|
||||||
|
"appSettings_translationModelDeleteFailed",
|
||||||
|
"appSettings_translationModelDeleted",
|
||||||
|
"background_serviceText",
|
||||||
|
"background_serviceTitle",
|
||||||
|
"channels_channelUpdateFailed",
|
||||||
|
"channels_sortManual",
|
||||||
|
"channels_via",
|
||||||
|
"chat_score",
|
||||||
|
"common_done",
|
||||||
|
"contact_typeChat",
|
||||||
|
"contact_typeRepeater",
|
||||||
|
"contact_typeRoom",
|
||||||
|
"contact_typeSensor",
|
||||||
|
"contact_typeUnknown",
|
||||||
|
"contacts_ping",
|
||||||
|
"mapCache_boundsLabel",
|
||||||
|
"map_chat",
|
||||||
|
"map_estLocation",
|
||||||
|
"map_location",
|
||||||
|
"map_path",
|
||||||
|
"map_publicKey",
|
||||||
|
"map_publicKeyPrefixHint",
|
||||||
|
"map_sensor",
|
||||||
|
"map_type",
|
||||||
|
"repeater_actionFailed",
|
||||||
|
"repeater_actionSucceeded",
|
||||||
|
"repeater_cliCommandError",
|
||||||
|
"repeater_duplicatesTotal",
|
||||||
|
"repeater_general",
|
||||||
|
"repeater_rxAirtime",
|
||||||
|
"repeater_txAirtime",
|
||||||
|
"settings_deleteAllPaths",
|
||||||
|
"settings_deleteAllPathsSubtitle",
|
||||||
|
"settings_error"
|
||||||
|
],
|
||||||
|
"fr": [
|
||||||
|
"appSettings_notifications",
|
||||||
|
"appSettings_translationModelDeleteFailed",
|
||||||
|
"appSettings_translationModelDeleted",
|
||||||
|
"background_serviceText",
|
||||||
|
"background_serviceTitle",
|
||||||
|
"channels_channelUpdateFailed",
|
||||||
|
"channels_public",
|
||||||
|
"channels_via",
|
||||||
|
"chat_score",
|
||||||
|
"common_done",
|
||||||
|
"contact_typeChat",
|
||||||
|
"contact_typeRepeater",
|
||||||
|
"contact_typeRoom",
|
||||||
|
"contact_typeSensor",
|
||||||
|
"contact_typeUnknown",
|
||||||
|
"contacts_ping",
|
||||||
|
"losLegendTerrain",
|
||||||
|
"losPointA",
|
||||||
|
"losPointB",
|
||||||
|
"map_estLocation",
|
||||||
|
"map_location",
|
||||||
|
"map_path",
|
||||||
|
"map_publicKey",
|
||||||
|
"map_publicKeyPrefixHint",
|
||||||
|
"map_source",
|
||||||
|
"map_type",
|
||||||
|
"notification_messagesCount",
|
||||||
|
"repeater_actionsTitle",
|
||||||
|
"repeater_cliQuickVersion",
|
||||||
|
"repeater_latitude",
|
||||||
|
"repeater_localAdvertIntervalMinutes",
|
||||||
|
"repeater_longitude",
|
||||||
|
"repeater_loopDetectMinimal",
|
||||||
|
"repeater_loopDetectStrict",
|
||||||
|
"repeater_rxAirtime",
|
||||||
|
"repeater_txAirtime",
|
||||||
|
"settings_actions",
|
||||||
|
"settings_deleteAllPaths",
|
||||||
|
"settings_deleteAllPathsSubtitle",
|
||||||
|
"settings_latitude",
|
||||||
|
"settings_longitude",
|
||||||
|
"tcpPortLabel",
|
||||||
|
"telemetry_altitudeLabel",
|
||||||
|
"telemetry_concentrationLabel",
|
||||||
|
"telemetry_directionLabel",
|
||||||
|
"telemetry_distanceLabel",
|
||||||
|
"time_minutes"
|
||||||
|
],
|
||||||
|
"hu": [
|
||||||
|
"appSettings_translationModelDeleteFailed",
|
||||||
|
"appSettings_translationModelDeleted",
|
||||||
|
"background_serviceText",
|
||||||
|
"background_serviceTitle",
|
||||||
|
"channelPath_observedSomeOf",
|
||||||
|
"channels_channelUpdateFailed",
|
||||||
|
"channels_sortAZ",
|
||||||
|
"channels_via",
|
||||||
|
"chat_pathSetHops",
|
||||||
|
"chat_replyTo",
|
||||||
|
"chat_replyingTo",
|
||||||
|
"chat_score",
|
||||||
|
"common_done",
|
||||||
|
"contact_typeChat",
|
||||||
|
"contact_typeRepeater",
|
||||||
|
"contact_typeRoom",
|
||||||
|
"contact_typeSensor",
|
||||||
|
"contact_typeUnknown",
|
||||||
|
"contacts_lastSeenDaysAgo",
|
||||||
|
"contacts_ping",
|
||||||
|
"contacts_searchUsers",
|
||||||
|
"listFilter_az",
|
||||||
|
"losAntennaA",
|
||||||
|
"losAntennaB",
|
||||||
|
"losProfileClear",
|
||||||
|
"mapCache_boundsLabel",
|
||||||
|
"mapCache_cachedTilesWithFailed",
|
||||||
|
"map_estLocation",
|
||||||
|
"map_location",
|
||||||
|
"map_path",
|
||||||
|
"map_publicKey",
|
||||||
|
"map_publicKeyPrefixHint",
|
||||||
|
"map_type",
|
||||||
|
"repeater_daysHoursMinsSecs",
|
||||||
|
"repeater_rxAirtime",
|
||||||
|
"repeater_txAirtime",
|
||||||
|
"repeater_txPower",
|
||||||
|
"settings_deleteAllPaths",
|
||||||
|
"settings_deleteAllPathsSubtitle",
|
||||||
|
"time_daysAgo"
|
||||||
|
],
|
||||||
|
"it": [
|
||||||
|
"appSettings_translationModelDeleteFailed",
|
||||||
|
"appSettings_translationModelDeleted",
|
||||||
|
"background_serviceText",
|
||||||
|
"background_serviceTitle",
|
||||||
|
"channels_channelUpdateFailed",
|
||||||
|
"channels_via",
|
||||||
|
"chat_score",
|
||||||
|
"common_done",
|
||||||
|
"contact_typeChat",
|
||||||
|
"contact_typeRepeater",
|
||||||
|
"contact_typeRoom",
|
||||||
|
"contact_typeSensor",
|
||||||
|
"contact_typeUnknown",
|
||||||
|
"contacts_ping",
|
||||||
|
"login_password",
|
||||||
|
"losAntennaA",
|
||||||
|
"losAntennaB",
|
||||||
|
"losSelectedObstructionDetails",
|
||||||
|
"mapCache_boundsLabel",
|
||||||
|
"map_chat",
|
||||||
|
"map_estLocation",
|
||||||
|
"map_location",
|
||||||
|
"map_path",
|
||||||
|
"map_publicKey",
|
||||||
|
"map_publicKeyPrefixHint",
|
||||||
|
"map_type",
|
||||||
|
"repeater_actionFailed",
|
||||||
|
"repeater_rxAirtime",
|
||||||
|
"repeater_txAirtime",
|
||||||
|
"settings_deleteAllPaths",
|
||||||
|
"settings_deleteAllPathsSubtitle"
|
||||||
|
],
|
||||||
|
"ja": [
|
||||||
|
"appSettings_translationModelDeleteFailed",
|
||||||
|
"appSettings_translationModelDeleted",
|
||||||
|
"background_serviceText",
|
||||||
|
"background_serviceTitle",
|
||||||
|
"channelPath_observedSomeOf",
|
||||||
|
"channels_channelUpdateFailed",
|
||||||
|
"channels_via",
|
||||||
|
"chat_pathSetHops",
|
||||||
|
"chat_score",
|
||||||
|
"common_done",
|
||||||
|
"contact_typeChat",
|
||||||
|
"contact_typeRepeater",
|
||||||
|
"contact_typeRoom",
|
||||||
|
"contact_typeSensor",
|
||||||
|
"contact_typeUnknown",
|
||||||
|
"losProfileBlocked",
|
||||||
|
"losProfileClear",
|
||||||
|
"losStatusSummary",
|
||||||
|
"mapCache_boundsLabel",
|
||||||
|
"mapCache_cachedTilesWithFailed",
|
||||||
|
"mapCache_downloadedTiles",
|
||||||
|
"map_estLocation",
|
||||||
|
"map_location",
|
||||||
|
"map_path",
|
||||||
|
"map_publicKey",
|
||||||
|
"map_publicKeyPrefixHint",
|
||||||
|
"map_type",
|
||||||
|
"notification_messagesCount",
|
||||||
|
"settings_deleteAllPaths",
|
||||||
|
"settings_deleteAllPathsSubtitle"
|
||||||
|
],
|
||||||
|
"ko": [
|
||||||
|
"appSettings_translationModelDeleteFailed",
|
||||||
|
"appSettings_translationModelDeleted",
|
||||||
|
"background_serviceText",
|
||||||
|
"background_serviceTitle",
|
||||||
|
"channelPath_observedSomeOf",
|
||||||
|
"channels_channelUpdateFailed",
|
||||||
|
"channels_via",
|
||||||
|
"chat_pathSetHops",
|
||||||
|
"chat_score",
|
||||||
|
"common_done",
|
||||||
|
"contact_typeChat",
|
||||||
|
"contact_typeRepeater",
|
||||||
|
"contact_typeRoom",
|
||||||
|
"contact_typeSensor",
|
||||||
|
"contact_typeUnknown",
|
||||||
|
"contacts_lastSeenHoursAgo",
|
||||||
|
"contacts_lastSeenMinsAgo",
|
||||||
|
"losAntennaB",
|
||||||
|
"losProfileBlocked",
|
||||||
|
"losProfileClear",
|
||||||
|
"losSelectedObstructionDetails",
|
||||||
|
"mapCache_boundsLabel",
|
||||||
|
"mapCache_cachedTilesWithFailed",
|
||||||
|
"mapCache_downloadedTiles",
|
||||||
|
"map_estLocation",
|
||||||
|
"map_location",
|
||||||
|
"map_path",
|
||||||
|
"map_publicKey",
|
||||||
|
"map_publicKeyPrefixHint",
|
||||||
|
"map_type",
|
||||||
|
"neighbors_heardAgo",
|
||||||
|
"path_usingHopsPath",
|
||||||
|
"settings_deleteAllPaths",
|
||||||
|
"settings_deleteAllPathsSubtitle",
|
||||||
|
"time_hoursAgo"
|
||||||
|
],
|
||||||
|
"nl": [
|
||||||
|
"appSettings_translationModelDeleteFailed",
|
||||||
|
"appSettings_translationModelDeleted",
|
||||||
|
"background_serviceText",
|
||||||
|
"background_serviceTitle",
|
||||||
|
"channelPath_directPath",
|
||||||
|
"channels_channelUpdateFailed",
|
||||||
|
"channels_via",
|
||||||
|
"chat_direct",
|
||||||
|
"chat_hopsCount",
|
||||||
|
"chat_score",
|
||||||
|
"common_done",
|
||||||
|
"contact_typeChat",
|
||||||
|
"contact_typeRepeater",
|
||||||
|
"contact_typeRoom",
|
||||||
|
"contact_typeSensor",
|
||||||
|
"contact_typeUnknown",
|
||||||
|
"debugLog_bleTitle",
|
||||||
|
"listFilter_filters",
|
||||||
|
"losSelectedObstructionDetails",
|
||||||
|
"mapCache_boundsLabel",
|
||||||
|
"map_chat",
|
||||||
|
"map_estLocation",
|
||||||
|
"map_location",
|
||||||
|
"map_path",
|
||||||
|
"map_publicKey",
|
||||||
|
"map_publicKeyPrefixHint",
|
||||||
|
"map_sensor",
|
||||||
|
"map_type",
|
||||||
|
"repeater_actionFailed",
|
||||||
|
"repeater_status",
|
||||||
|
"repeater_txPower",
|
||||||
|
"settings_deleteAllPaths",
|
||||||
|
"settings_deleteAllPathsSubtitle",
|
||||||
|
"settings_infoStatus",
|
||||||
|
"telemetry_gyrometerLabel",
|
||||||
|
"telemetry_percentageLabel",
|
||||||
|
"time_week"
|
||||||
|
],
|
||||||
|
"pl": [
|
||||||
|
"appSettings_translationModelDeleteFailed",
|
||||||
|
"appSettings_translationModelDeleted",
|
||||||
|
"background_serviceText",
|
||||||
|
"background_serviceTitle",
|
||||||
|
"channels_channelUpdateFailed",
|
||||||
|
"channels_via",
|
||||||
|
"chat_score",
|
||||||
|
"common_done",
|
||||||
|
"contact_typeChat",
|
||||||
|
"contact_typeRepeater",
|
||||||
|
"contact_typeRoom",
|
||||||
|
"contact_typeSensor",
|
||||||
|
"contact_typeUnknown",
|
||||||
|
"losSelectedObstructionDetails",
|
||||||
|
"mapCache_boundsLabel",
|
||||||
|
"map_estLocation",
|
||||||
|
"map_location",
|
||||||
|
"map_path",
|
||||||
|
"map_publicKey",
|
||||||
|
"map_publicKeyPrefixHint",
|
||||||
|
"map_type",
|
||||||
|
"repeater_actionFailed",
|
||||||
|
"settings_deleteAllPaths",
|
||||||
|
"settings_deleteAllPathsSubtitle",
|
||||||
|
"tcpPortLabel"
|
||||||
|
],
|
||||||
|
"pt": [
|
||||||
|
"appSettings_translationModelDeleteFailed",
|
||||||
|
"appSettings_translationModelDeleted",
|
||||||
|
"background_serviceText",
|
||||||
|
"background_serviceTitle",
|
||||||
|
"channels_channelUpdateFailed",
|
||||||
|
"channels_sortManual",
|
||||||
|
"channels_via",
|
||||||
|
"chat_score",
|
||||||
|
"common_done",
|
||||||
|
"contact_typeChat",
|
||||||
|
"contact_typeRepeater",
|
||||||
|
"contact_typeRoom",
|
||||||
|
"contact_typeSensor",
|
||||||
|
"contact_typeUnknown",
|
||||||
|
"losSelectedObstructionDetails",
|
||||||
|
"mapCache_boundsLabel",
|
||||||
|
"map_chat",
|
||||||
|
"map_estLocation",
|
||||||
|
"map_location",
|
||||||
|
"map_path",
|
||||||
|
"map_publicKey",
|
||||||
|
"map_publicKeyPrefixHint",
|
||||||
|
"map_sensor",
|
||||||
|
"map_type",
|
||||||
|
"repeater_actionFailed",
|
||||||
|
"repeater_actionSucceeded",
|
||||||
|
"repeater_duplicatesTotal",
|
||||||
|
"repeater_latitude",
|
||||||
|
"repeater_longitude",
|
||||||
|
"repeater_rxAirtime",
|
||||||
|
"repeater_txAirtime",
|
||||||
|
"settings_deleteAllPaths",
|
||||||
|
"settings_deleteAllPathsSubtitle",
|
||||||
|
"settings_latitude",
|
||||||
|
"settings_longitude",
|
||||||
|
"settings_multiAck",
|
||||||
|
"telemetry_altitudeLabel"
|
||||||
|
],
|
||||||
|
"ru": [
|
||||||
|
"common_ok",
|
||||||
|
"losSelectedObstructionDetails",
|
||||||
|
"repeater_actionFailed",
|
||||||
|
"repeater_actionSucceeded",
|
||||||
|
"settings_deleteAllPaths",
|
||||||
|
"settings_deleteAllPathsSubtitle"
|
||||||
|
],
|
||||||
|
"sk": [
|
||||||
|
"appSettings_translationModelDeleteFailed",
|
||||||
|
"appSettings_translationModelDeleted",
|
||||||
|
"background_serviceText",
|
||||||
|
"background_serviceTitle",
|
||||||
|
"channels_channelUpdateFailed",
|
||||||
|
"channels_via",
|
||||||
|
"chat_score",
|
||||||
|
"common_done",
|
||||||
|
"contact_typeChat",
|
||||||
|
"contact_typeRepeater",
|
||||||
|
"contact_typeRoom",
|
||||||
|
"contact_typeSensor",
|
||||||
|
"contact_typeUnknown",
|
||||||
|
"debugFrame_text",
|
||||||
|
"losSelectedObstructionDetails",
|
||||||
|
"mapCache_boundsLabel",
|
||||||
|
"map_estLocation",
|
||||||
|
"map_location",
|
||||||
|
"map_path",
|
||||||
|
"map_publicKey",
|
||||||
|
"map_publicKeyPrefixHint",
|
||||||
|
"map_type",
|
||||||
|
"repeater_actionFailed",
|
||||||
|
"repeater_actionSucceeded",
|
||||||
|
"repeater_rxAirtime",
|
||||||
|
"repeater_txAirtime",
|
||||||
|
"repeater_txPower",
|
||||||
|
"settings_deleteAllPaths",
|
||||||
|
"settings_deleteAllPathsSubtitle",
|
||||||
|
"telemetry_gyrometerLabel"
|
||||||
|
],
|
||||||
|
"sl": [
|
||||||
|
"appSettings_translationModelDeleteFailed",
|
||||||
|
"appSettings_translationModelDeleted",
|
||||||
|
"background_serviceText",
|
||||||
|
"background_serviceTitle",
|
||||||
|
"channels_channelUpdateFailed",
|
||||||
|
"channels_via",
|
||||||
|
"chat_score",
|
||||||
|
"common_done",
|
||||||
|
"contact_typeChat",
|
||||||
|
"contact_typeRepeater",
|
||||||
|
"contact_typeRoom",
|
||||||
|
"contact_typeSensor",
|
||||||
|
"contact_typeUnknown",
|
||||||
|
"contacts_pathTraceTo",
|
||||||
|
"losSelectedObstructionDetails",
|
||||||
|
"mapCache_boundsLabel",
|
||||||
|
"map_estLocation",
|
||||||
|
"map_location",
|
||||||
|
"map_path",
|
||||||
|
"map_publicKey",
|
||||||
|
"map_publicKeyPrefixHint",
|
||||||
|
"map_type",
|
||||||
|
"repeater_rxAirtime",
|
||||||
|
"repeater_txAirtime",
|
||||||
|
"settings_deleteAllPaths",
|
||||||
|
"settings_deleteAllPathsSubtitle"
|
||||||
|
],
|
||||||
|
"sv": [
|
||||||
|
"appSettings_translationModelDeleteFailed",
|
||||||
|
"appSettings_translationModelDeleted",
|
||||||
|
"background_serviceText",
|
||||||
|
"background_serviceTitle",
|
||||||
|
"channels_channelUpdateFailed",
|
||||||
|
"channels_sortAZ",
|
||||||
|
"channels_via",
|
||||||
|
"chat_score",
|
||||||
|
"common_done",
|
||||||
|
"contact_typeChat",
|
||||||
|
"contact_typeRepeater",
|
||||||
|
"contact_typeRoom",
|
||||||
|
"contact_typeSensor",
|
||||||
|
"contact_typeUnknown",
|
||||||
|
"contacts_ping",
|
||||||
|
"debugFrame_text",
|
||||||
|
"listFilter_az",
|
||||||
|
"losSelectedObstructionDetails",
|
||||||
|
"mapCache_boundsLabel",
|
||||||
|
"map_chat",
|
||||||
|
"map_estLocation",
|
||||||
|
"map_location",
|
||||||
|
"map_path",
|
||||||
|
"map_publicKey",
|
||||||
|
"map_publicKeyPrefixHint",
|
||||||
|
"map_sensor",
|
||||||
|
"map_type",
|
||||||
|
"repeater_cliQuickVersion",
|
||||||
|
"repeater_loopDetectMinimal",
|
||||||
|
"repeater_rxAirtime",
|
||||||
|
"repeater_status",
|
||||||
|
"repeater_txAirtime",
|
||||||
|
"settings_deleteAllPaths",
|
||||||
|
"settings_deleteAllPathsSubtitle",
|
||||||
|
"settings_infoStatus",
|
||||||
|
"telemetry_accelerometerLabel",
|
||||||
|
"telemetry_gyrometerLabel"
|
||||||
|
],
|
||||||
|
"uk": [
|
||||||
|
"losSelectedObstructionDetails",
|
||||||
|
"repeater_actionFailed",
|
||||||
|
"repeater_actionSucceeded"
|
||||||
|
],
|
||||||
|
"zh": [
|
||||||
|
"appSettings_translationModelDeleteFailed",
|
||||||
|
"appSettings_translationModelDeleted",
|
||||||
|
"background_serviceText",
|
||||||
|
"background_serviceTitle",
|
||||||
|
"channels_channelUpdateFailed",
|
||||||
|
"channels_via",
|
||||||
|
"chat_score",
|
||||||
|
"common_done",
|
||||||
|
"contact_typeChat",
|
||||||
|
"contact_typeRepeater",
|
||||||
|
"contact_typeRoom",
|
||||||
|
"contact_typeSensor",
|
||||||
|
"contact_typeUnknown",
|
||||||
|
"losSelectedObstructionDetails",
|
||||||
|
"map_estLocation",
|
||||||
|
"map_location",
|
||||||
|
"map_path",
|
||||||
|
"map_publicKey",
|
||||||
|
"map_publicKeyPrefixHint",
|
||||||
|
"map_type",
|
||||||
|
"settings_deleteAllPaths",
|
||||||
|
"settings_deleteAllPathsSubtitle"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,262 @@
|
|||||||
|
"""Tests for check_arb.py (#1323): one deliberately broken string per rule."""
|
||||||
|
|
||||||
|
import io
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import tempfile
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
|
||||||
|
import check_arb # noqa: E402
|
||||||
|
|
||||||
|
REPO = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||||||
|
|
||||||
|
ENGLISH = {
|
||||||
|
"@@locale": "en",
|
||||||
|
"greeting": "Hello {name}",
|
||||||
|
"@greeting": {"placeholders": {"name": {"type": "String"}}},
|
||||||
|
"hops": "{count} {count, plural, =1{hop} other{hops}}",
|
||||||
|
"minutes": "{minutes} min",
|
||||||
|
"@minutes": {"placeholders": {"minutes": {"type": "int"}}},
|
||||||
|
"pronoun": "{gender, select, male{He} female{She} other{They}}",
|
||||||
|
"percent": "{percent}%",
|
||||||
|
"chat": "Chat",
|
||||||
|
"title": "Offband MeshCore",
|
||||||
|
"untranslated": "Delete All Paths",
|
||||||
|
}
|
||||||
|
|
||||||
|
GERMAN = {
|
||||||
|
"@@locale": "de",
|
||||||
|
"greeting": "Hallo {name}",
|
||||||
|
"hops": "{count} {count, plural, =1{Hop} other{Hops}}",
|
||||||
|
"minutes": "{minutes} Min.",
|
||||||
|
"pronoun": "{gender, select, male{Er} female{Sie} other{Sie}}",
|
||||||
|
"percent": "{percent}%",
|
||||||
|
"chat": "Unterhaltung",
|
||||||
|
"title": "Offband MeshCore",
|
||||||
|
"untranslated": "Alle Pfade löschen",
|
||||||
|
}
|
||||||
|
|
||||||
|
CONFIG = {
|
||||||
|
"fail_on_missing": False,
|
||||||
|
"allow_identical": {"title": "*"},
|
||||||
|
"pending_identical": {},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class CheckArbTest(unittest.TestCase):
|
||||||
|
def run_check(self, german=None, config=None, raw_german=None, english=None, l10n_yaml=None):
|
||||||
|
with tempfile.TemporaryDirectory() as tmp:
|
||||||
|
l10n_dir = os.path.join(tmp, "lib", "l10n")
|
||||||
|
os.makedirs(l10n_dir)
|
||||||
|
if l10n_yaml is not None:
|
||||||
|
with open(os.path.join(tmp, "l10n.yaml"), "w", encoding="utf-8") as fh:
|
||||||
|
fh.write(l10n_yaml)
|
||||||
|
with open(os.path.join(l10n_dir, "app_en.arb"), "w", encoding="utf-8") as fh:
|
||||||
|
json.dump(english or ENGLISH, fh, ensure_ascii=False)
|
||||||
|
with open(os.path.join(l10n_dir, "app_de.arb"), "w", encoding="utf-8") as fh:
|
||||||
|
fh.write(raw_german if raw_german is not None else json.dumps(german or GERMAN, ensure_ascii=False))
|
||||||
|
config_path = os.path.join(tmp, "config.json")
|
||||||
|
with open(config_path, "w", encoding="utf-8") as fh:
|
||||||
|
json.dump(config or CONFIG, fh)
|
||||||
|
out = io.StringIO()
|
||||||
|
code = check_arb.run(l10n_dir, config_path, out)
|
||||||
|
return code, out.getvalue()
|
||||||
|
|
||||||
|
def assert_fails(self, german, expected, config=None):
|
||||||
|
code, out = self.run_check(german, config)
|
||||||
|
self.assertEqual(code, 1, out)
|
||||||
|
self.assertIn(expected, out)
|
||||||
|
|
||||||
|
def with_german(self, **changes):
|
||||||
|
german = dict(GERMAN)
|
||||||
|
for key, value in changes.items():
|
||||||
|
if value is None:
|
||||||
|
german.pop(key)
|
||||||
|
else:
|
||||||
|
german[key] = value
|
||||||
|
return german
|
||||||
|
|
||||||
|
def test_a_correct_translation_passes(self):
|
||||||
|
code, out = self.run_check()
|
||||||
|
self.assertEqual(code, 0, out)
|
||||||
|
self.assertIn("check_arb: OK", out)
|
||||||
|
|
||||||
|
def test_dropped_placeholder_fails(self):
|
||||||
|
self.assert_fails(self.with_german(greeting="Hallo"), "'greeting': drops {name}")
|
||||||
|
|
||||||
|
def test_renamed_placeholder_fails(self):
|
||||||
|
code, out = self.run_check(self.with_german(greeting="Hallo {nmae}"))
|
||||||
|
self.assertEqual(code, 1, out)
|
||||||
|
self.assertIn("'greeting': drops {name}", out)
|
||||||
|
self.assertIn("'greeting': adds {nmae}", out)
|
||||||
|
|
||||||
|
def test_added_placeholder_fails(self):
|
||||||
|
self.assert_fails(self.with_german(greeting="Hallo {name} {extra}"), "'greeting': adds {extra}")
|
||||||
|
|
||||||
|
def test_plural_without_other_fails(self):
|
||||||
|
self.assert_fails(
|
||||||
|
self.with_german(hops="{count} {count, plural, =1{Hop}}"),
|
||||||
|
"'{count, plural' has no 'other' case",
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_unknown_plural_category_fails(self):
|
||||||
|
self.assert_fails(
|
||||||
|
self.with_german(hops="{count} {count, plural, =1{Hop} several{Hops} other{Hops}}"),
|
||||||
|
"unknown cases: several",
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_unclosed_brace_fails(self):
|
||||||
|
self.assert_fails(self.with_german(greeting="Hallo {name"), "'greeting': does not parse")
|
||||||
|
|
||||||
|
def test_stray_closing_brace_fails(self):
|
||||||
|
self.assert_fails(self.with_german(greeting="Hallo {name}}"), "'greeting': does not parse")
|
||||||
|
|
||||||
|
def test_unbalanced_plural_fails(self):
|
||||||
|
self.assert_fails(
|
||||||
|
self.with_german(hops="{count} {count, plural, =1{Hop other{Hops}}"),
|
||||||
|
"'hops': does not parse",
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_renamed_selector_variable_fails(self):
|
||||||
|
self.assert_fails(
|
||||||
|
self.with_german(hops="{count} {anzahl, plural, =1{Hop} other{Hops}}"),
|
||||||
|
"'hops': adds {anzahl}",
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_select_without_other_fails(self):
|
||||||
|
self.assert_fails(
|
||||||
|
self.with_german(pronoun="{gender, select, male{Er} female{Sie}}"),
|
||||||
|
"'{gender, select' has no 'other' case",
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_repeated_case_fails(self):
|
||||||
|
self.assert_fails(
|
||||||
|
self.with_german(hops="{count} {count, plural, one{Hop} one{Sprung} other{Hops}}"),
|
||||||
|
"repeats cases: one",
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_plural_over_a_text_placeholder_fails(self):
|
||||||
|
self.assert_fails(
|
||||||
|
self.with_german(greeting="Hallo {name, plural, one{du} other{ihr}}"),
|
||||||
|
"'{name, plural' counts a placeholder English does not declare as a number",
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_plural_over_a_number_placeholder_passes(self):
|
||||||
|
code, out = self.run_check(
|
||||||
|
self.with_german(minutes="{minutes} {minutes, plural, one{Minute} other{Minuten}}")
|
||||||
|
)
|
||||||
|
self.assertEqual(code, 0, out)
|
||||||
|
|
||||||
|
def test_malformed_english_fails(self):
|
||||||
|
english = dict(ENGLISH, greeting="Hello {name")
|
||||||
|
code, out = self.run_check(english=english)
|
||||||
|
self.assertEqual(code, 1, out)
|
||||||
|
self.assertIn("FAIL app_en.arb: 'greeting' does not parse", out)
|
||||||
|
|
||||||
|
def test_escaping_turned_on_fails(self):
|
||||||
|
code, out = self.run_check(l10n_yaml="arb-dir: lib/l10n\nuse-escaping: true\n")
|
||||||
|
self.assertEqual(code, 1, out)
|
||||||
|
self.assertIn("use-escaping is on", out)
|
||||||
|
|
||||||
|
def test_escaping_turned_on_with_a_quoted_value_fails(self):
|
||||||
|
code, out = self.run_check(l10n_yaml='use-escaping: "true"\n')
|
||||||
|
self.assertEqual(code, 1, out)
|
||||||
|
self.assertIn("use-escaping is on", out)
|
||||||
|
|
||||||
|
def test_english_value_that_is_not_a_string_fails(self):
|
||||||
|
english = dict(ENGLISH, chat=123)
|
||||||
|
code, out = self.run_check(english=english)
|
||||||
|
self.assertEqual(code, 1, out)
|
||||||
|
self.assertIn("FAIL app_en.arb: 'chat' is not a string", out)
|
||||||
|
|
||||||
|
def test_escaping_left_off_passes(self):
|
||||||
|
code, out = self.run_check(l10n_yaml="arb-dir: lib/l10n\nuse-escaping: false\n")
|
||||||
|
self.assertEqual(code, 0, out)
|
||||||
|
|
||||||
|
def test_dropping_a_plural_block_but_keeping_the_count_passes(self):
|
||||||
|
code, out = self.run_check(self.with_german(hops="{count} Hops"))
|
||||||
|
self.assertEqual(code, 0, out)
|
||||||
|
|
||||||
|
def test_empty_translation_fails(self):
|
||||||
|
self.assert_fails(self.with_german(chat=""), "'chat': empty translation")
|
||||||
|
|
||||||
|
def test_identical_to_english_fails(self):
|
||||||
|
self.assert_fails(self.with_german(chat="Chat"), "'chat' is identical to English")
|
||||||
|
|
||||||
|
def test_identical_apart_from_spacing_fails(self):
|
||||||
|
self.assert_fails(self.with_german(chat=" Chat "), "'chat' is identical to English")
|
||||||
|
|
||||||
|
def test_a_change_of_case_alone_is_a_translation(self):
|
||||||
|
english = dict(ENGLISH, minutes="{minutes} min.")
|
||||||
|
code, out = self.run_check(self.with_german(minutes="{minutes} Min."), english=english)
|
||||||
|
self.assertEqual(code, 0, out)
|
||||||
|
|
||||||
|
def test_identical_to_english_is_allowed_when_allowlisted(self):
|
||||||
|
config = dict(CONFIG, allow_identical={"title": "*", "chat": ["de"]})
|
||||||
|
code, out = self.run_check(self.with_german(chat="Chat"), config)
|
||||||
|
self.assertEqual(code, 0, out)
|
||||||
|
|
||||||
|
def test_allowlist_for_another_locale_does_not_cover_this_one(self):
|
||||||
|
config = dict(CONFIG, allow_identical={"title": "*", "chat": ["fr"]})
|
||||||
|
self.assert_fails(self.with_german(chat="Chat"), "'chat' is identical to English", config)
|
||||||
|
|
||||||
|
def test_identical_to_english_is_allowed_while_pending(self):
|
||||||
|
config = dict(CONFIG, pending_identical={"de": ["untranslated"]})
|
||||||
|
code, out = self.run_check(self.with_german(untranslated="Delete All Paths"), config)
|
||||||
|
self.assertEqual(code, 0, out)
|
||||||
|
|
||||||
|
def test_pending_entry_that_is_now_translated_fails(self):
|
||||||
|
config = dict(CONFIG, pending_identical={"de": ["untranslated"]})
|
||||||
|
self.assert_fails(GERMAN, "'untranslated' is listed in pending_identical", config)
|
||||||
|
|
||||||
|
def test_text_with_no_words_may_match_english(self):
|
||||||
|
code, out = self.run_check(self.with_german(percent="{percent}%"))
|
||||||
|
self.assertEqual(code, 0, out)
|
||||||
|
|
||||||
|
def test_key_missing_from_english_fails(self):
|
||||||
|
self.assert_fails(self.with_german(gone="Weg"), "'gone' is not in app_en.arb")
|
||||||
|
|
||||||
|
def test_metadata_for_a_key_missing_from_english_fails(self):
|
||||||
|
self.assert_fails(self.with_german(**{"@gone": {}}), "'@gone' is metadata")
|
||||||
|
|
||||||
|
def test_missing_key_is_reported_not_failed(self):
|
||||||
|
code, out = self.run_check(self.with_german(chat=None))
|
||||||
|
self.assertEqual(code, 0, out)
|
||||||
|
self.assertIn("note app_de.arb: 1 keys not translated yet", out)
|
||||||
|
|
||||||
|
def test_missing_key_fails_once_fail_on_missing_is_set(self):
|
||||||
|
config = dict(CONFIG, fail_on_missing=True)
|
||||||
|
self.assert_fails(self.with_german(chat=None), "1 keys missing: chat", config)
|
||||||
|
|
||||||
|
def test_duplicate_key_fails(self):
|
||||||
|
raw = json.dumps(GERMAN, ensure_ascii=False)[:-1] + ', "chat": "Plaudern"}'
|
||||||
|
code, out = self.run_check(raw_german=raw)
|
||||||
|
self.assertEqual(code, 1, out)
|
||||||
|
self.assertIn("duplicate key 'chat'", out)
|
||||||
|
|
||||||
|
def test_locale_that_does_not_match_the_file_name_fails(self):
|
||||||
|
self.assert_fails(self.with_german(**{"@@locale": "fr"}), "@@locale is 'fr'")
|
||||||
|
|
||||||
|
|
||||||
|
class RepositoryTest(unittest.TestCase):
|
||||||
|
def test_the_repository_passes(self):
|
||||||
|
out = io.StringIO()
|
||||||
|
code = check_arb.run(
|
||||||
|
os.path.join(REPO, "lib", "l10n"),
|
||||||
|
os.path.join(REPO, "tools", "l10n", "l10n_check.json"),
|
||||||
|
out,
|
||||||
|
)
|
||||||
|
self.assertEqual(code, 0, out.getvalue())
|
||||||
|
|
||||||
|
def test_every_allowlisted_key_exists(self):
|
||||||
|
template, _ = check_arb.load_arb(os.path.join(REPO, "lib", "l10n", "app_en.arb"))
|
||||||
|
config = check_arb.load_config(os.path.join(REPO, "tools", "l10n", "l10n_check.json"))
|
||||||
|
stale = [k for k in config["allow_identical"] if k not in template]
|
||||||
|
self.assertEqual(stale, [])
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
unittest.main()
|
||||||
Loading…
Reference in new issue