I am developing a mobile application with Phonegap and I need internationalization - display a html page in different languages. I do understand now that this is not a Phonegap issue - I have to internationalize the web application.
Kind regards, Christian
--- Edit --
Phonegap has a nice Globalization plugin since 2.2.0. It covers a lot of the i18n functionality. Check the docs http://docs.phonegap.com/en/edge/cordova_globalization_globalization.md.html#Globalization
PhoneGap, Apache Cordova, and Ionic are frameworks for developing mobile application with single HTML, CSS, and JavaScript/TypeScript code base and targeting various mobile platforms, including Android. Install and enable the PhoneGap/Cordova repository plugin on the Plugins page as described in Managing plugins.
The plugin is available only in IntelliJ IDEA Ultimate. PhoneGap and Apache Cordova are frameworks for developing mobile application with single HTML, CSS, and JavaScript/TypeScript code base and targeting various mobile platforms, including Android.
PhoneGap originally started as an open-source project by Nitobi Software in 2008. Nitobi Software was acquired by Adobe in 2011 and shortly after donated PhoneGap to the Apache Software Foundation as Cordova.
Some Cordova plugins include Android Support Libraries to faciliate them. Most commonly, these are now included into the Cordova project by specifying them as Gradle dependencies (see the Cordova plugin spec documentation ).
I took an approach to this problem that allows others to contribute language translations for my application.
Pros:
Cons:
I used handlebars for templating and the html10n library to provide translation logic, translated strings come from community contributed json files.
TranslateWiki provides the actual translations through the power of crowd-sourcing. Most of the heavy lifting on my implementation is done by TranslateWiki, a free and open source community service from the Wiki Media Foundation.
Handlebars and the html10n library are powerful, built for the web and widely used. They prove to be extremely useful libraries for this implementation.
No native code or plugins are required.
index.html
<head> <script type="text/javascript" src="js/handlebars.js"></script> <script type="text/javascript" src="js/html10n.js"></script> <link rel="localizations" type="application/l10n+json" href="locales.json"> </head> <body> {{html10n "helloWorld"}} </body>
locales.json
{ "fr":"locales/fr.json", "en":"locales/en.json" }
locales/en.json
{ "en":{ "helloWorld":"Hello Cruel World" } }
locales/fr.json
{ "fr":{ "helloWorld":"Hello Baguette World" } }
index.js
Handlebars.registerHelper('html10n', function(str,a){ return (html10n != undefined ? html10n.get(str) : str); });
To switch between languages bring up your browser javascript console and type
html10n.localize("fr");
Some additional logic is needed to do browser language detection, I use Etherpad's implementation to accomplish this.
var language = document.cookie.match(/language=((\w{2,3})(-\w+)?)/); if(language) language = language[1]; html10n.bind('indexed', function() { html10n.localize([language, navigator.language, navigator.userLanguage, 'en']) }) html10n.bind('localized', function() { document.documentElement.lang = html10n.getLanguage() document.documentElement.dir = html10n.getDirection() // Then I display the index page using handlebars to render a template. });
That's it, a hack free recipe for rolling out i18n in your Cordova Application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With