{"id":8223,"library":"i18nice","title":"i18nice","description":"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.","status":"active","version":"0.16.0","language":"en","source_language":"en","source_url":"https://github.com/solaluset/i18nice","tags":["i18n","localization","translation","l10n"],"install":[{"cmd":"pip install i18nice","lang":"bash","label":"Base installation"},{"cmd":"pip install i18nice[YAML]","lang":"bash","label":"Installation with YAML support"}],"dependencies":[{"reason":"Required for loading translations from YAML files. Install with `pip install i18nice[YAML]` or `pip install PyYAML`.","package":"PyYAML","optional":true}],"imports":[{"note":"The library's core functionality is exposed through the `i18n` module itself.","symbol":"i18n","correct":"import i18n"}],"quickstart":{"code":"import i18n\nimport os\n\n# Create a dummy translation directory and file\n# In a real application, these would be pre-existing\nif not os.path.exists('translations'):\n    os.makedirs('translations')\nwith open('translations/app.en.json', 'w') as f:\n    f.write('{\n  \"greeting\": \"Hello %{name}!\",\n  \"mails\": {\n    \"zero\": \"You have no mails.\",\n    \"one\": \"You have one mail.\",\n    \"other\": \"You have %{count} mails.\"\n  }\n}')\n\n# Configure i18n to load translations from the 'translations' directory\ni18n.load_path.append('translations')\ni18n.set('locale', 'en')\n\n# Translate a simple string with a placeholder\nmessage = i18n.t('app.greeting', name='World')\nprint(message) # Expected: Hello World!\n\n# Translate with pluralization\nmessage_zero = i18n.t('app.mails', count=0)\nmessage_one = i18n.t('app.mails', count=1)\nmessage_many = i18n.t('app.mails', count=5)\n\nprint(message_zero) # Expected: You have no mails.\nprint(message_one)  # Expected: You have one mail.\nprint(message_many) # Expected: You have 5 mails.\n\n# Clean up dummy file and directory\nos.remove('translations/app.en.json')\nos.rmdir('translations')","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade to Python 3.8 or newer to use i18nice v0.16.0 and later.","message":"Python 3.6 and 3.7 support has been officially dropped in version 0.16.0.","severity":"breaking","affected_versions":">=0.16.0"},{"fix":"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', ...)`.","message":"The `key` argument in `i18n.t()` is now positional-only as of version 0.16.0.","severity":"breaking","affected_versions":">=0.16.0"},{"fix":"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]`.","message":"Custom function interfaces underwent significant changes in versions 0.14.0 and 0.15.0. If you used custom translation functions, their signatures will need updating.","severity":"breaking","affected_versions":"0.14.0, 0.15.0"},{"fix":"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'])`.","message":"The default YAML loader no longer uses `yaml.FullLoader`. If your YAML translation files rely on full YAML functionalities (e.g., tags, anchors), they might not load correctly.","severity":"gotcha","affected_versions":"All versions with YAML support after change (exact version not specified, but mentioned in docs)"},{"fix":"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.","message":"Pluralization logic was refined in v0.15.2; a dictionary is now considered plural only if all its keys (`one`, `many`, `zero`, `few`) are explicitly plural forms.","severity":"gotcha","affected_versions":">=0.15.2"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Pass the translation key as the first positional argument: `i18n.t('your.key', ...)`.","cause":"Attempting to call `i18n.t(key='your.key')` or similar, where 'key' is passed as a keyword argument.","error":"TypeError: 'key' is a positional-only argument and cannot be passed as keyword argument"},{"fix":"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.","cause":"The translation for 'some.key' was not found for the current locale or the translation files were not loaded correctly. This can happen if `i18n.load_path` is incorrect or the key does not exist in the files.","error":"i18n.t('some.key') returns 'some.key' (the key itself) instead of translated text."},{"fix":"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.","cause":"The default YAML loader in `i18nice` no longer uses `yaml.FullLoader`, which might lead to issues if your YAML files use advanced features (e.g., custom tags, anchors).","error":"Error loading YAML translation file, potentially related to missing features."}]}