DedrisFrameworkDedrisFramework

← Plugins  /  Globalization

🌍

Globalization

cordova-plugin-globalization
iOS Android 🌐 Browser

This official Apache Cordova plugin reports locale- and language-specific information from the device and formats dates, numbers and currencies according to the user's settings. It's the building block for apps that need to feel native in every region.

Installation

terminal
cordova plugin add cordova-plugin-globalization

API

All methods live on navigator.globalization and are asynchronous — each takes a success and an error callback. Call them after deviceready:

MethodReturns
getPreferredLanguage(success, error)The user's current language, e.g. { value: "English" }.
getLocaleName(success, error)The device locale, e.g. { value: "en-US" }.
dateToString(date, success, error, options)A locale-formatted date string.
stringToDate(string, success, error, options)A parsed date from a locale string.
getDatePattern(success, error, options)The locale's date pattern and time zone.
getFirstDayOfWeek(success, error)The first day of the week for the locale.
numberToString(number, success, error, options)A locale-formatted number, percent or currency string.
getCurrencyPattern(currencyCode, success, error)The formatting pattern for a currency.

Usage example

Read the device locale and format today's date for it:

www/js/app.js
document.addEventListener("deviceready", onReady, false);

function onReady() {
  navigator.globalization.getLocaleName(
    function (locale) {
      console.log("Locale: " + locale.value);
    },
    function () {
      console.log("Could not read locale");
    }
  );

  navigator.globalization.dateToString(
    new Date(),
    function (date) {
      console.log("Today: " + date.value);
    },
    function () {},
    { formatLength: "medium", selector: "date" }
  );
}

Tips

📚 Source: the technical reference on this page is based on the official Apache Cordova globalization documentation. Descriptions and examples have been rewritten in DedrisFramework's own words. Apache Cordova documentation is published by the Apache Software Foundation under the Apache License 2.0.
← Back to plugins Start a project