Book Image

PhoneGap Beginners Guide (third edition)

Book Image

PhoneGap Beginners Guide (third edition)

Overview of this book

Table of Contents (22 chapters)
PhoneGap Beginner's Guide Third Edition
About the Authors
About the Reviewers
Related Plugin Resources

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:

  1. Open the command-line tool and create a new PhoneGap project called Globalization:

    $ cordova create Globalization
  2. Add the Globalization API plugin using the following command:

    $ cordova plugin add cordova-plugin-globalization
  3. 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
  4. Download and save the l10n.js file available at in the www/js folder.

  5. Go to the www folder and create the JSON file named langs.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”: ...