Skip to content

v0.5.0: Python CLIs

Choose a tag to compare

@DABH DABH released this 28 Sep 00:19
· 30 commits to main since this release

Localizer now localizes Python CLIs built with Typer, Click or argparse, alongside Go CLIs built with Cobra.

Python runtime: localizer-py

pip install localizer-py (import name localizer; Python 3.10+, no dependencies). Note: the PyPI project named localizer is unrelated.

  • localizer.localize(app, "yourcli.locales"), one line before the app runs, renders help, option descriptions, the framework's own messages and errors, and prompts in the user's language. Works with Click 8.1+, Typer 0.17+ (including the Click copy bundled since Typer 0.26) and argparse. Translation happens when help and errors render, on copies of your command objects, so plugin and lazily registered commands are covered and the originals are never modified.
  • Helpers for your own messages: t, tf, error, translate, lang. The same environment controls as the Go runtime (LOCALIZER_LANG, off, qps, LOCALIZER_DEBUG, LOCALIZER_DUMP) and identical language selection.
  • Built-in translations of Click's, Typer's and argparse's own strings for ja, zh-Hans, ko, es, fr, de and pt-BR.
  • Placeholder grammar for str.format fields, printf-style verbs and Rich markup, specified once in testdata/conformance/ and satisfied by both runtimes.
  • Every hook fails open: any internal error leaves the CLI in English.

Service

The GitHub App and the Action detect the repository language (or take language: from .localizer.yml), extract strings from Python source statically (f-strings become templates such as Plugin {name} is not installed: {0}), and onboard Python repositories: the locales package, the one line, and the localizer-py dependency. extract.funcs accepts keyword-argument names for Python; extract.skip_log_levels unset now means debug and trace for Go and every level for Python.

Docs

One Getting Started with a Go/Python switch; AGENTS.md gives coding agents the integration recipe; llms.txt indexes the docs.

Demo

DABH/snowflake-cli: the Snowflake CLI (Typer, ~1,700 strings) in Japanese and German.

Go

github.com/DABH/localizer@v0.5.0 has no API changes for Cobra users. msgfmt gains the Python placeholder syntax (Syntax, ExtractSyntax, CompileSyntax, PseudoSyntax), engine gains NewSyntax/NewPseudoSyntax, and catalog.File gains the optional format field. Action: DABH/localizer/action@v0.5.0.