Registry / serialization / python-i18n

python-i18n

JSON →
library0.3.9pypiunverified

python-i18n is an easy-to-use internationalization (i18n) library for Python 3, providing functionality largely inspired by Rails i18n. It allows developers to manage translations, pluralization, and placeholders using YAML or JSON files. The current version is 0.3.9, last released in August 2020, indicating a low-activity maintenance status.

pip install python-i18n
INSTALL
IMPORT
SIG · PYTHON-I18N
P
python-i18n
serializationenv0.3.9
Install
1.6s avg
Import
82ms
Disk
18MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.3.9 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.083s · 20.1MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.6s · import 0.082s · 21MB
18MB installed
● package 18MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

i18n
import i18n

This quickstart demonstrates how to initialize `python-i18n` by adding translation file paths, setting the locale, and performing basic translations, including placeholders and pluralization. It assumes translation files (YAML or JSON) are stored in a `locales` directory.

import i18n import os # Configure translation path (assuming 'locales' directory exists with translation files) # Example: locales/en.yml or locales/foo.en.yml # Create a dummy translation file for the example if not os.path.exists('locales'): os.makedirs('locales') with open('locales/en.yml', 'w') as f: f.write('en:\n hello: "Hello world!"\n welcome: "Welcome, %{name}!"\n mail_number:\n zero: "You have no mails."\n one: "You have one mail." many: "You have %{count} mails." ') i18n.load_path.append('./locales') # Set the default locale i18n.set('locale', 'en') # Basic translation from a file (if en.yml exists with 'en: hello: "Hello world!"') print(i18n.t('hello')) # Translation with placeholders print(i18n.t('welcome', name='Bob')) # Pluralization (requires `count` argument and specific keys in translation file) print(i18n.t('mail_number', count=0)) # Should output 'You have no mails.' print(i18n.t('mail_number', count=1)) # Should output 'You have one mail.' print(i18n.t('mail_number', count=5)) # Should output 'You have 5 mails.'
Debug
Known issues
gotchaThe library primarily targets Python 3. While version 0.3.0 explicitly supported Python 2.7, subsequent developments and the current README focus on Python 3. Users attempting to use the latest version (0.3.9) with Python 2.7 may encounter compatibility issues.
fix
Ensure your project runs on Python 3.x for full compatibility with the current library version.
affects: 0.3.9
gotchaEnabling `memoization` (i18n.set('enable_memoization', True)) loads translation files into memory only once. Subsequent changes to these files on disk will not be reflected without restarting the Python interpreter. This can lead to confusion during development when updating translations.
fix
During development, set `enable_memoization` to `False` or restart your application after modifying translation files. For production, enabling it can improve performance, but requires a deployment strategy that handles application restarts for translation updates.
affects: All versions
gotchaBy default, translation keys are namespaced by their filename. For example, if you have a file `messages.en.yml` with a key `hi: 'Hello!'`, you must access it as `i18n.t('messages.hi')`. To remove this namespace, you need to configure `filename_format` (e.g., `i18n.set('filename_format', '{locale}.{format}')`).
fix
Either adjust your translation keys to include the filename namespace (e.g., `i18n.t('filename.key')`) or explicitly set `i18n.set('filename_format', '{locale}.{format}')` to remove the filename prefix from keys.
affects: All versions
gotchaIf `PyYAML` is installed in your environment, `python-i18n` will default to using YAML for translation files. If you intend to use JSON files even when `PyYAML` is present, you must explicitly set the file format (e.e., `i18n.set('file_format', 'json')`).
fix
If you prefer JSON files over YAML when both are possible, explicitly set `i18n.set('file_format', 'json')` before loading translation paths.
affects: All versions
Upgrade
Version history
0.3.9latest on PyPI · released Aug 26, 2020
Audit
Dependencies
PyYAMLoptionalRequired for YAML translation file support, defaults to YAML if installed.
Agent activity
3 hits · last 30 days
node
2
OpenAI (training)
1
Resources

No resource links recorded.

python-i18n — pip install python-i18n · libregistry