Cordova Version:

Document TOP » API Reference » Core Cordova Plugins » Globalization Plugin

Globalization Plugin

Tested Version: 1.0.7

Note

This document is based on the original Cordova docs available at Cordova Docs.

This plugin obtains information and performs operations specific to the user’s locale, language, and timezone. Note the difference between locale and language: locale controls how numbers, dates, and times are displayed for a region, while language determines what language text appears as, independently of locale settings. Often developers use locale to set both settings, but there is no reason a user couldn’t set her language to “English” but locale to “French”, so that text is displayed in English but dates, times, etc., are displayed as they are in France. Unfortunately, most mobile platforms currently do not make a distinction between these settings.

This plugin defines global navigator.globalization object. Although in the global scope, it is not available until after the deviceready event.

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    console.log(navigator.globalization);
}

Plugin ID

cordova-plugin-globalization

Adding the Plugin in Monaca

In order to use this plugin, please enable Globalization plugin in Monaca Cloud IDE.

API Reference

Objects

  • GlobalizationError

Methods

  • navigator.globalization.getPreferredLanguage
  • navigator.globalization.getLocaleName
  • navigator.globalization.dateToString
  • navigator.globalization.stringToDate
  • navigator.globalization.getDatePattern
  • navigator.globalization.getDateNames
  • navigator.globalization.isDayLightSavingsTime
  • navigator.globalization.getFirstDayOfWeek
  • navigator.globalization.numberToString
  • navigator.globalization.stringToNumber
  • navigator.globalization.getNumberPattern
  • navigator.globalization.getCurrencyPattern

GlobalizationError

An object representing a error from the Globalization API.

Properties
  • code: One of the following codes representing the error type (Number)
  • GlobalizationError.UNKNOWN_ERROR: 0
  • GlobalizationError.FORMATTING_ERROR: 1
  • GlobalizationError.PARSING_ERROR: 2
  • GlobalizationError.PATTERN_ERROR: 3
  • message: A text message that includes the error’s explanation and/or details. (String)
Description

This object is created and populated by Cordova, and returned to a callback in the case of an error.

Supported Platforms
  • Android
  • iOS
  • Windows
Example

When the following error callback executes, it displays a popup dialog with the text similar to code: 3 and message:

function errorCallback(error) {
    alert('code: ' + error.code + '\n' +
          'message: ' + error.message + '\n');
};