How to Localize wForms
This post is part of the wForms Documentation. wForms is an open-source javascript library that adds commonly needed behaviors to traditional web forms without the need for any programming skill.
For additional help, visit the wForms forum.
wForms was designed from the onset to be easily adapted to languages other than english.
When the wForms extension loads, it instantiates a javascript object called ‘wf’. Public properties and methods of that object can be easily overwritten for localization purpose.
You should not change wForms.js directly, as it would hinder your ability to install updates. Instead, use a short javascript file, linked after wForms.js.
For instance,
<script type="text/javascript" src="js/wforms.js" ></script>
<script type="text/javascript" src="js/localization-francais.js" ></script>
Available Localization Files
- Please visit http://www.formassembly.com/wForms for the complete list.
How to create your own localization file
1. Translating Error Messages
Error messages are contained in an array (wf.arrErrorMsg[]). Your translation should follow this example :
wf.arrErrorMsg[0] = "Champs requis"; // required field
wf.arrErrorMsg[1] = "Caractères alphabétiques uniquement (a-z)"; // alpha char. only
wf.arrErrorMsg[2] = "Adresse email invalide"; // email
wf.arrErrorMsg[3] = "Entrez un nombre entier"; // integer
wf.arrErrorMsg[4] = "Entrez un nombre"; // float
wf.arrErro rMsg[5] = ""; // password - not implemented
wf.arrErrorMsg[6] = "Caractères alpha-numeriques uniquement (a-z 0-9)"; // alphanumeric
wf.arrErrorMsg[7] = "Date invalide"; // date
wf.arrErrorMsg[8] =”Il y a %% erreur(s). Votre formulaire n’a pas été envoyé.\nVérifiez les informations saisies.”; // %% will be replaced by the actual number of errors.
2. Translating Other Texts
wf.arrMsg[0] = "Ajouter"; // repeat link
wf.arrMsg[1] = "Ajouter un nouveau rang" // title attribute on the repeat link
wf.arrMsg[2] = "Supprimer"; // remove link
wf.arrMsg[3] = "Supprimer le rang" // title attribute on the remove link
wf.arrMsg[4] = "Next Page"; // label used with multi-page forms
wf.arrMsg[5] = "Previous Page"; // label used with multi-page forms
3. Adapting Input Validation
The Alphabetic and Alphanumeric field types are accepting by default only basic latin characters : a-z, A-Z and 0-9. To validate a different character set, the wf.isAlpha() and wf.isAlphanum() methods must be redefined.
These two methods rely on a regular expression to validate the input.
wf.isAlpha = function(s) {
var reg = /^[\u0041-\u007A\u00C0-\u00FF\u0100–\u017F]+$/;
return this.isEmpty(s) || reg.test(s);
}
wf.isAlphaNum = function(s) {
var reg = /^[\u0030-\u0039\u0041-\u007A\u00C0-\u00FF\u0100–\u017F]+$/;
return this.isEmpty(s) || reg.test(s);
}
The expression /^[\u0041-\u007A]+$/ covers the Unicode range 0041 to 007A, which corresponds to the basic latin alphabet.
The expression /^[\u0041-\u007A\u00C0-\u00FF\u0100–\u017F]+$/ covers the Unicode ranges 0041 to 007A, 00C0 to 00FF and 0100 to 017F. This includes the most common variations of the latin alphabet.
Here’s an overview of common Unicode ranges :
| Unicode Range | Character Set | Languages |
|---|---|---|
| \u0030-\u0039 | Numbers 0-9 | |
| \u0041-\u007A | Basic Latin | English |
| \u0041-\u007A + \u00C0-\u00FF |
Latin-1 (used with Basic Latin) | Danish, Dutch, Faroese, Finnish, Flemish, German, Icelandic, Irish,Italian, Norwegian, Portuguese, Spanish, and Swedish. |
| \u0041-\u007A + \u00C0-\u00FF + \u0100–\u017F |
Latin Extended-A (used with Latin-1 and Basic Latin) | Afrikaans, Basque, Breton, Catalan, Croatian, Czech, Esperanto, Estonian, French, Frisian, Greenlandic, Hungarian, Latin, Latvian, Lithuanian, Maltese, Polish, Provençal, Rhaeto-Romanic, Romanian, Romany, Sami, Slovak, Slovenian, Sorbian, Turkish, Welsh, and many others. |
| \u0370-\u03FF | Greek | |
| \u0400-\u04FF | Cyrillic | Russian, etc.. |
| \u0590–\u05FF | Hebrew | |
| \u0600–\u06FF | Arabic | |
| \u0900–\u097F | Devanagari | Hindi, etc.. |
| \u4E00–\u9FFF | Han | Chinese, Japanese, and Korean languages |
See http://www.unicode.org/charts/ for other languages.
Please share your localization files by sending them to webmaster at formassembly dot com.
Update: Comments are now closed for this post, but you can go to the wForms forum if you have any question or comment. Thanks !
April 8th, 2005 at 1:41 am
// Português do Brasil (pt_BR)
this.arrErrorMsg = new Array();
this.arrErrorMsg[0] = “Este campo é obrigatório. “; // required
this.arrErrorMsg[1] = “O texto deve usar apenas caracteres alphabéticos (a-z, A-Z). Números não são permitidos. “; // validate_alpha
this.arrErrorMsg[2] = “Este não é um endereço de email válido.”; // validate_email
this.arrErrorMsg[3] = “Por favor entre um número inteiro.”; // validate_integer
this.arrErrorMsg[4] = “Por favor entre um número decimal (ex. 1.9).”;
this.arrErrorMsg[5] = “Senha insegura. Sua senha deve ter entre 4 e 12 caracteres e usar uma combinação de letras maiúsculas e minúsculas.”;
this.arrErrorMsg[6] = “”;
April 12th, 2005 at 1:18 pm
Dutch:
this.arrErrorMsg[0] = “Dit veld is verplicht. “; // required
this.arrErrorMsg[1] = “De tekst mag alleen uit letters (a-z, A-Z) bestaan. Getallen zijn niet toegestaan. “; // validate_alpha
this.arrErrorMsg[2] = “Dit ziet er niet uit als een email adres.”; // validate_email
this.arrErrorMsg[3] = “Vul een natuurlijk getal in.”; // validate_integer
this.arrErrorMsg[4] = “Vul een komma getal in (vb. 1.9).”;
this.arrErrorMsg[5] = “Onveilig paswoord. Je paswooord zou tussen de 4 en 12 karakters lang moeten zijn en gebruik maken an hoofdletters en kleine letters.”;
this.arrErrorMsg[6] = “Gebruk alleen alfanumerieke tekens [a-z 0-9].”;
this.arrErrorMsg[7] = “Dit is geen bestaande datum.”;
April 24th, 2005 at 9:24 pm
Spanish:
wf.arrErrorMsg[0] = “Campo obligatorio. “; /// required
wf.arrErrorMsg[1] = “Sólo se admiten letras (a-z A-Z). No se permiten números. “; // no numbers
wf.arrErrorMsg[2] = “No es una dirección de correo válida.”; // validate email
wf.arrErrorMsg[3] = “Introduzca un valor numérico.”; // integer
wf.arrErrorMsg[4] = “Introduzca un valor decimal (ej: 1.9) .”; // float
wf.arrErrorMsg[5] = “Contraseña insegura. Se admite una combinación de mayúsculas y minúsculas de entre 4 y 12 caracteres. “; // password
wf.arrErrorMsg[6] = “Únicamente caracteres alfanuméricos (a-z 0-9). “; // alphanumeric
wf.arrErrorMsg[7] = “La fecha no es correcta”; // date
wf.arrErrorMsg[8] = “Se ha(n) encontrado %% error(es). El formulario no se ha enviado.\nVerifique los datos introducidos.”; // %% errors.
wf.arrMsg[0] = “Añadir una fila”; // repeat row
wf.arrMsg[1] = “Repite el campo o grupo anterior.” // repeat row title
wf.arrMsg[2] = “Eliminar”; // remove row
wf.arrMsg[3] = “Borra el campo o grupo anterior.” // remove row title
May 15th, 2005 at 11:07 pm
// Localization for wForms - a javascript extension to web forms.
// Português do Brasil (pt_BR) v0.98 - May 15 2005.
// Thanks to Vicente Russo Neto (http://www.thedarkpirate.com || http://www.guiavest.com.br)
//
// This software is licensed under the CC-GNU LGPL
//
// Veja http://formassembly.com/blog/how-to-localize-wforms/
// Deve ser incluído *DEPOIS* de wforms.js
// Exemplo:
// …
//
//
//
wf.arrErrorMsg[0] = “Este campo é obrigatório.”; // requerido
wf.arrErrorMsg[1] = “O texto deve usar apenas caracteres alfabéticos (a-z, A-Z). Números não são permitidos.”; // validate_alpha
wf.arrErrorMsg[2] = “Este não é um endereço de email válido.”; // validate_email
wf.arrErrorMsg[3] = “Por favor entre um número inteiro.”; // validate_integer
wf.arrErrorMsg[4] = “Por favor entre um número decimal (ex. 1.9).”; // validate_float
wf.arrErrorMsg[5] = “Senha insegura. Sua senha deve ter entre 4 e 12 caracteres e usar uma combinação de letras maiúsculas e minúsculas.”; // senha - não implementado
wf.arrErrorMsg[6] = “somente alfa-numéricos”;
wf.arrErrorMsg[7] = “data inválida”;
wf.arrErrorMsg[8] = “%% erro(s) detectados. Seu formulário ainda não foi submetido.\nPor favor, verifique o(s) dado(s) informado(s).”; // %% será substituído pelo número atual de erros.
wf.arrMsg[0] = “Adicionar mais dados”; // repetir link
wf.arrMsg[1] = “Repetir o campo ou o grupo antecedente.” // título em repetir link
wf.arrMsg[2] = “Remover”; // removers link
wf.arrMsg[3] = “Remover o campo ou o grupo antecedente.” // título em remover link
wf.arrMsg[4] = “Próxima Página”;
wf.arrMsg[5] = “Página Anterior”;
// Alfa-Numériocos para validação de campo de entrada:
// limites do UNICODE (veja http://www.unicode.org/) :
// \u0030-\u0039 : Números 0-9
// \u0041-\u007A : Latim Básico : Para Inglès, e somente strings em ASCII (ex: login, senha, ..)
// \u00C0-\u00FF : Latim-1 : Para Dinamarquês, Holandês, Faroese (Norte da Alemanha), Finlandês, Flamengo (Bélgica), Alemão, Islandês, Irlandês, Italiano, Norueguês, Português , Espanhol, e Sueco.
// \u0100–\u017F : Latim Extendido-A (para ser usado com o Latim Básico e Latim-1) : Africano , Basco, Bretão, Catalão, Croata, Tcheco, Esperanto, Estoniano, Francês, Frisão, Húngaro, Latim, Letão, lituano, Maltês , Polonês, Provençal, Romeno, Cigano, Esloveno, Turco, Galês, e muitos outros.
// \u0180–\u024F : Latim Extendido-B (para ser usado com o Latim Básico e Latim-1) : ?
// \u1E00–\u1EFF : Latim Adicional Extendido : Vietnamita ?
// \u0370-\u03FF : Grego
// \u0400-\u04FF : Cirílico : Russo, etc..
// \u0590–\u05FF : Hebraico (e #FB1D - #FB4F ?)
// \u0600–\u06FF : Árabe
// \u0900–\u097F : Devanagario : Hindu, etc..
// \u4E00–\u9FFF : Han - ideogramas comuns: Chinês, Japanês, e idiomas Koreaos.
// veja http://www.unicode.org/charts/ para outras linguagens
May 17th, 2005 at 3:08 am
Many thanks Daniel, Roderik, Pablo & Vicente.
May 24th, 2005 at 11:30 am
Hi!
the translation to spanish for: Next Page & Previous Page is:
Next Page: Página siguiente
Previous Page: Página anterior
You’re making a great job!
Regards,
June 1st, 2005 at 11:51 pm
Dutch complete:
// Error messages. This array may be overwritten in a separate js file for localization or customization purpose.
this.arrErrorMsg = new Array();
this.arrErrorMsg[0] = “Dit veld is verplicht. “; // required
this.arrErrorMsg[1] = “De tekst kan uitsluitend alfanumerieke tekens bevatten (a-z, A-Z). Cijfers zijn niet toegestaan. “; // validate_alpha
this.arrErrorMsg[2] = “Dit email adres is niet juist.”; // validate_email
this.arrErrorMsg[3] = “Voer a.u.b. een geheel getal in.”; // validate_integer
this.arrErrorMsg[4] = “Voer a.u.b. een getal met cijfers achter de komma in (bijv. 1,9).”;
this.arrErrorMsg[5] = “Onveilig password. Uw password zou minimaal 4 en maximaal 12 karakters moeten bevatten en bestaan uit een combinatie van kleine en hoofdletters.”;
this.arrErrorMsg[6] = “Gebruik uitsluitend alfanumerieke karakters [a-z 0-9].”;
this.arrErrorMsg[7] = “Dit is geen valide datum.”;
this.arrErrorMsg[8] = “%% fouten ontdekt. Het formulier is nog niet verzonden.\nControleer a.u.b. de informatie die is ingevoerd.”; // %% will be replaced by the actual number of errors.
// Other Messages
this.arrMsg = new Array();
this.arrMsg[0] = “Klik om een rij toe te voegen”; // repeat link
this.arrMsg[1] = “Voeg een rij toe”; // title attribute on the repeat link
this.arrMsg[2] = “Verwijder de rij”; // remove link
this.arrMsg[3] = “Verwijdert het voorgaande veld of veld groep.”; // title attribute on the remove link
this.arrMsg[4] = “Volgende pagina”;
this.arrMsg[5] = “Vorige pagina”;
this.utilities = wu;
June 14th, 2005 at 7:15 pm
Thanx for the great work.
Best regards,
Here is Turkish localisation:
// Error messages. wf array may be overwritten in a separate js file for localization or customization purpose.
wf.arrErrorMsg[0] = “Bu alan zorunludur. “; // required
wf.arrErrorMsg[1] = “Metin sadece alfabetik karakterleri (a-z, A-Z) kullanmalıdır. Rakamlar kullanılamaz. “; // validate_alpha
wf.arrErrorMsg[2] = “Geçerli bir e-mail adresi olarak görünmüyor.”; // validate_email
wf.arrErrorMsg[3] = “Lütfen bir tamsayı giriniz.”; // validate_integer
wf.arrErrorMsg[4] = “Lütfen bir sayı giriniz (Ör: 1.9).”;
wf.arrErrorMsg[5] = “Basit şifre. Şifreniz 4-12 karakter uzunluğunda olmalı ve büyük-küçük harf kombinasyonları içermelidir.”;
wf.arrErrorMsg[6] = “Lütfen sadece alfanümerik karakterler kullanınız (a-z 0-9).”;
wf.arrErrorMsg[7] = “Geçerli bir tarih olarak görünmüyor.”;
wf.arrErrorMsg[8] = “%% hata bulundu. Formunuz henüz gönderilmedi.\nLütfen girdiğiniz bilgiyi kontrol ediniz.”;
// Other Messages
wf.arrMsg[0] = “Bir satır ekle”; // repeat link
wf.arrMsg[1] = “Önceki alanı veya alan grubunu tekrarlar.” // title attribute on the repeat link
wf.arrMsg[2] = “Çıkar”; // remove link
wf.arrMsg[3] = “Önceki alan veya alan grubunu çıkarır.” // title attribute on the remove link
wf.arrMsg[4] = “Sonraki Sayfa”;
wf.arrMsg[5] = “Önceki Sayfa”;
wf.isAlpha = function(s) {
var reg = /^[\u0041-\u007A\u00C0-\u00FF\u0100–\u017F]+$/; // Add ‘ and - ?
return this.isEmpty(s) || reg.test(s);
}
wf.isAlphaNum = function(s) {
var illegalChars = /[^\u0030-\u0039\u0041-\u007A\u00C0-\u00FF\u0100–\u017F]/;
return self.isEmpty(s) || !illegalChars.test(s);
}
August 17th, 2005 at 10:21 am
Here is Russian L10N:
// Сообщения об ощибках
wf.arrErrorMsg = new Array();
wf.arrErrorMsg[0] = “Это поле обязательно для заполнения. “;
wf.arrErrorMsg[1] = “В этом поле должны находиться только буквы (а-я, А-Я). Цифры не допустимы. “;
wf.arrErrorMsg[2] = “Неправильный формат адреса.”;
wf.arrErrorMsg[3] = “Пожалуйста введите целое число.”;
wf.arrErrorMsg[4] = “Пожалуйста введите дробное число (например, 1.9).”;
wf.arrErrorMsg[5] = “Небезопасный пароль. Ваш пароль должен быть от 4 до 12 знаков и состоять из комбинации заглывных и строчных букв.”;
wf.arrErrorMsg[6] = “Пожалуйста используйте только цифро-буквенные символы [а-я 0-9].”;
wf.arrErrorMsg[7] = “Неправильный формат даты.”;
wf.arrErrorMsg[8] = “Данные формы не были отправлены.\nПожалуйста проверьте введённую информацию.\n(Ошибок: %%) “;
// Прочие сообщения
wf.arrMsg = new Array();
wf.arrMsg[0] = “Добавить ряд”;
wf.arrMsg[1] = “Повторить предыдущее поле или группу полей.”;
wf.arrMsg[2] = “Удалить”;
wf.arrMsg[3] = “Удалить предыдущее поле или группу полей.”;
wf.arrMsg[4] = “Следующая страница”;
wf.arrMsg[5] = “Предыдущая страница”;
wf.isAlpha = function(s) {
var reg = /^[\u0400-\u04FF]+$/;
return this.isEmpty(s) || reg.test(s);
}
wf.isAlphaNum = function(s) {
var reg = /^[\u0030-\u0039\u0400-\u04FF]+$/;
return this.isEmpty(s) || reg.test(s);
}
November 1st, 2005 at 5:14 am
Hello,
I try to translate it to Chinese language.
But it can’t work.
Could anyone tell me what’s wrong ?
Thank Q~
December 19th, 2005 at 10:41 am
Hello cedsav, validate-alpha don’t accept space between words. It is correct? how can do this?
December 19th, 2005 at 9:32 pm
Edgar, try to add \s at the end of the regular expression, like this:
wf.isAlpha = function(s) {
var reg = /^[\u0041-\u007A\u00C0-\u00FF\u0100–\u017F\s]+$/;
return this.isEmpty(s) || reg.test(s);
}
April 9th, 2007 at 1:46 pm
[…] 只允许a-z 的字母 和数字(validate-alphanum)也允许空数据,用法同上。可以根据不同地区语言进行调整(方法) […]