i18nice is a Python library that provides internationalization (i18n) functionality, largely inspired by the Rails i18n library. It simplifies translation management for Python 3 applications by supporting translation files (JSON, YAML), placeholders, pluralization, and fallback locales. The current version is 0.16.0, and it maintains a relatively active release cadence with minor and patch updates.
pip install i18niceVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up `i18nice` by adding a translation path, setting the locale, and performing basic string translation with placeholders and pluralization using a simple JSON file.
Upgrade to Python 3.8 or newer to use i18nice v0.16.0 and later.
Ensure the key for translation is always passed as the first positional argument, e.g., `i18n.t('your.key', ...)` instead of `i18n.t(key='your.key', ...)`.For v0.14.0, change `lambda **kw: kw['count'] != 1` to `lambda a, **kw: a[kw['count'] != 1]`. For v0.15.0, change to `lambda *a, **kw: a[kw['count'] != 1]`.
Register a custom YAML loader that uses `yaml.FullLoader` if needed. Example: `class MyLoader(i18n.loaders.YamlLoader): loader = yaml.FullLoader; i18n.register_loader(MyLoader, ['yml', 'yaml'])`.
Review pluralization dictionary structures to ensure all keys conform to expected plural forms, or adjust your translation data if you relied on previous implicit pluralization.
Pass the translation key as the first positional argument: `i18n.t('your.key', ...)`.Verify that `i18n.load_path` points to the correct directory containing your translation files, ensure your locale is set (`i18n.set('locale', 'en')`), and confirm the key exists within your translation files and matches the file namespace (e.g., `app.greeting` for `app.en.json`). Use `i18n.load_everything()` to explicitly load all translations.If your YAML files are complex, you may need to register a custom YAML loader that explicitly uses `yaml.FullLoader` to restore full YAML parsing capabilities. Refer to the i18nice documentation for the exact implementation.