Testing and QA
Keep golden tests in English
Section titled “Keep golden tests in English”Localization follows the user’s environment, so a developer with a Japanese desktop would otherwise get
Japanese output in your tests. Set LOCALIZER_LANG=en in the environment of the process under test:
cmd := exec.Command(binaryPath, args...)cmd.Env = append(os.Environ(), "LOCALIZER_LANG=en")Tests that build the command tree without going through your main aren’t affected, because
Localize is never called there.
# conftest.py at the repository rootimport os
def pytest_configure(config): os.environ.setdefault("LOCALIZER_LANG", "en")With Typer’s CliRunner or Click’s, localize runs whenever your entry point does, so the pin matters
even for in-process tests. To test a language on purpose, set the variable for that test
(monkeypatch.setenv("LOCALIZER_LANG", "ja")) and call localizer.uninstall() afterwards so the hooks
don’t leak into other tests.
Try a language
Section titled “Try a language”LANG=ja_JP.UTF-8 yourcli --help # the way your users select a languageLOCALIZER_LANG=de yourcli --help # force one, whatever the system settings areFind strings that aren’t localized
Section titled “Find strings that aren’t localized”Pseudo-localization rewrites every string Localizer knows about, so anything left in plain English doesn’t go through Localizer yet:
$ LOCALIZER_LANG=qps taskctl --help⟦ţášķçţļ ķééþš á šɱáļļ ļîšţ öƒ ţášķš.Ûšé îţ ţö áďď, ļîšţ áñď çöɱþļéţé ţášķš.⟧
⟦Ûšáĝé:⟧ taskctl [command]Two more switches help with coverage:
-
LOCALIZER_DEBUG=1reports on stderr each help string that has no translation, as it renders (localizer: untranslated (ja): "Add a task."), and internal failures the runtime swallowed: a catalog that fails to load, a hook that failed, in Go a translation that would break a template. Misses in output and error messages aren’t reported; pseudo-localization shows those. Together withLOCALIZER_DUMP, which looks up every help string in the tree, it reports every help miss at once. -
LOCALIZER_DUMP=<file>writes every help string in the command tree as JSON, including whether each one was translated. Go writes it whenLocalizeruns, and so does Python for an argparse parser; for Typer and Click, Python writes it the first time help renders, so run--help. Both runtimes create the file new (an existing file is never overwritten) and ignore the variable when the process runs as root or setuid:{"language": "ja","entries": [{ "kind": "short", "command": "taskctl add", "text": "Add a task.", "translated": true },{ "kind": "flag", "command": "taskctl add", "flag": "due", "text": "Due date in YYYY-MM-DD format.", "translated": true }]}kindis one ofshort,long,example,deprecated,group,flagorflag_deprecated; Python writesepilogin place ofexampleand has noflag_deprecated.
Terminal width
Section titled “Terminal width”Translations can be longer than English, and CJK characters take two columns.
Localizer keeps flag columns aligned the same way Cobra does. For your own tables, prefer a library that
measures display width (for example one based on go-runewidth) over text/tabwriter, which counts runes.
Rich (used by Typer) measures display width, so panels and tables line up. Plain Click help wraps translated text with the same width rules as English.
© 2026 Snizyx Software LLC