When developing an internationalized system, multiple languages are required.
In general, there are two kinds of processing methods, one is back-end processing, the other is front-end processing. Oh, a little nonsense ~ ~
Back-end processing has not worked, guess the place where the markup needs to be handled is replaced.
Front-end processing is to first load the language files, and then the translation of the various DOM nodes to translate.
1<label id= "User" ></label>2<script>3 vari18n = {4En: {User: ' user '},5Zh: {User: ' users '} 6 }7 8 varLang = ' Zh ';9 Ten functiontranlation (str) { One returnI18N[LANG][STR] | |str; A } - -$ (' #user '). HTML (translation (' user '))); the</script>
Of course, this is the most stupid method, because it is inconvenient to modify, especially when the volume of translation is very large.
A more general approach is to write the translation field on the specified attr. For example, we agree that T is the DOM node to be translated, and the example above can be written as:
<labelT= "User"></label><Script> $('[T]'). each (function(){ varKey= $( This). attr ('T'); $( This). HTML (transltion (key); })</Script>
In this way, the JS code can not be modified, in the need to translate the place only need to add the T attribute.
Of course, doing a little better is to encapsulate the translation as a common method.
< Script > = function () {...} $ ('[t]'). Transtion (); </ Script >
A processing method of Web multi-language