Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multi language support

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.

like image 451
VansFannel Avatar asked Sep 02 '11 06:09

VansFannel


1 Answers

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? ;)

like image 174
Sebastian Wramba Avatar answered Sep 28 '22 08:09

Sebastian Wramba