Skip to content

Add runtime i18n hooks for validation messages#547

Open
aleksandr-kotlyar wants to merge 15 commits into
alecthomas:masterfrom
aleksandr-kotlyar:issue-73
Open

Add runtime i18n hooks for validation messages#547
aleksandr-kotlyar wants to merge 15 commits into
alecthomas:masterfrom
aleksandr-kotlyar:issue-73

Conversation

@aleksandr-kotlyar

@aleksandr-kotlyar aleksandr-kotlyar commented Jul 5, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds runtime i18n support for Voluptuous built-in validation messages.

This PR introduces gettext-compatible hooks so applications can translate Voluptuous error messages without Voluptuous shipping production translation catalogs.

Main changes:

  • Add configure_i18n() for loading gettext catalogs from an application-provided localedir
  • Add set_gettext() for injecting a custom translation callable
  • Add gettext_scope() for temporary context-local translation overrides
  • Route built-in user-facing validation messages and the Invalid.__str__ message/error-type format through the i18n hook
  • Keep the error path suffix, for example @ data[...], untranslated so existing tooling can continue to parse it
  • Document the i18n API in the README
  • Add test-only locale fixtures and packaging checks to ensure fixture catalogs are not treated as production catalogs

Voluptuous intentionally does not ship production translation catalogs in this PR. Applications are expected to provide their own gettext catalogs.

Also includes a few small validation correctness fixes covered by tests while touching error-message paths:

  • enum scalar schemas
  • set element transforms
  • non-numeric Number input
  • Schema.extend(Schema(...))
  • Invalid.__repr__

Resolves #73.

@aleksandr-kotlyar
aleksandr-kotlyar marked this pull request as ready for review July 5, 2026 10:35
@aleksandr-kotlyar aleksandr-kotlyar changed the title Add runtime i18n support and validation fixes Add runtime i18n hooks for validation messages Jul 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make all messages i18n friendly

1 participant