Scene: The site is validate.unotrusive.js verified, the language of the website has been switched to traditional, but the prompt language is English.
Environment: Built-in validation of ASP. NET MVC4,JQUERY.VALIDATE.UNOTRUSIVE.JS,MVC Integration
Problem Scenario:
Expected Scenario:
Workaround:
Find the source of the text first: Search the entire project solution for must be a number is not searchable.
Guess: These hint words are in the Xxxx.resource.dll language pack. Speculation reason: Web site background Threading language set to Chinese, prompt Chinese, set to traditional, prompt English, it is likely because there is no traditional language pack.
and the online response to the language pack has not been found.
JS Omnipotent:
After investigation, the hint language exists in the Data property of the form object with the key value: Unobtrusivevalidation
Therefore, after unobtrusive initialization, according to the foreground of the current language environment, the prompt language can be changed to the required language. (The foreground language environment does not repeat in this article)
Js相关函数:
var ruleNames = { required: ‘required‘, number: ‘number‘ };
function initUnobtrusiveLang() {
initCulture();
var v = $(document.forms[0]).data(‘unobtrusiveValidation‘);
if (v && v.options && v.options.messages) {
var m = v.options.messages;
for (var t in m) {
if (t) {
var required_prop = m[t][ruleNames.required];
?
if (required_prop) {
var msg = required_prop;
var msg_new = msg.replace("The", ‘‘);
msg_new = msg_new.replace("field is required", $.Resources.SfExpressDelivery.FieldIsRequired);
m[t][ruleNames.required] = msg_new;
?
}
var number_prop = m[t][ruleNames.number];
?
if (number_prop) {
var msg = number_prop;
var msg_new = msg.replace("The field", $.Resources.SfExpressDelivery.TheFiled);
msg_new = msg_new.replace("must be a number", $.Resources.SfExpressDelivery.MustBeFiled);
m[t][ruleNames.number] = msg_new;
?
}
}
}
}
}
?
Then in, $jQval. Unobtrusive ={ after each function in the parse function is called
$(selector).find(":input[data-val=true]").each(function () {
$jQval.unobtrusive.parseElement(this, true);
});
?
initUnobtrusiveLang();//初始化语言包
Done, who knows the traditional language pack, trouble sharing under
How to set the language pack for unobtrusive