cd D:\orisys_ws\orisys-app
git add apps/studio/config/locales/zh_CN.json `
apps/studio/config/locales/en_US.json `
apps/studio/tests/test_locales.py `
apps/studio/tools/ui_check.py `
apps/studio/tests/test_ui_smoke.py `
apps/studio/src/orisys_studio/app_window.py `
apps/studio/src/orisys_studio/ui/cal_panel.py `
apps/studio/src/orisys_studio/ui/playback_dialog.py `
apps/studio/src/orisys_studio/ui/force_plots.py `
apps/studio/docs/record-channel.md `
shared/src/orisys_app_shared/force/calibration_recorder.py `
shared/src/orisys_app_shared/record/__init__.py `
shared/src/orisys_app_shared/record/playback.py `
shared/src/orisys_app_shared/record/depth.py `
shared/tests/test_record_channel.py `
shared/tests/test_playback.py
This commit is contained in:
@@ -74,3 +74,46 @@ def test_locale_files_are_valid_utf8_json():
|
||||
data = _load_locale(name)
|
||||
assert isinstance(data, dict)
|
||||
assert data.get("app", {}).get("title")
|
||||
|
||||
|
||||
#: Sequences that only ever appear when UTF-8 text was decoded as a single-byte
|
||||
#: codepage and then re-encoded. A ``Get-Content -Raw | Set-Content`` round trip
|
||||
#: in Windows PowerShell does exactly that and silently mangles every non-ASCII
|
||||
#: string, which is how the Chinese UI once ended up unreadable.
|
||||
#:
|
||||
#: Written as escapes, with no literal examples in the comments, so that this
|
||||
#: guard cannot itself be corrupted by the same mistake.
|
||||
_MOJIBAKE = (
|
||||
"\u00c3",
|
||||
"\u00c2",
|
||||
"\u00e2\u20ac",
|
||||
"\u00e3\u20ac",
|
||||
"\u00ef\u00bf\u00bd",
|
||||
)
|
||||
|
||||
|
||||
def test_locale_files_are_utf8_without_bom_and_not_mojibake():
|
||||
for name in ("zh_CN", "en_US"):
|
||||
path = LOCALES_DIR / f"{name}.json"
|
||||
raw = path.read_bytes()
|
||||
assert not raw.startswith(b"\xef\xbb\xbf"), f"{name}.json starts with a BOM"
|
||||
text = raw.decode("utf-8") # raises if it is not valid UTF-8
|
||||
|
||||
for sequence in _MOJIBAKE:
|
||||
assert sequence not in text, (
|
||||
f"{name}.json contains {sequence!r}: the file was decoded with the "
|
||||
"wrong encoding. Rewrite it with an explicit UTF-8 writer instead "
|
||||
"of a PowerShell Get-Content/Set-Content round trip."
|
||||
)
|
||||
|
||||
|
||||
def test_chinese_locale_actually_contains_chinese():
|
||||
"""A corrupted zh_CN.json still parses as JSON, so check the content."""
|
||||
data = _load_locale("zh_CN")
|
||||
for key in ("menu/theme_dark", "app/about_title", "chart/mode_follow"):
|
||||
node = data
|
||||
for part in key.split("/"):
|
||||
node = node[part]
|
||||
assert any("\u4e00" <= char <= "\u9fff" for char in node), (
|
||||
f"zh_CN.{key} has no Chinese characters: {node!r}"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user