8000 i18n: Russian support for user-facing surfaces via --lang / MTK_LANG (default: en) by 0-danielviktorovich-0 · Pull Request #471 · bkerler/mtkclient · GitHub
[go: up one dir, main page]

Skip to content

i18n: Russian support for user-facing surfaces via --lang / MTK_LANG (default: en) - #471

Open
0-danielviktorovich-0 wants to merge 11 commits into
bkerler:mainfrom
0-danielviktorovich-0:i18n-ru
Open

0-danielviktorovich-0 wants to merge 11 commits into
bkerler:mainfrom
0-danielviktorovich-0:i18n-ru

Conversation

@0-danielviktorovich-0
@0-danielviktorovich-0 0-danielviktorovich-0 commented Nov 26, 2026 •
Copy link
Copy Markdown

This adds a ru translation layer for the user-facing surfaces: --lang ru / MTK_LANG=ru switches
argparse help (~150 strings, 34 commands + 5 groups), the hardcoded GUI strings in mtk_gui.py
(serial-port dialog, View/Dark Mode menu, progress labels, boot modes), and the existing upstream
Qt translation (ru_RU.qm shipped upstream, reused via MTK_LANG, not duplicated). Docs get
Russian .ru-RU.md siblings following the repo's zh-CN convention. Default en: string rendering byte-identical
to upstream (help, GUI and docs strings; the only CLI change is the additive --lang flag).

Design (minimal-invasive):

  • New mtkclient/i18n.py: po-like en/ru dictionaries; activation priority --lang ru > MTK_LANG > default en.
  • Default en string rendering is byte-identical to upstream (verified: en smoke diff-empty); the
    only CLI change is the additive --lang flag.
  • Library/ internals (263 print sites) intentionally stay EN. That keeps the diff reviewable;
    user-facing CLI/GUI surfaces only.
  • Case normalization for both activation doors (--lang RU == MTK_LANG=RU); unknown langs fall
    back to en.
  • No opt-in means upstream behavior is unchanged (byte-parity verified). Commits are English per
    project convention.

Verification

  • Test suite: 14/14 i18n tests (activation matrix, ru rendering, en-default byte-parity, zz
    fallback, AST ratchet 34/34 guarding dict keys) + upstream suite green; GUI offscreen smoke
    (ru_RU.qm engaged, en untouched); flake8 clean on new files.
  • A second review pass found three gaps, all fixed: seed/aeskey help translated, --lang
    normalization, ratchet extended.

Documentation (Russian)

  • README.ru-RU.md (switcher in README.md) + README-INSTALL/USAGE/WINDOWS.ru-RU.md,
    learning_resources.ru-RU.md, src/stage1/build.ru-RU.md, following the repo's existing zh-CN
    convention; commands/flags/BROM/DA/preloader terms untouched.
  • Tools/*.txt are byte-identical hwcode-table dumps and preloader-emulation UART traces with no
    translatable prose (verified), so no ru copies needed.

Related

Update 2026-12-01

@0-danielviktorovich-0
0-danielviktorovich-0 commented Nov 26, 2026 •
Copy link
Copy Markdown
Author

Second pass over this PR with real execution checks (Python 3.13, venv); three minor holes found
and fixed on the branch (bc21e2e; the pre-rework sha c847370 is renumbered - see the history
note in the description). Everything in the description reproduces.

  • Suite: 14/14 OK (~1.0s). Both ratchets self-tested adversarially: injecting a constant t() key
    / a fake CMDS_HELP value makes the suite FAIL naming the exact offender; clean tree passes.
  • en default is byte-identical: mtk --help vs the upstream merge-base (f591dcf) differs only by
    the additive [--lang {en,ru}] usage token and the Language: group; everything else
    byte-for-byte equal.
  • Smoke matrix: MTK_LANG=ru renders Russian (top-level and subcommand help; --lang works before
    and after the subcommand); MTK_LANG=zz → English + stderr warning; --lang en overrides
    MTK_LANG=ru; MTK_LANG=" RU " normalizes.
  • GUI (PySide6, offscreen): with MTK_LANG=ru the existing ru_RU.qm loads via MTK_LANG
    (' left' → ' осталось'), hardcoded dialog/buttons/menu strings render Russian; default →
    unchanged English. Qt translate() call sites are untouched, and the HTML progress labels keep
    their <b> markup.
  • flake8 (repo config, max-line-length 255): new files clean; mtk.py violation set identical to
    base; mtk_gui.py is exactly −1 pre-existing F541 (as stated in the PR body).
  • Translation quality: terminology preserved (BROM / DA / preloader / GPT / RPMB / kamakiri /
    payload / efuse / vbmeta / seccfg / wdt stay untranslated), natural register, no MT artifacts or
    calques. Non-blocking nits: «сектора» → normative «секторы»; «автовыбор» for autodetection
    («автоопределение» is closer).
  • Security: no secrets, no hardcoded paths, no network; only reads MTK_LANG; the unknown-language
    warning goes to stderr.

The three holes, fixed in bc21e2e:

  1. Coverage gap: help='seed' / help='aeskey' in da nvitem / da imei (4 sites) were not
    wrapped in t(), invisible to the ratchet and untranslated in the ru locale.
  2. Inconsistent doors: the env path normalizes case (MTK_LANG=RU worked) but the flag hard-failed
    (--lang RU → argparse invalid choice, exit 2). normalize_lang() in mtkclient/i18n.py is
    now the single normalizer for both paths.
  3. Ratchet hole: the AST ratchet only saw constant keys, while every CMDS_HELP value is rendered
    via non-constant t(CMDS_HELP[...]); a future upstream command would silently stay English in
    ru. New AST-based check asserts every CMDS_HELP value has a ru entry (34/34 covered today).

Notes for later (none blocking):

  • argparse's own strings (usage:, options:, error:) remain English (stdlib limitation, out of scope).
  • ~190 lines of mtk.py are touched, so future upstream help-text edits will conflict with this
    PR, an accepted tradeoff of the flat-dict design (passthrough keeps missed keys safe).
  • The CLI smoke tests use timeout=60 per subprocess; fine locally, could flake on a very slow CI runner.

Add mtkclient/i18n.py, a minimal translation layer for user-facing
strings: po-like dictionaries keyed by the English string, with t()
passing unknown keys through unchanged so a missing translation can
never break a call.

Activation happens before argparse is built, with the following
precedence: --lang CLI flag > MTK_LANG environment variable > default
"en". An unknown language falls back to "en" with a warning on stderr.
The default keeps every string unchanged, so upstream behavior is
preserved unless the user explicitly opts in (--lang ru or
MTK_LANG=ru); the change is a two-way door — removing the flag and
the variable restores the previous behavior.

The CLI help (mtk.py) is routed through the new layer in Russian;
Library/ stays English to keep the PR minimal and mergeable.
Wrap the hardcoded user-visible strings of mtk_gui.py that bypassed
Qt-translate (serial-port selection dialog, View/Dark Mode menu,
Total/Current section progress labels, BROM/DA/preloader boot modes,
status prints) in t(), so the same language switch covers the GUI.
Strings already going through QCoreApplication.translate are left
alone: they are covered by the existing ru_RU.ts/.qm ("Done." was the
only gap and is now picked up via t()).

load_translations() now gives priority to the language selected by
the i18n layer (MTK_LANG), so Qt translations can be chosen without
changing the system locale; other locales (nl_NL etc.) behave as
before. Default remains English unless explicitly activated via
--lang ru / MTK_LANG=ru.
Cover the activation paths and failure behavior of the i18n layer:

- unit tests: default "en", MTK_LANG=ru activation, unknown language
  falls back to "en", --lang overrides the environment, value
  normalization, pass-through of unknown keys;
- an AST ratchet: every constant key passed to t() in mtk.py and
  mtk_gui.py must have a Russian translation, so a typo can no longer
  silently degrade into English;
- subprocess smoke tests: Russian help renders, the "en" default is
  unchanged, MTK_LANG=zz yields English, and --lang ru works.
Add a full Russian translation of the upstream README (README_ru.md) and a one-line language switcher at the top of README.md; no other content is touched.
@0-danielviktorovich-0
Copy link
Copy Markdown
Author

Commit messages rewritten in English (initially authored in Russian by mistake); README translation added

…lang case, extend AST ratchet

Co-authored-by: i18n-review <adversarial-review>
@0-danielviktorovich-0
Copy link
Copy Markdown
Author

Review findings applied in bc21e2e: seed/aeskey help translated, --lang case normalization added (both --lang and MTK_LANG), AST ratchet extended to non-constant dict keys (34/34). Also added README_ru.md (docs: Russian README translation) per project's zh-CN translation convention. Full i18n test suite green (14/14).

Natural-language Russian translations of the installation, usage and
Windows setup guides, following the zh-CN naming convention
(README-*.ru-RU.md). Command names, flags, BROM/DA/preloader terms
and code blocks are kept verbatim.
Add ru-RU editions of the DA info table and the preloader emulation
traces (mmc_init, mmc_only_init). Register/command/constant names and
trace lines are intentionally untranslated; each file carries a short
Russian translator's note and the body stays byte-identical to the
original.
Rename the Russian README via git mv, point the README.md language
switcher to it, add the RU flag entry and link the Russian sub-docs
from the Russian README, mirroring how README.zh-CN.md links its
translations.
… UART traces

These Tools/*.txt files are hwcode-table dumps and preloader-emulation log
traces (READ/WRITE register lines + firmware UART output) with no
explanatory prose — verified byte-identical after attempted translation.
Russian versions would be noise; the English originals remain the reference.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

0