Time for action – rendering localized messages
Refer to the following steps to render different messages in your app according to the device's language settings:
Open the command-line tool and create a new PhoneGap project called
Globalization
:$ cordova create Globalization
Add the Globalization API plugin using the following command:
$ cordova plugin add cordova-plugin-globalization
Using the command-line tool, add the platform you want to use for this test (Android, Blackberry, iOS, or Windows Phone 8):
$ cordova platforms add android
Download and save the
l10n.js
file available at https://github.com/marcelklehr/html10n.js in thewww/js
folder.Go to the
www
folder and create the JSON file namedlangs.json
to store all the required language strings as shown here. A JSON file format is a simple way of storing data like XML. The file will have the same literals repeated for each language:{ “en”: { “welcome”: “Welcome”, “english”: “English”, “french”: “French”, “alert”: ...