LocaleModule Module

The LocaleModule class exposes device locale information.

Usage

const Locale = require('Locale');

Properties

PropertyDescription

fromDevice

read-only: String

Specifies the device language and country setting expressed as a 2-letter, lowercase ISO 639-1 locale code, followed by an underscore, followed by a 2-letter, uppercase ISO-3166-1 country code.

Examples: en_US, es_MX

Methods

This class exposes no methods.

Example

The following example demonstrates how to print device locale information to the console. To use this class you must add the Locale capabilities to your project manifest.

const Locale = require('Locale');
const Diagnostics = require('Diagnostics');

// NOTE: You must enable the Locale capability in the project manifest.

// Languages are represented by a two-letter, lowercase ISO 639-1 code.
// Countries are represented by a two-letter, uppercase ISO-3166-1 code.
// The Locale module exposes these device settings as a single string,
// with the two fields separated by an underscore.
// e.g., en_US, zh_CN, es_MX...

const localeInfo = Locale.fromDevice;
Diagnostics.log(localeInfo);
const localeAsArray = localeInfo.split('_');
Diagnostics.log(localeAsArray);
const language = localeAsArray[0];
Diagnostics.log(language);
const country = localeAsArray[1];
Diagnostics.log(country);

// Now you can load resources or perform logic based on locale info.