{"id":14838,"library":"python-i18n","title":"Python i18n","description":"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.","status":"maintenance","version":"0.3.9","language":"en","source_language":"en","source_url":"https://github.com/tuvistavie/python-i18n","tags":["i18n","localization","internationalization","translation"],"install":[{"cmd":"pip install python-i18n","lang":"bash","label":"Core library"},{"cmd":"pip install python-i18n[YAML]","lang":"bash","label":"With YAML support (recommended)"}],"dependencies":[{"reason":"Required for YAML translation file support, defaults to YAML if installed.","package":"PyYAML","optional":true}],"imports":[{"symbol":"i18n","correct":"import i18n"}],"quickstart":{"code":"import i18n\nimport os\n\n# Configure translation path (assuming 'locales' directory exists with translation files)\n# Example: locales/en.yml or locales/foo.en.yml\n# Create a dummy translation file for the example\nif not os.path.exists('locales'):\n    os.makedirs('locales')\nwith open('locales/en.yml', 'w') as f:\n    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.\"\n    many: \"You have %{count} mails.\"\n')\n\ni18n.load_path.append('./locales')\n\n# Set the default locale\ni18n.set('locale', 'en')\n\n# Basic translation from a file (if en.yml exists with 'en: hello: \"Hello world!\"')\nprint(i18n.t('hello'))\n\n# Translation with placeholders\nprint(i18n.t('welcome', name='Bob'))\n\n# Pluralization (requires `count` argument and specific keys in translation file)\nprint(i18n.t('mail_number', count=0)) # Should output 'You have no mails.'\nprint(i18n.t('mail_number', count=1)) # Should output 'You have one mail.'\nprint(i18n.t('mail_number', count=5)) # Should output 'You have 5 mails.'\n","lang":"python","description":"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."},"warnings":[{"fix":"Ensure your project runs on Python 3.x for full compatibility with the current library version.","message":"The 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.","severity":"gotcha","affected_versions":"0.3.9"},{"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.","message":"Enabling `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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"By 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}')`).","severity":"gotcha","affected_versions":"All versions"},{"fix":"If you prefer JSON files over YAML when both are possible, explicitly set `i18n.set('file_format', 'json')` before loading translation paths.","message":"If `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')`).","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[],"ecosystem":"pypi"}