Skip to main content
https://img.shields.io/github/license/inveniosoftware/invenio-i18n.svg https://github.com/inveniosoftware/invenio-i18n/workflows/CI/badge.svg https://img.shields.io/coveralls/inveniosoftware/invenio-i18n.svg https://img.shields.io/pypi/v/invenio-i18n.svg

Invenio-I18N provides the internationalization layer for InvenioRDM and other Invenio/Flask applications. It integrates the Babel/Flask-Babel stack, merges translation catalogs from multiple sources, exposes safe language-switch routes, and includes CLI tools to fetch from Transifex and distribute i18next-ready JSON for front-end use.

Features

  • Load and merge message catalogs from various locations.

  • Robust user-locale detection.

  • Secure views/endpoints for changing the active locale.

  • Jinja2 macros and filters for i18n in templates.

  • Fetch from Transifex, read PO files, and convert to/from i18next JSON for the browser.

  • Further documentation: https://invenio-i18n.readthedocs.io/

What it provides

  • Unified catalogs across locations. Merge translations from your app, entry-point packages, optional bundles, and extra paths. The multi-directory domain (via I18N_TRANSLATIONS_PATHS) keeps translations modular per feature while rendering as a single catalog.

  • Sensible locale selection. Language is chosen in this order: session → user preference → ``Accept-Language`` → default.

  • Language-switch views. A small blueprint persists the choice in the session and redirects back safely.

  • Jinja2 helpers. Macros (e.g., a language selector) and filters such as language_name plus timezone utilities.

  • Lazy strings. lazy_gettext() returns LazyString objects that resolve at render time—ideal for constants and form labels.

  • Front-end compatibility. Convert PO catalogs to i18next-style JSON or consume i18next JSON directly. Bundled Webpack entries ship minimal JS helpers for the selector; wire JSON into i18next with React, Angular, or plain JS.

How it fits together (high level)

  • Babel / Flask-Babel supply gettext, pluralization, and locale-aware formatting.

  • Merged “multidir” domain overlays catalogs from multiple directories; later sources override earlier ones so apps can override package defaults.

  • Jinja renders templates/macros for the language selector and localized UI.

  • i18n blueprint handles /lang (or your configured path) to set the session language and redirect back.

CLI commands

  • Fetch from Transifex → unified JSON

    invenio i18n fetch-from-transifex \
      -t <TRANSIFEX_TOKEN> -l "en,tr,de" -o js_translations/

    Pulls PO resources from Transifex, maps plurals, and writes per-language unified i18next JSON.

  • Distribute JSON back to packages

    invenio i18n distribute-js-translations -i js_translations/

    Splits each unified language file into per-package translations.json under the correct asset paths.

Key configuration (config.py)

  • I18N_LANGUAGES — available languages, e.g. [("en","English"),("tr","Türkçe")].

  • I18N_SET_LANGUAGE_URL — base URL for the language-switch routes (e.g., "/lang").

  • I18N_DEFAULT_REDIRECT_ENDPOINT — fallback endpoint after switching.

  • I18N_SESSION_KEY — session key storing the chosen language (default: "language").

  • I18N_USER_LANG_ATTR — user model attribute for a saved preference (e.g., "preferred_language").

  • I18N_TRANSLATIONS_PATHS — extra filesystem paths to include in the merged domain.

  • I18N_JS_DISTR_EXCEPTIONAL_PACKAGE_MAP — webpack-entry → package name fixes.

  • I18N_TRANSIFEX_JS_RESOURCES_MAP — maps Transifex resources to packages for JS translations.

Typical locale selection order: session → user profile → ``Accept-Language`` → ``BABEL_DEFAULT_LOCALE``.

Minimal setup

from flask import Flask
from invenio_i18n import InvenioI18N
from invenio_i18n.views import create_blueprint_from_app

app = Flask(__name__)
app.config.update(
    SECRET_KEY="dev",
    BABEL_DEFAULT_LOCALE="en",
    BABEL_DEFAULT_TIMEZONE="UTC",
    I18N_LANGUAGES=[("en", "English"), ("tr", "Türkçe")],
    I18N_SET_LANGUAGE_URL="/lang",            # enables the routes
    I18N_USER_LANG_ATTR="preferred_language", # if your User has it
)

InvenioI18N(app)                                    # init extension
app.register_blueprint(create_blueprint_from_app(app))  # language routes

Installation

Available on PyPI:

pip install invenio-i18n

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

invenio_i18n-3.6.0.tar.gz (34.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

invenio_i18n-3.6.0-py3-none-any.whl (85.0 kB view details)

Uploaded Python 3

File details

Details for the file invenio_i18n-3.6.0.tar.gz.

File metadata

  • Download URL: invenio_i18n-3.6.0.tar.gz
  • Upload date:
  • Size: 34.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for invenio_i18n-3.6.0.tar.gz
Algorithm Hash digest
SHA256 ac106342f056a5c017463977375b2f5c9980af8a88e5ec0187a2ae5cae5f68c1
MD5 6038774834752f1300fbf2861e22601a
BLAKE2b-256 812128328f1c79617c1702d5ba286573ef039cef63ab13202379ea8c6b5b1afa

See more details on using hashes here.

File details

Details for the file invenio_i18n-3.6.0-py3-none-any.whl.

File metadata

  • Download URL: invenio_i18n-3.6.0-py3-none-any.whl
  • Upload date:
  • Size: 85.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for invenio_i18n-3.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c880e6e2d992b878da407bf38a3d0eb04038c2e05dcb5684ebf3d9fa0502f34f
MD5 ee0f50ee52bffd5cd1667761089b2c4d
BLAKE2b-256 e93dd6e20558628e3fc62d9f318ef9f223204b997f919316386d851e3a53ab29

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page