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 !