Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what are the different approaches to multilingual javascript applications

I wonder what are the different and which is the best method to set up some multilingual javascript application. i want to have all used strings in one file to easily change strings or add more languages later.

thnx!

like image 440
headkit Avatar asked Apr 14 '11 14:04

headkit


2 Answers

You can simply make a big object tree:

var languages = {
   english:{
      Save:"Save"
   },
   german:{
      Save:"Speichern"
   }
};

In your app:

var l = languages.german;
alert(l.Save); //Alerts "Speicher"

The benefit of this system is that you can make sub objects to group some values together.

like image 74
Van Coding Avatar answered Oct 16 '22 05:10

Van Coding


Whatever you do, the most important thing is to separate between your code and the texts.

If the code and the texts are mixed, maintenance will be impossible and you'll soon abandon it.

The translatable texts must be easily scanned, so that translators can translate just texts. Then, you should be able to insert the translations conveniently.

We use a JS file that includes a map of strings. We have a simple Python script that extracts the translatable strings from it. The same script also builds the output JS file that includes the same labels with the translated strings.

The result is:

  • When the application evolves, it's easy to add new strings.
  • The script automatically finds the new strings and we can translate them.
  • Completed translations go back to the JS file without manual work.
like image 26
ICanLocalize Avatar answered Oct 16 '22 03:10

ICanLocalize