How to set the language pack for unobtrusive

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.