I18n Phonegap / gettext app?

I am developing a Phonegap application.

I want the user to be able to choose the language when the application starts.

So, I want all the lines in my html and javascript files to be translated into the selected language.

Is there a "best practice" or plugin that I could use?

Gettext http://jsgettext.berlios.de/ is a lot for this, isn't it? Thanks for the help!

+4
source share
2 answers

If you can live with the idea, the application language is automatically installed in the language configured on the phone (which is better, in my opinion, but may not meet your requirements), you can take a look at the library I just sent to github called phonegap-l10n .

+1
source

You can use localStorage HTML and then make language files in arrays like

lang.english = { hello: "Hello kind sir", bye: "Bye, hope to see you again" } 

So, you would call the text as follows if you use jQuery to add to the DOM

 $("#welcome p").text(lang.localStorage.getItem("lang").hello); 

EDIT: I think you could even make a function to get the correct 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

0
source

Source: https://habr.com/ru/post/1478958/


All Articles