The Intl.Locale()
constructor creates Intl.Locale
objects.
The Intl.Locale()
constructor creates Intl.Locale
objects.
tag
The Unicode locale identifier string. For the syntax of locale identifier strings, see the Intl main page. Note that the Intl.Locale
constructor, unlike most other Intl
constructors, does not accept an array of locales or undefined
.
options
An object that contains configuration for the Locale. Option values here take priority over extension keys in the locale identifier. Possible properties are:
language
The language. Any syntactically valid string following the unicode_language_subtag
grammar (2–3 or 5–8 letters) is accepted, but the implementation only recognizes certain kinds.
script
The script. Any syntactically valid string following the unicode_script_subtag
grammar (4 letters) is accepted, but the implementation only recognizes certain kinds.
region
The region. Any syntactically valid string following the unicode_region_subtag
grammar (either 2 letters or 3 digits) is accepted, but the implementation only recognizes certain kinds.
calendar
The calendar. Any syntactically valid string following the type
grammar (one or more segments of 3–8 alphanumerals, joined by hyphens) is accepted, but the implementation only recognizes certain kinds, which are listed in Intl.Locale.prototype.getCalendars
.
collation
The collation. Any syntactically valid string following the type
grammar is accepted, but the implementation only recognizes certain kinds, which are listed in Intl.Locale.prototype.getCollations
.
numberingSystem
The numbering system. Any syntactically valid string following the type
grammar is accepted, but the implementation only recognizes certain kinds, which are listed in Intl.Locale.prototype.getNumberingSystems
.
caseFirst
The case-first sort option. Possible values are "upper"
, "lower"
, or "false"
.
hourCycle
The hour cycle. Possible values are "h23"
, "h12"
, "h11"
, or the practically unused "h24"
, which are explained in Intl.Locale.prototype.getHourCycles
numeric
The numeric sort option. A boolean.
At its very simplest, the Intl.Locale()
constructor takes a locale identifier string as its argument:
const us = new Intl.Locale("en-US");
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:
const locale = new Intl.Locale("en-US", { hourCycle: "h12" }); console.log(locale.hourCycle); // "h12"
Desktop | Mobile | Server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | Deno | Node.js | ||
Locale |
74 | 79 | 75 | 62 | 14 | 74 | 79 | 53 | 14 | 11.0 | 74 | 1.8 | 12.0.0 |
Intl.Locale
in FormatJSIntl.Collator
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/Locale