Reputation: 689
i´m developing a Phonegap app.
I want the user to be able to choose a language when they launch the app.
So i want all strings in my html and javascript files to be translated into the chosen language.
Is there a "best practise" or a plugin I could use?
Gettext http://jsgettext.berlios.de/ is to much for that, isn't it? Thanks for help!
Upvotes: 4
Views: 1520
Reputation: 5646
If you can live with the idea the application language is automatically set to the language configured on the phone (which is better in my opinion, but might not fit your requirements), you might have a look at the library I have just sent to github, called phonegap-l10n.
Upvotes: 1
Reputation: 880
You could use HTML localStorage and then make the language files in arrays like
lang.english = {
hello: "Hello kind sir",
bye: "Bye, hope to see you again"
}
So you would call the text like this if you are using jQuery to append to the DOM
$("#welcome p").text(lang.localStorage.getItem("lang").hello);
EDIT: I guess you could even make a function to receive the right text.
function getText(text) {
var localLanguage = localStorage.getItem("lang");
return lang.localLanguage.text;
}
So the correct way would be something like this:
$("#welcome p").text(getText(hello));
Patrick
Upvotes: 0