Skip to main content

Invenio-I18N

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

Metadata

Release files for invenio-i18n 4.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for invenio-i18n 4.0.3
File Size Uploaded Provenance Actions
invenio_i18n-4.0.3.tar.gz 34.2 kB Without provenance Details for invenio_i18n-4.0.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for invenio-i18n 4.0.3
File Interpreter ABI Platform Actions
invenio_i18n-4.0.3-py3-none-any.whl Python 3 none any Details for invenio_i18n-4.0.3-py3-none-any.whl

Total release size: 117.7 kB

Release files / invenio_i18n-4.0.3.tar.gz

Download URL invenio_i18n-4.0.3.tar.gz
Size 34.2 kB
Tags Source
SHA-256 checksum
How to use checksums
a6974b35a95301ec37449055a4bf0b202636a3e38925cea63f8ddb8862f788b3
BLAKE2b-256 checksum
How to use checksums
de3841ad93680c94fe283e7e5771877d5d81bae78246cab02a2c7f0bfa1b87f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / invenio_i18n-4.0.3-py3-none-any.whl

Download URL invenio_i18n-4.0.3-py3-none-any.whl
Size 83.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6f0031220788bbb952ca18969af12ac6865e3c3e48a6cb4480791b044b960af3
BLAKE2b-256 checksum
How to use checksums
74c5d6e81913f83ee4462b12758b2c475b4ab8bcb41abd650090b055f24ffa80
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for invenio-i18n 4.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

4.0.3 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page