Multi language support

VansFannel picture VansFannel · Sep 2, 2011 · Viewed 9.6k times · Source

I'm developing a HTML5 application that uses jQuery. I want to make it multi language: detecting user language and changing all literals to user's language.

I think that one approach is to use one HTML file for each language supported, but it is a waste of space.

Another approach could be use jQuery to change all literals to user's language. But I'm not sure how to do this.

What do you think? Is there a better approach?

UPDATE:

I've forget it to say that I have some literals inside JavaScript too.

Answer

Sebastian Wramba picture Sebastian Wramba · Sep 2, 2011

Coulnd't you do some sort of server-side query to the user's language and then load the appropriate text automatically? Maybe even a CMS is appropriate here.

For all the Javascript code, I would use String literals as a variable. So you can load a different language file appropriate to the user language.

File english.js:

var messages_siteA1 = "This is an alert.";
var messages_siteA2 = "...";
// ...

File german.js:

var messages_siteA1 = "Dies ist eine Warnung.";
var messages_siteA2 = "...";
// ...

And in your Javascript:

alert(messages_siteA1);

Or am I missing the point here? ;)