W3cubDocs

/JavaScript

Intl.locale

The Intl.Locale object is a standard built-in property of the Intl object that represents a Unicode locale identifier.

Description

The Intl.Locale object was created to allow for easier manipulation of Unicode locales. Unicode represents locales with a string, called a locale identifier. The locale identifier consists of a language identifier and extension tags. Language identifiers are the core of the locale, consisting of language, script, and region subtags. Additional information about the locale is stored in the optional extension tags. Extension tags hold information about locale aspects such as calendar type, clock type, and numbering system type.

Traditionally, the Intl API used strings to represent locales, just as Unicode does. This is a simple and lightweight solution that works well. Adding a Locale class, however, adds ease of parsing and manipulating the language, script, and region, as well as extension tags.

Constructor

Intl.Locale()
Creates a new Locale object.

Instance properties

Intl.Locale.prototype.baseName
Returns basic, core information about the Locale in the form of a substring of the complete data string.
Intl.Locale.prototype.calendar
Returns the part of the Locale that indicates the Locale's calendar era.
Intl.Locale.prototype.caseFirst
Returns whether case is taken into account for the locale's collation rules.
Intl.Locale.prototype.collation
Returns the collation type for the Locale, which is used to order strings according to the locale's rules.
Intl.Locale.prototype.hourCycle
Returns the time keeping format convention used by the locale.
Intl.Locale.prototype.language
Returns the language associated with the locale.
Intl.Locale.prototype.numberingSystem
Returns the numeral system used by the locale.
Intl.Locale.prototype.numeric
Returns whether the locale has special collation handling for numeric characters.
Intl.Locale.prototype.region
Returns the region of the world (usually a country) associated with the locale.
Intl.Locale.prototype.script
Returns the script used for writing the particular language used in the locale.

Instance methods

Intl.Locale.prototype.maximize()
Gets the most likely values for the language, script, and region of the locale based on existing values.
Intl.Locale.prototype.minimize()
Gets the most likely values for the language, script, and region of the locale based on existing values.
Intl.Locale.prototype.toString()
Returns the Locale's full locale identifier string.

Examples

Basic usage

At its very simplest, the Intl.Locale constructor takes a locale identifier string as its argument:

let us = new Intl.Locale('en-US');

Using the Locale constructor with an options object

The constructor also takes an optional configuration object argument, which can contain any of several extension types. For example, set the hourCycle property of the configuration object to your desired hour cycle type, and then pass it into the constructor:

let us12hour = new Intl.Locale("en-US", {hourCycle: "h12"});
console.log(us12hour.hourCycle); // Prints "h12"

Specifications

Browser compatibilityUpdate compatibility data on GitHub

Desktop
Chrome Edge Firefox Internet Explorer Opera Safari
Locale 74 79 75 No 62 14
14
Safari 14 Technology Preview 107-111 returns a string instead of a Locale object from the minimize and maximize methods.
Locale() constructor 74 79 75 No 62 14
baseName 74 79 75 No 62 14
calendar 74 79 75 No 62 14
caseFirst 74 79 75 No 62 14
collation 74 79 75 No 62 14
hourCycle 74 79 75 No 62 14
language 74 79 75 No 62 14
maximize 74 79 75 No 62 14
14
Safari 14 Technology Preview 107-111 returns a string instead of a Locale object.
minimize 74 79 75 No 62 14
14
Safari 14 Technology Preview 107-111 returns a string instead of a Locale object.
numberingSystem 74 79 75 No 62 14
numeric 74 79 75 No 62 14
region 74 79 75 No 62 14
script 74 79 75 No 62 14
toString 74 79 75 No 62 14
Mobile
Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
Locale 74 74 No 53 14
14
Safari 14 Technology Preview 107-111 returns a string instead of a Locale object from the minimize and maximize methods.
11.0
Locale() constructor 74 74 No 53 14 11.0
baseName 74 74 No 53 14 11.0
calendar 74 74 No 53 14 11.0
caseFirst 74 74 No 53 14 11.0
collation 74 74 No 53 14 11.0
hourCycle 74 74 No 53 14 11.0
language 74 74 No 53 14 11.0
maximize 74 74 No 53 14
14
Safari 14 Technology Preview 107-111 returns a string instead of a Locale object.
11.0
minimize 74 74 No 53 14
14
Safari 14 Technology Preview 107-111 returns a string instead of a Locale object.
11.0
numberingSystem 74 74 No 53 14 11.0
numeric 74 74 No 53 14 11.0
region 74 74 No 53 14 11.0
script 74 74 No 53 14 11.0
toString 74 74 No 53 14 11.0
Server
Node.js
Locale 12.0.0
12.0.0
Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() constructor for more details.
Locale() constructor 13.0.0
13.0.0
12.0.0
Before version 13.0.0, only the locale data for en-US is available by default. When other locales are specified, the Locale instance silently falls back to en-US. To make full ICU (locale) data available for versions prior to 13, see Node.js documentation on the --with-intl option and how to provide the data.
baseName 12.0.0
12.0.0
Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() constructor for more details.
calendar 12.0.0
12.0.0
Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() constructor for more details.
caseFirst 12.0.0
12.0.0
Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() constructor for more details.
collation 12.0.0
12.0.0
Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() constructor for more details.
hourCycle 12.0.0
12.0.0
Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() constructor for more details.
language 12.0.0
12.0.0
Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() constructor for more details.
maximize 12.0.0
12.0.0
Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() constructor for more details.
minimize 12.0.0
12.0.0
Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() constructor for more details.
numberingSystem 12.0.0
12.0.0
Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() constructor for more details.
numeric 12.0.0
12.0.0
Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() constructor for more details.
region 12.0.0
12.0.0
Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() constructor for more details.
script 12.0.0
12.0.0
Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() constructor for more details.
toString 12.0.0
12.0.0
Before version 13.0.0, only the locale data for en-US is available by default. See the Locale() constructor for more details.

See also

© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://wiki.developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale