A processing method of Web multi-language

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.