Language selecting

K

knoak

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.forms[0]

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

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

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

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

if(F.remarks.value.length<1)Result+=Warn[4]

if(Result.length>2){
alert("De volgende onderdelen zijn incorrect:\n\n"+Result)
return
}
else{
F.submit()
}
};
 
T

Thomas 'PointedEars' Lahn

knoak said:
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?

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.defaultLang]));


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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top