Skip to main content

i18nparse

Localization of the Python argparse module

Goals

The argparse module makes it easy to write user-friendly command-line interfaces. Specifically, it automatically generates help and usage messages and issues errors when users give the program invalid arguments. Unfortunately, even if the module is able to use gettext type localization strings, none is provided by the standard library.

This module provides some translations and is simply installable through pip

Current status

Starting with the 1.0.0 release this package is announced as Production grade. The translations are provided by the Translation Project, except for the French one which is still provided by the developer.

The binary wheel file contains little endian mo translation files. Users of big endian systems should use the source distribution to generate the mo files on their own system.

The list of the translations and the Python versions for which they are in sync is available in the TRANSLATIONS.md file.

Nevertheless, even if the translation is too old or too recent, the worst effect will be some texts still appearing in English language.

For the version 1.0.0, the reference version for the argparse.py file is the one from the 3.13.2 Python release (raw content). As of February 2025, it is the one for the 3.13 branch available here

Known bugs and limitations

When you pass the option -h to a program using i18nparse the text for the version option will appear in English for all Python releases before 3.11.9, 3.12.3 or 3.13.0 . For example for a French locale you would get:

usage : ProgName [-h] [--version]

options:
-h, --help  affiche ce message et termine le programme
--version   show program's version number and exit

The problem in not in i18nparse. The string "show program's version number and exit" is simply not marked for translation is the module argparse.py before those Python versions.

Installing

End user installation

With pip: pip install i18nparse.

Developer installation

If you want to contribute, you should get a copy of the full tree from GitHub:

git clone https://github.com/s-ball/i18nparse.git [your_working_copy_folder]

Building

The i18nparse project now uses hatch as its build system.

Usage

The i18nparse module defines 2 functions:

def activate(lang = None)

which activates the usage of the translation for the required language. By default, the language for locale.getlocale() is used. Note: In order to use the expected locale, it should be loaded prior to the call to activate with locale.setlocale(locale.LC_ALL, locale_name) where locale_name is the name of a known locale or '' (empty string) for the default locale.

def deactivate()

which reverts to the original texts.

Example:

import argparse
import i18nparse
import locale

locale.setlocale(locale.LC_ALL, '') # sets a locale
i18nparse.activate()     # Ok use current locale (if translation file exists)

parser = argparse.ArgumentParser('foo')
parser.print_help()      # displays the help message for the current locale

Assuming a fr_FR locale, this displays:

usage : foo [-h]

options:
  -h, --help  affiche ce message et termine le programme

Contributing

Contribution for new language translations or improvement of existing ones should be addressed to the Translation Project. Only remarks on the project itself should lead to issues on GitHub. See CONTRIBUTING for details

Versioning

This project uses a standard Major.Minor.Patch versioning pattern. Inside a major version, public API stability is expected. Inside a minor version, the matrix of compatibility with Python versions should remain unchanged.

License

This project is licensed under the MIT License - see the LICENSE file for details

Metadata

Release files for i18nparse 1.0.3

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

Source distribution (sdist)

Source distribution for i18nparse 1.0.3
File Size Uploaded Provenance Actions
i18nparse-1.0.3.tar.gz 18.5 kB Without provenance Details for i18nparse-1.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for i18nparse 1.0.3
File Interpreter ABI Platform Actions
i18nparse-1.0.3-py3-none-any.whl Python 3 none any Details for i18nparse-1.0.3-py3-none-any.whl

Total release size: 49.9 kB

Release files / i18nparse-1.0.3.tar.gz

Download URL i18nparse-1.0.3.tar.gz
Size 18.5 kB
Tags Source
SHA-256 checksum
How to use checksums
32ea8747e2162aec20d337e034f90a4698d85dd101320481c2950e86e3c8381a
BLAKE2b-256 checksum
How to use checksums
506718cf3f6820416f919ac643842b8c03f3e3179e0f4a9de6ea10f486a1282c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.28.1

Release files / i18nparse-1.0.3-py3-none-any.whl

Download URL i18nparse-1.0.3-py3-none-any.whl
Size 31.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5f3df1a9a2e47f488575b327bb7ff50a7969cc5eb52bd1ebd4755079d2e6cd2d
BLAKE2b-256 checksum
How to use checksums
f9e4ab74b3d7a629de9c17d46eecd15e0e87ec0ee4a448c9b4ae3cd35e6992df
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via python-httpx/0.28.1

Security for i18nparse 1.0.3

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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