Skip to main content

localizer-py

Render a Typer, Click or argparse CLI's own strings — help text, option descriptions, messages, errors, prompts — in the user's language. Translations come from JSON catalogs committed to your repository and shipped inside your package; nothing is downloaded or executed at runtime, and a CLI without a matching catalog behaves exactly as before.

The catalogs are written by Localizer: install the GitHub App or add the GitHub Action to your repository and it keeps a pull request up to date with translations of every string it finds in your code. This package is the runtime half — the part that runs on your users' machines.

pip install localizer-py   # not "localizer", which is an unrelated project

Python 3.10 or newer, no dependencies. Works with Click 8.1+, Typer 0.17+ (including Typer's bundled Click) and the standard library's argparse.

One line

Call localize after every command and option is registered, right before the app runs:

import localizer

# Typer
app = typer.Typer()
...
if __name__ == "__main__":
    localizer.localize(app, "yourcli.locales")
    app()

# Click
@click.group()
def cli(): ...

def main():
    localizer.localize(cli, "yourcli.locales")
    cli()

# argparse
parser = argparse.ArgumentParser(prog="yourcli")
...
localizer.localize(parser, "yourcli.locales")
args = parser.parse_args()

"yourcli.locales" names the package holding your catalogs (yourcli/locales/ja.json, …); a directory path or an importlib.resources Traversable works too. If your CLI builds its command tree in a factory, call localize where the finished app object is handed out — translation happens when help and errors are rendered, so commands registered later (plugins, lazy groups) are covered.

What is translated: your help text and option descriptions, the framework's own messages (Usage:, Show this message and exit., Missing argument 'NAME'., Aborted!, prompts, argparse's error: lines — built-in catalogs for these ship in this package), the messages of exceptions your CLI raises, and whatever your program passes through the helpers below. Nothing else changes: command and option names, values, JSON/YAML output and logs stay as they are.

Your own messages

from localizer import t, tf, error

print(t("Nothing to do."))                          # exact lookup, or the English text
print(tf("Added task {n}: {title!r}", n=3, title=s))  # translated format string, then .format()
console.print(t(f"Deleted {count} files"))          # formatted text is matched against the catalog
raise click.ClickException(error(exc))              # an exception's message, for display

t on a format string looks the template up exactly (call it before formatting, or use tf); on finished text it reverse-matches the catalog's templates, so f"Deleted {count} files" finds Deleted {count} files and keeps the number. localizer.translate(text, localizer.Mode.ERROR) does the same for chokepoints that receive already-formatted messages. Every helper returns its input unchanged when there is no translation and never raises.

Catalogs

One file per language, named by BCP 47 tag, keyed by the exact English source string:

{
  "version": 1,
  "language": "ja",
  "format": "python",
  "messages": {
    "Add a task.": "タスクを追加します。",
    "Added task {n}: {title!r}": "タスク {n} を追加しました: {title!r}"
  }
}

Localizer generates and maintains these; you review them like any other pull request. Make sure the JSON files are packaged: hatchling, poetry, flit, pdm and uv include them automatically, setuptools needs [tool.setuptools.package-data] yourcli = ["locales/*.json"].

Language selection

LOCALIZER_LANG, then LC_ALL, LC_MESSAGES, LANG (and LANGUAGE), then the operating system's preferred languages on macOS and Windows; the best available catalog wins, English is the default. localize(app, ..., env_var="YOURCLI_LANG") adds an application-specific override checked first; language="de" forces a language. Setting the variable to off keeps a CLI in English; LOCALIZER_LANG=qps pseudo-localizes every translatable string (⟦Ûšáĝé:⟧) so you can see what is covered without a catalog. LOCALIZER_DEBUG=1 reports untranslated strings and swallowed hook errors on stderr; LOCALIZER_DUMP=path.json writes the help tree with a translated/untranslated flag per entry.

Pin your tests to English so snapshots don't depend on the machine's locale:

# conftest.py
import os

def pytest_configure(config):
    os.environ.setdefault("LOCALIZER_LANG", "en")

More

Metadata

Release files for localizer-py 0.5.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for localizer-py 0.5.0
File Size Uploaded
localizer_py-0.5.0.tar.gz 50.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for localizer-py 0.5.0
File Interpreter ABI Platform
localizer_py-0.5.0-py3-none-any.whl Python 3 none any Details

Total release size: 108.0 kB

Release files / localizer_py-0.5.0.tar.gz

Download URL localizer_py-0.5.0.tar.gz
Size 50.2 kB
Tags Source
SHA-256 checksum
How to use checksums
6ae6a11ad65e91d3269ee6e5458eeb1d13f15423f46c82062e2e0404f9818616
BLAKE2b-256 checksum
How to use checksums
928e74b09817dc4c7e81372f3b05797cfc97ffda42f1774b588b68fa4372feb8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 28, 2026.

Transparency log

Release files / localizer_py-0.5.0-py3-none-any.whl

Download URL localizer_py-0.5.0-py3-none-any.whl
Size 57.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
47a013d3bf45c61daeccbb18140b7f7993e097a15bad36e9e22cb5693c6b892a
BLAKE2b-256 checksum
How to use checksums
249c1d1fcdf9bd4232b24015d03f60ef946729026bbff24e64cd12024f78afbc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 28, 2026.

Transparency log

Release history Release notifications | RSS feed

0.6.0

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

This release

0.5.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page