-
Notifications
You must be signed in to change notification settings - Fork 95
Description
Summary
Fastest-Validator currently doesn’t provide a clean or native way to define internationalized validation messages and dynamically switch between locales based on a locale option. As a result, applications that need multi-language support must implement custom workarounds, message maps, or manual message overrides, which becomes messy and difficult to maintain.
Problem
- Validation messages are static and tied directly to rule definitions.
- There is no built-in mechanism to specify message strings per locale.
- There is no global or per-validation
localeoption that automatically selects the correct localized message. - Implementing i18n requires writing custom logic that defeats the purpose of using a structured validation library.
What’s Needed
-
Ability to define messages in a multi-locale format, for example:
messages: { required: { en: "The field '{field}' is required.", fr: "Le champ '{field}' est obligatoire.", sw: "Sehemu ya '{field}' inahitajika." } }
-
A validator-level or call-level
localeoption:const validate = v.compile(schema, { locale: "fr" });
or:
v.validate(data, schema, { locale: "fr" });
-
Automatic fallback (e.g., fallback to
enif the specified locale is missing).
Why It Matters
Proper i18n support is essential for real-world applications that serve users across different regions. Without it, developers are forced to duplicate schemas or build their own localization systems around the validator.
Proposed Outcome
A first-class internationalization API that allows developers to define localized messages cleanly and select the active locale at runtime.