globalization.getLocaleName

Get the string identifier for the client's current locale setting.

navigator.globalization.getLocaleName(successCallback, errorCallback);

Description

Returns the locale identifier string to the successCallback with a properties object as a parameter. That object should have a value property with a String value.

If there is an error getting the locale, then the errorCallback executes with a [GlobalizationError](GlobalizationError/globalizationerror.html) object as a parameter. The error's expected code is [GlobalizationError](GlobalizationError/globalizationerror.html).UNKNOWN\_ERROR.

Supported Platforms

  • Android
  • BlackBerry WebWorks (OS 5.0 and higher)
  • iOS
  • Windows Phone 8

Quick Example

When the browser is set to the en\_US locale, this displays a popup dialog with the text locale: en\_US.

navigator.globalization.getLocaleName(
    function (locale) {alert('locale: ' + locale.value + '\n');},
    function () {alert('Error getting locale\n');}
);

Full Example

<!DOCTYPE HTML>
<html>
  <head>
    <title>getLocaleName Example</title>
    <script type="text/javascript" charset="utf-8" src="cordova-x.x.x.js"></script>
    <script type="text/javascript" charset="utf-8">

    function checkLocale() {
      navigator.globalization.getLocaleName(
        function (locale) {alert('locale: ' + locale.value + '\n');},
        function () {alert('Error getting locale\n');}
      );
    }
    </script>
  </head>
  <body>
    <button onclick="checkLocale()">Click for locale</button>
  </body>
</html>

Windows Phone 8 Quirks

  • Returns the two-letter code defined in ISO 3166 for the current country/region.