- Overview
- Platform Support
- The Command-Line Interface
- Platform Guides
- Using Plugman to Manage Plugins
- The config.xml File
- Icons and Splash Screens
- Embedding WebViews
- Plugin Development Guide
- Privacy Guide
- Whitelist Guide
- Accelerometer
- Camera
- Capture
- Compass
- Connection
- Contacts
- Device
- Events
- File
- Geolocation
- Globalization
- InAppBrowser
- Media
- Notification
- Splashscreen
- Storage
This version of the documentation is outdated!
Click here for the latest released version.
globalization.getPreferredLanguage
Get the string identifier for the client's current language.
navigator.globalization.getPreferredLanguage(successCallback, errorCallback);
Description
Returns the language 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 language, 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
- Amazon Fire OS
- Android
- iOS
- Windows Phone 8
Quick Example
When the browser is set to the en\_US
locale, this should display a
popup dialog with the text language: English
:
navigator.globalization.getPreferredLanguage(
function (language) {alert('language: ' + language.value + '\n');},
function () {alert('Error getting language\n');}
);
Full Example
<!DOCTYPE HTML>
<html>
<head>
<title>getPreferredLanguage Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">
function checkLanguage() {
navigator.globalization.getPreferredLanguage(
function (language) {alert('language: ' + language.value + '\n');},
function () {alert('Error getting language\n');}
);
}
</script>
</head>
<body>
<button onclick="checkLanguage()">Click for language</button>
</body>
</html>
Windows Phone 8 Quirks
- Returns the ISO 639-1 two-letter code for the current language.