-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom rule: cannot display localized message #2426
Comments
The sourse of the bug is in the init logic: for vee-validate.full.js 2615: // Install locale
2616: localize('en', en); After this initial call, updateRules() method will never be called again as INSTALLED flag is already set to true: var INSTALLED = false;
function updateRules() {
if (INSTALLED) {
return;
}
RuleContainer.iterate(function (name, schema) {
var _a, _b;
if (schema.message && !DICTIONARY.hasRule(name)) {
DICTIONARY.merge((_a = {},
_a[DICTIONARY.locale] = {
messages: (_b = {},
_b[name] = schema.message,
_b)
},
_a));
}
extend(name, {
message: function (field, values) {
return DICTIONARY.resolve(field, name, values || {});
}
});
});
INSTALLED = true;
}
function localize(locale, dictionary) {
var _a;
if (!DICTIONARY) {
DICTIONARY = new Dictionary('en', {});
}
if (typeof locale === 'string') {
DICTIONARY.locale = locale;
if (dictionary) {
DICTIONARY.merge((_a = {}, _a[locale] = dictionary, _a));
}
updateRules();
return;
}
DICTIONARY.merge(locale);
updateRules();
} To overcome i used this code to explicitly rewrite translation string for each rule: Object.keys(newLocaleMessages).forEach(
ruleName => {
extend(ruleName, {
message: newLocaleMessages[ruleName]
});
}
); |
@logaretm Are you going to take a look at this? |
Also, it would be nice, if we could load localizations once and they are picked up by rules that are As far as I understand, currently l10n messages are only applied to rules that are already registered. But due to this bug it's not possible to re-invoke |
Thanks 👍 |
Hi @logaretm , Is there any way to keep the defaultMessage method if already configured ? Thanks for your feedback, |
Versions
Describe the bug
I cannot seem to add localized messages via the
localize()
function for custom rules. Instead it will display the genericinput is not valid
message. I tried everyway of registering the language message, but there just is no way to get the rule return the localized message (not using any other l18n solution, just the internal vee-validate localization).To reproduce
This is my registration of the custom rule, which does not define a static message (!) (note i also tried all forms of the
localize()
function (and i suggest to review the documentation, since it is, at least to me, still not clear how this function operates with each input).Expected behavior
I expect the rule to use the current localized message.
Thank you.
PS: Referencing #2318 here, since it would also lead to the same error, i suppose.
The text was updated successfully, but these errors were encountered: