Jump to content

Tutorial about localization


 Share

Recommended Posts

One approach is to create a JavaScript object for each language you want to support, whose keys could be an identifier for a certain string, and whose corresponding value would be that string written in that language. For example:

var english = {};var spanish = {};english["greet"] = "hello";spanish["greet"] = "hola";var currentLanguage = english; // or spanishrenderText(currentLanguage["greet"]); // should show text in appropriate language

You can even pick a "primary" language and use that language for the keys, such that english["hello"] == "hello" and spanish["hello"] == "hola". This can be made more robust of course, e.g. falling back to the key or the primary language translation if the key doesn't exist, etc. but you can follow the basic principles here.

 

And regarding external files, the contents of your "language" objects can come from external JSON files, for example.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...