Skip to content

oarepo_config.i18n

oarepo_config.i18n

Configuration for i18n.

initialize_i18n() -> None

Enable translated validation error messages.

Makes sure that when a user submits invalid data (for example, a required field is missing), the error message shown to them is translated into their chosen language instead of always being shown in English. Takes no parameters; call it once, near the top of invenio.cfg.

Invenio configuration variables set: none - this only patches Marshmallow's error-message machinery in memory.

Example
config.initialize_i18n()
Source code in oarepo_config/i18n.py
def initialize_i18n() -> None:
    """Enable translated validation error messages.

    Makes sure that when a user submits invalid data (for example, a
    required field is missing), the error message shown to them is
    translated into their chosen language instead of always being shown
    in English. Takes no parameters; call it once, near the top of
    `invenio.cfg`.

    Invenio configuration variables set: none - this only patches
    Marshmallow's error-message machinery in memory.

    Example:
        ```python
        config.initialize_i18n()
        ```

    """
    from flask_babel import lazy_gettext as _
    from marshmallow_i18n_messages import add_i18n_to_marshmallow

    add_i18n_to_marshmallow(_)