API Docs¶
Extension¶
Invenio internationalization module.
-
class
invenio_i18n.ext.
InvenioI18N
(app=None, date_formats=None, localeselector=None, timezoneselector=None, entry_point_group='invenio_i18n.translations')[source]¶ Invenio I18N extension.
Initialize extension.
Parameters: - app – Flask application.
- data_formats – Override default date/time formatting.
- localeselector – Callback function used for locale selection.
(Default:
invenio_i18n.selectors.get_locale()
) - timezoneselector – Callback function used for timezone selection.
(Default:
BABEL_DEFAULT_TIMEZONE
) - entry_point_group – Entrypoint used to load translations from.
Set to
None
to not load translations from entry points.
-
get_locales
()[source]¶ Get a list of supported locales.
Computes the list using
I18N_LANGUAGES
configuration variable.
-
init_app
(app)[source]¶ Flask application initialization.
The initialization will:
- Set default values for the configuration variables.
- Load translations from paths specified in
I18N_TRANSLATIONS_PATHS
. - Load translations from
app.root_path>/translations
if it exists. - Load translations from a specified entry point.
- Add
toutc
andtousertimezone
template filters. - Install a custom JSON encoder on app.
-
language
¶ Get current language code.
-
locale
¶ Get current locale.
-
timezone
¶ Get current timezone.
-
invenio_i18n.ext.
get_lazystring_encoder
(app)[source]¶ Return a JSONEncoder for handling lazy strings from Babel.
Installed on Flask application by default by
InvenioI18N
.
Translation Domain¶
Flask-BabelEx domain for merging translations from many directories.
-
class
invenio_i18n.babel.
MultidirDomain
(paths=None, entry_point_group=None, domain='messages')[source]¶ Domain supporting merging translations from many catalogs.
The domain contains an internal list of paths that it loads translations from. The translations are merged in order of the list of paths, hence the last path in the list will overwrite strings set by previous paths.
Entry points are added to the list of paths before the
paths
.Initialize domain.
Parameters: - paths – List of paths with translations.
- entry_point_group – Name of entry point group.
- domain – Name of message catalog domain.
(Default:
'messages'
)
Jinja2 filters¶
Babel datetime localization template filters for Jinja.
See full documentation of corresponding methods in Flask-BabelEx: https://pythonhosted.org/Flask-BabelEx/
-
invenio_i18n.jinja2.
filter_language_name
(lang_code)[source]¶ Convert language code into display name in current locale.
Installed on application as
language_name
.
-
invenio_i18n.jinja2.
filter_language_name_local
(lang_code)[source]¶ Convert language code into display name in local locale.
Installed on application as
language_name_local
.
Locale/timezone selectors¶
Default locale and timezone selectors for Flask-BabelEx.
See Flask-BabelEx documentation for corresponding methods.
-
invenio_i18n.selectors.
get_locale
()[source]¶ Get locale.
Searches for locale in the following the order:
- User has specified a concrete language in the query string.
- Current session has a language set.
- User has a language set in the profile.
- Headers of the HTTP request.
- Default language from
BABEL_DEFAULT_LOCALE
.
Will only accept languages defined in
I18N_LANGUAGES
.
Views¶
Views for Invenio-I18N.
-
invenio_i18n.views.
create_blueprint
(register_default_routes=True)[source]¶ Create Invenio-I18N blueprint.
Date/time formatting¶
For formatting date and time using the current locale settings, you may use the methods provided by Flask-BabelEx.
These methods are also available as Jinja filters:
- format_datetime as
datetimeformat
- format_date as
dateformat
- format_time as
timeformat
- format_timedelta as
timedeltaformat
.