Invenio-i18n
raw JSON → 3.5.0 verified Fri May 01 auth: no python
Invenio internationalization (I18N) module. Provides Flask-based i18n support, locale selector, and translation utilities for Invenio repositories. Current version 3.5.0, requires Python >=3.9.
pip install invenio-i18n Common errors
error ImportError: cannot import name 'InvenioI18N' from 'invenio_i18n' ↓
cause Older version of invenio-i18n (pre-1.0) had different import path.
fix
Upgrade to latest: pip install --upgrade invenio-i18n
error RuntimeError: babel data directory not found ↓
cause Missing translation files; often due to incomplete pip install or without Flask-BabelEx.
fix
Ensure Flask-BabelEx is installed and translation data is packaged: pip install Flask-BabelEx
Warnings
breaking Invenio-i18n 3.x requires Flask-BabelEx >= 2.x and is not compatible with plain Flask-Babel. Ensure Flask-Babel is not installed. ↓
fix Use Flask-BabelEx explicitly: pip install Flask-BabelEx. Do not install Flask-Babel.
deprecated The 'I18N_LANGUAGES' config key is deprecated in favor of 'I18N_AVAILABLE_LANGUAGES' since version 3.3.0. ↓
fix Use app.config['I18N_AVAILABLE_LANGUAGES'] instead of I18N_LANGUAGES.
gotcha If you override 'current_i18n' from Flask-BabelEx, ensure you import from invenio_i18n, not flask_babelex, as the internal wrapper may change. ↓
fix Always import current_i18n from invenio_i18n.
Imports
- InvenioI18N
from invenio_i18n import InvenioI18N - current_i18n wrong
from flask_babelex import current_i18ncorrectfrom invenio_i18n import current_i18n
Quickstart
from flask import Flask
from invenio_i18n import InvenioI18N
app = Flask(__name__)
app.config['I18N_LANGUAGES'] = [('en', 'English'), ('fr', 'Fran\u00e7ais')]
ext = InvenioI18N(app)
@app.route('/')
def index():
from invenio_i18n import current_i18n
return current_i18n.locale.language
if __name__ == '__main__':
app.run()