Repository navigation
Add runtime i18n hooks for validation messages - #547
aleksandr-kotlyar wants to merge 16 commits into
Conversation
b502faf to
0d33e69
Compare
|
Hi @alecthomas, sorry for the ping. This PR is ready for review when you have time. It keeps the change focused on runtime i18n support for validation messages, includes regression coverage, and the branch is up to date with I would appreciate any feedback on whether this approach matches the project’s expected API and packaging semantics, especially around Thanks! |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 0d33e696b7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| return list(languages) | ||
|
|
||
|
|
||
| _default_translator: TranslateFunc = _gettext.gettext |
There was a problem hiding this comment.
Keep the unconfigured translator independent of process gettext
When a host application has called gettext.textdomain()/bindtextdomain() (and selected a language through its environment), _gettext.gettext consults that process-global domain, so Voluptuous messages become translated—or collide with unrelated catalog entries—even though none of these new configuration APIs were called. This also lets another component's later domain changes alter validation output unexpectedly, contrary to the documented English default; initialize this to an identity translator and reserve gettext catalog lookup for configure_i18n().
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Addressed in 1ffe417: the unconfigured default translator is now an identity function, and gettext catalog lookup is only used via configure_i18n(). Added a regression test covering process-global gettext isolation.
|
Hi @alecthomas, a gentle follow-up: the Codex review feedback has been addressed in 1ffe417, with a regression test covering gettext isolation. Could you take a look when you have time? Thanks! |
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:
configure_i18n()for loading gettext catalogs from an application-providedlocaledirset_gettext()for injecting a custom translation callablegettext_scope()for temporary context-local translation overridesInvalid.__str__message/error-type format through the i18n hook@ data[...], untranslated so existing tooling can continue to parse itVoluptuous 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:
NumberinputSchema.extend(Schema(...))Invalid.__repr__Resolves #73.