开发者

How can I display "please fill required field" in different languages using jquery.validate and ?lang=?

开发者 https://www.devze.com 2022-12-20 16:52 出处:网络
I\'m using $lang = $_GET[\'lang\']; and some arrays to change the language of the page. So my pages URL look like this when I select a language: ...index.php?lang=en

I'm using $lang = $_GET['lang']; and some arrays to change the language of the page. So my pages URL look like this when I select a language: ...index.php?lang=en (so my index page never changes neither my jquery files)

(more details in my previous post)

I'm using jQuery validate plugin to validate my form and a custom.js:

$(document).ready(function(){

    $("#sendmail").validate({
        rules: {
            FieldData0: {
                required: true
            },
            FieldData1: {
                required: true,
                email: true
            },
            FieldData2: {
                required: true
            }
        },
        messages: {
            FieldData0: {
                required: "Please enter your name"
            },
            FieldData1: {
                required: "Please enter your email address"
            },
            FieldData2: {
                required: "Please enter a message"
       开发者_StackOverflow     }
        }
    });
})

How can I show different requirement warning for different languages in this case? Do I have to make a custom.js for every language and then use php if else statements, is the a better way?


I would do this: Make a custom-en.js (and one for each language) then have something like the following for in the custom-en.js:

var messList = {
     mess1 : "This is message 1";
     ...
     reqMess1 : "Please enter your name";
}

then in your non-changing file you would have lines that look like this:

    messages: {
        FieldData0: {
            required: messList.reqMess1;
        },
0

精彩评论

暂无评论...
验证码 换一张
取 消