Language selecting

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • knoak

    Language selecting

    Hi there,

    I have a site and it's got three languages. I also
    have a contact-form with error alerts.

    What i wonder is how can i tell the alerts that
    are in a separate js-file what language they should pick.
    I don't want to create a formcheck file for each language.

    You can see the formcheck below.
    The lines in the array are the alerts in dutch, but where and how
    do i put them in English?

    Thanks in advance.

    Greetings knoak

    _______________ _______________ _______________ _______________

    function doForm()
    {
    Result=""

    Warn=new Array(
    " · U heeft geen geslacht ingevuld.\n",
    " · U heeft geen achternaam ingevuld.\n",
    " · U heeft geen e-mail adres ingevuld.\n",
    " · Het e-mail adres is incorrect.\n",
    " · U heeft geen opmerkingen ingevuld.\n"
    )
    F=document.form s[0]

    genderOK=0
    for(x=0;x<F.gen der.length;x++) {
    if(F.gender[x].checked==true) genderOK=1
    }
    if(genderOK==0) Result+=Warn[0]

    if(F.lastname.v alue.length<1) Result+=Warn[1]

    if(F.email.valu e.length<1) Result+=Warn[2]

    if(F.email.valu e.length>0){
    Em=F.email.valu e
    re=/.+\@.+\..+/
    OK = re.exec(Em)
    if(!OK)Result+= Warn[3]
    WrongMail=1
    }

    if(F.remarks.va lue.length<1)Re sult+=Warn[4]

    if(Result.lengt h>2){
    alert("De volgende onderdelen zijn incorrect:\n\n" +Result)
    return
    }
    else{
    F.submit()
    }
    };
  • Thomas 'PointedEars' Lahn

    #2
    Re: Language selecting

    knoak wrote:[color=blue]
    > I have a site and it's got three languages. I also
    > have a contact-form with error alerts.
    >
    > What i wonder is how can i tell the alerts that
    > are in a separate js-file what language they should pick.
    > I don't want to create a formcheck file for each language.
    >
    > You can see the formcheck below.
    > The lines in the array are the alerts in dutch, but where and how
    > do i put them in English?[/color]

    You need a script file you be included before all others
    that require the language/message data to contain something
    like this:

    var resources = {
    lang: "nl",
    defaultLang: "nl",
    msgs: {
    no_sex: {
    en: "You have not specified the sex.",
    nl: "U heeft geen geslacht ingevuld."
    },
    no_surname: {
    en: "You have not specified the surname.",
    nl: "U heeft geen achternaam ingevuld."
    },
    no_email: {
    en: "You have not specified an e-mail address.",
    nl: "U heeft geen e-mail adres ingevuld."
    },
    invalid_email: {
    en: "The e-mail address is incorrect.",
    nl: "Het e-mail adres is incorrect."
    },
    no_comment: {
    en: "You have not provided a comment.",
    nl: "U heeft geen opmerkingen ingevuld."
    }
    }
    };

    var
    o = resources.msgs. no_sex,
    lang = resources.lang;

    alert(" · "
    + (o[lang] ? o[lang] : o[resources.defau ltLang]));


    You can use the a DOM object's property value instead of the `lang'
    property of that global object[1] as well. The `defaultLang' property
    and the ternary operator are provided only to have a useful text if a
    text for a language is missing.


    HTH

    PointedEars
    ___________
    [1] Do not confuse it with *the* global object of
    which `_that_ global object' is a property.

    Comment

    Working...