Skip to main content

marshmallow-i18n-messages

A simple library to provide i18n messages for marshmallow validation errors.

Installation

pip install marshmallow-i18n-messages

Usage

Call add_i18n_to_marshmallow once at application startup, before any marshmallow schemas are imported or instantiated:

from marshmallow_i18n_messages import add_i18n_to_marshmallow

add_i18n_to_marshmallow()

After this call all marshmallow validation errors will be translated to the active GNU gettext locale at the moment the error is rendered.

Enabling i18n for schemas loaded before add_i18n_to_marshmallow

If a schema class was imported and cached before add_i18n_to_marshmallow was called, its error messages will not have been wrapped yet. Enable i18n on it explicitly with enable_i18n:

from marshmallow_i18n_messages import enable_i18n

enable_i18n(MyAlreadyLoadedSchema)

enable_i18n is idempotent — calling it on a schema that is already patched is safe and has no effect. It also recurses into parent classes and any nested schemas automatically.

Invenio / InvenioRDM usage

This package ships with an integrated support for InvenioRDM repositories and in most cases, no extra configuration is necessary to activate the translations.

This package adds an invenio_config.module entrypoint that is loaded when InvenioRDM configuration is loaded. This entrypoint:

  • Calls add_i18n_to_marshmallow(lazy_gettext) with the lazy_gettext from invenio_i18n
  • Registers an app_loaded signal. In this signal it processes marshmallow schemas from all registered invenio services which might have been already cached before the add_i18n_to_marshmallow was called.

If you encounter a schema that is neither covered by the global patch above nor by the built-in service-schema finalizer, patch it explicitly in invenio.cfg:

from mypackage import MyUncoveredSchema
from marshmallow_i18n_messages import enable_i18n
from invenio_i18n import lazy_gettext

enable_i18n(MyUncoveredSchema, lazy_gettext)

If you find such a gap in the built-in coverage, please open an issue so it can be addressed in a future release.

Contributing new translations

To contribute new translations or fix translation issues:

  1. Fork the repository and create a feature branch.
  2. Add your language to build.sh and create an empty messages.po file at marshmallow_i18n_messages/translations/<language>/LC_MESSAGES/messages.po.
  3. Run build.sh to regenerate the POT template and merge it into your PO file.
  4. Translate the messages in the generated .po file.
  5. Run build.sh again to compile the translations.
  6. Commit the changes, push to your fork, and open a pull request.

Metadata

Release files for marshmallow-i18n-messages 0.4.1

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

Source distribution (sdist)

Source distribution for marshmallow-i18n-messages 0.4.1
File Size Uploaded
marshmallow_i18n_messages-0.4.1.tar.gz 17.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for marshmallow-i18n-messages 0.4.1
File Interpreter ABI Platform
marshmallow_i18n_messages-0.4.1-py3-none-any.whl Python 3 none any Details

Total release size: 46.5 kB

Release files / marshmallow_i18n_messages-0.4.1.tar.gz

Download URL marshmallow_i18n_messages-0.4.1.tar.gz
Size 17.0 kB
Tags Source
SHA-256 checksum
How to use checksums
90c34897606164c4b7b2d5170ed3753477746e1711dcfee85a00d6c957caa50c
BLAKE2b-256 checksum
How to use checksums
12cae4609f95fa3dddf0d6768caaaee374acd49a957ebb75b2ee368e03a93283
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release files / marshmallow_i18n_messages-0.4.1-py3-none-any.whl

Download URL marshmallow_i18n_messages-0.4.1-py3-none-any.whl
Size 29.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a659091854f2db9a0bb5c23327ed569a9bb5aa21742cd21a5b62f8ffbe57b768
BLAKE2b-256 checksum
How to use checksums
2aa95a64b5b6e34e70f134c61c4302771e96939f4270225fed31ea6fd3f23267
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.12

Release history Release notifications | RSS feed

This release

0.4.1 This release

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

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