How can I change the language used in Validation messages?

ChronoForms v4 uses the FormCheck validation library that has support built in for about twenty languages. This FAQ shows you how to set them up for a single or multi-language site and how to add a new language.

Single language sites

You can set the language using the JS Validation Language option on the JS Validation tab (click the Form Name link in the Forms Manager to see this).

The currently listed languages are:

English (default) Chinese, Danish, Deutsch, Dutch, Farsi, French, Greek, Italian, Japanese, Latvian, Norwegian, Polish, Portuguese, Romanian, Russian, Slovenšcina, Spanish and Turkish.

There are also files available for Bulgarian (bu), Croatian (hr) and Hungarian (hu) that are not in the list. You can add a new language file by copying and renaming one of the existing files in the folder components/com_chronoforms/js/formcheck/lang User provided translations for Swedish (se) and Norwegian (no) are below for you to copy and paste.

To use a language that is not in the list add the following code into a Custom Code action in the On Load event of your form replacing xx with the two letter language code:

<?php
$form->form_params->set('jsvalidation_lang', 'xx');
?>

If you want to add languages to the drop-down list you can hack the code around line 106 of administrator/components/com_chronoforms/views/edit.php If you do this the hack will be over-written when you next upgrade ChronoForms.


Multi-language sites

You can change language using the Joomla! language object to find the currently selected language. Add this code to a Custom Code action to do this:

<?php
$lang = JFactory::getLanguage();
$tag = $lang->getTag();
$tag = substr( $tag, 0, 2 );
$form->form_params->set('jsvalidation_lang', $tag);
?>

Or you can try my custom Show HTML [GH] action which detects the language and selects the corresponding language file.


Language files

User SubCon noticed these errors in the English language file:
 
line 16: differs: "This value must be different of %0"
I guess it should be "from"

line 19: lengthmax: "The length is incorrect, it must be at max %0"
better "The length is incorrect, it must be at max of %0"
or "The length is incorrect, it must be %0 characters max"

line 21: words_min : "This field must concain at least %0 words, currently: %1 words"

There's an improved/updated Russian language file in the forums here.

Here are examples of language files if you want to create a new translation. The file needs to be saved in the components/com_chronoforms/js/formcheck/lang folder with an identifying name e.g. fi.js for the Norwegian file.

Finnish (fi)

formcheckLanguage = {
    required: "Tämä kenttä on pakollinen.",
    alpha: "Tämä kenttä hyväksyy vain aakkosia.",
    alphanum: "Tämä kenttä hyväksyy vain aakkosia ja numeroita.",
    nodigit: "Vain kokonaisluvut sallittuja.",
    digit: "Syötä käypä kokonaisluku.",
    digitmin: "Luvun täytyy olla vähintään %0",
    digitltd: "Arvon täytyy olla välillä %0 ja %1",
    number: "Syötä käypä luku.",
    email: "Syötä käypä email: <br/><span>Esim. omanimi@domain.com</span>",
    image : "Tämä kenttä saa sisältää vain kuvatiedostoja",
    phone: "Syötä käypä puhelinnumero.",
    url: "Syötä käypä url: <br/><span>Esim. http://www.domain.com</span>",    
    confirm: "Tämä kenttä eroaa arvosta %0",
    differs: "Tämän kentän täytyy erota arvosta %0",
    length_str: "Pituus on väärä, täytyy olla välillä %0 ja %1",
    length_fix: "Pituus on väärä, täytyy olla täsmälleen %0 merkkiä",
    lengthmax: "Pituus on väärä, saa olla enintään %0",
    lengthmin: "Pituus on väärä, täytyy olla vähintään %0",
    words_min : "Tämän kentän on sisällettävä vähintään %0 sanaa, tällä hetkellä: %1 sanaa",
    words_range : "Tämän kentän on sisällettävä %0-%1 sanaa, tällä hetkellä: %2 sanaa",
    words_max : "Tämä kenttä saa sisältää enimmillään %0 sanaa, tällä hetkellä: %1 sanaa",
    checkbox: "Rastita laatikko",
    checkboxes_group : "Rastita vähintään %0 laatikko(a)",
    radios: "Valitse yksi",
    select: "Valitse arvo",
    select_multiple : "Valitse vähintään yksi arvo"
}

Slovak (sk)

formcheckLanguage = {
	required: "Toto pole je povinné.",
	alpha: "Toto pole môže obsahovat iba písmená.",
	alphanum: "Do tohoto pola môžete zadávat len alfanumerické znaky.",
	nodigit: "Toto pole nemôže obsahovat císlice.",
	digit: "Toto pole môže obsahovat iba celé kladné císla.",
	digitmin: "Císlo musí byt minimálne %0",
	digitltd: "Hodnota musí byt v intervale %0 až %1",
	number: "Císlo prosím zadajte v správnom formáte.",
	email: "Prosím, zadajte mail v správnom formáte: Napr. VaseMeno@domena.sk",
	image : 'Toto pole môže obsahovat len formáty obrázkov',
	phone: "Prosím, zadajte telefónne císlo v správnom formáte.",
	url: "URL prosím zadajte v správnom formáte: napr. http://www.domena.sk",
	confirm: "Pole nie je totožné s polom %0",
	differs: "Toto pole musí byt odlišné ako %0",
	length_str: "Zadaný retazec nemá správnu dlžku, musí byt v rozsahu %0 a %1",
	length_fix: "Zadaný retazec nemá správnu dlžku, musí mat dlžku presne %0 znakov",
	lengthmax: "Zadaný retazec nemá správnu dlžku, môže byt dlhý maximálne %0 znakov",
	lengthmin: "Zadaný retazec nemá správnu dlžku, musí byt kratší ako %0 znakov",
	words_min : "Toto pole musí obsahovat minimálne %0 slov. Momentálne má len: %1 slov",
	words_range : "Toto pole musí obsahovat %0-%1 slov. Momentálne má : %2 slov",
	words_max : "Toto pole môže obsahovat maximálne %0 slov. Momentálne má: %1 slov",
	checkbox: "Zaškrtnutie tohoto checkboxu je povinné",
	checkboxes_group : 'Prosím, vyberte minimálne %0 možnost(i)',
	radios: "Prosím vyberte jednu z možností",
	select: "Prosím vyberte jednu z možností",
	select_multiple : "Prosím vyberte jednu alebo viac možností"
}

Swedish (se)

formcheckLanguage = {
  required: "Detta f&auml;lt &auml;r obligatoriskt.",
  alpha: "Detta f&auml;lt accepterar endast bokst&auml;ver.",
  alphanum: "Detta f&auml;lt accepterar endast alfanumeriska tecken.",
  nodigit: "Inga siffror accepteras.",
  digit: "Ange ett giltigt heltal.",
  digitmin: "Antalet m&aring;ste vara minst %0",
  digitltd: "V&auml;rdet m&aring;ste vara mellan %0 och %1",
  number: "Ange ett giltigt nummer.",
  email: "Ange en giltig e-postadress: <br /><span>T.ex. dittnamn@dom&auml;n.se</span>",
  image : 'Detta f&auml;lt ska endast inneh&aring;lla bildtyper',
  phone: "Ange ett giltigt telefonnummer.",
  url: "Ange en giltig webbadress: <br /><span>T.ex. http://www.dom&auml;n.se</span>",  
  confirm: "Detta f&auml;lt skiljer sig fr&aring;n %0",
  differs: "Detta v&auml;rde m&aring;ste skilja sig fr&aring;n %0",
  length_str: "L&auml;ngden &auml;r fel, den m&aring;ste vara mellan %0 och %1",
  length_fix: "L&auml;ngden &auml;r fel, den m&aring;ste vara exakt %0 tecken",
  lengthmax: "L&auml;ngden &auml;r fel, den m&aring;ste vara max %0",
  lengthmin: "L&auml;ngden &auml;r fel, den m&aring;ste vara minst %0",
  words_min : "Detta f&auml;lt m&aring;ste inneh&aring;lla minst %0 ord, f&ouml;r n&auml;rvarande: %1 ord",
  words_range : "Detta f&auml;lt m&aring;ste inneh&aring;lla %0-%1 ord, f&ouml;r n&auml;rvarande: %2 ord",
  words_max : "Detta f&auml;lt m&aring;ste inneh&aring;lla max %0 ord, f&ouml;r n&auml;rvarande: %1 ord",
  checkbox: "V&auml;nligen markera rutan",
  checkboxes_group : 'V&auml;nligen markera minst %0 ruta/rutor',
  radios: "V&auml;nligen g&ouml;r ett val",
  select: "V&auml;lj ett v&auml;rde",
  select_multiple : "V&auml;lj minst ett v&auml;rde"
}
Hebrew (he) 
Thanks to SubCon
formcheckLanguage = {
	alpha: "??? ?? ???? ?????? ??? ??? ????.",
	alphanum: "??? ?? ???? ?????? ??? ??? ??????? ????.",
	checkbox: "????? ??? ?? ???? ??????",
	checkboxes_group : '????? ??? ????? %0 ?????',
	confirm: "??? ?? ???? ? %0",
	differs: "??? ?? ???? ????? ???? ? %0",
	digit: "?? ????? ???? ???.",
	digitltd: "????? ???? ????? ??? %0 ? %1",
	digitmin: "????? ???? ????? ????? %0",
	email: "??? ???? ?????? ????: <br /><span>yourname@domain.com</span>",
	image : '??? ?? ???? ????? ?????? ????',
	length_fix: "???? ????, ???? ????? %0 ????? ?????",
	length_str: "???? ????, ???? ????? ??? %0 ? %1",
	lengthmax: "???? ????, ???? ????? %0 ???????",
	lengthmin: "???? ????, ???? ????? %0 ?????",
	nodigit: "?? ???? ????? ????? ???? ??.",
	number: "?? ??? ???? ???? ??.",
	phone: "??? ???? ???? ????? ????.",
	radios: "?? ???? ?????",
	required: "??? ??? ????.",
	select: "?? ????? ???",
	select_multiple : "?? ????? ??? ??? ?????",
	url: "??? ??? ????? ??????? ?????: <br /><span>http://www.domain.com</span>",
	words_max : "??? ?? ???? ????? %0-%1  ?????, ????: %2 ?????",
	words_min : "??? ?? ???? ????? %0 ????? ?????, ????: %1 ?????",
	words_range : "??? ?? ???? ????? %0 ????? ???????, ????: %1 ?????"
}
 
Category: CFv4 Validation

Comments:

You need to login to be able to post a comment.