Intl.Locale() constructor

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2020.

The Intl.Locale() constructor creates Intl.Locale objects.

Try it

const korean = new Intl.Locale("ko", {
  script: "Kore",
  region: "KR",
  hourCycle: "h23",
  calendar: "gregory",
});

const japanese = new Intl.Locale("ja-Jpan-JP-u-ca-japanese-hc-h12");

console.log(korean.baseName, japanese.baseName);
// Expected output: "ko-Kore-KR" "ja-Jpan-JP"

console.log(korean.hourCycle, japanese.hourCycle);
// Expected output: "h23" "h12"

Syntax

js
new Intl.Locale(tag)
new Intl.Locale(tag, options)

Note: Intl.Locale() can only be constructed with new. Attempting to call it without new throws a TypeError.

Parameters

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.

variants

The variants. It should be a dash (-) separated list of unique variant tags, where each tag is any syntactically valid string following the unicode_variant_subtag grammar (either 5–8 alphanumerals or a digit followed by 3 alphanumerals), 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.supportedValuesOf().

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.supportedValuesOf().

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.supportedValuesOf().

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.

Examples

Basic usage

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

js
const 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:

js
const locale = new Intl.Locale("en-US", { hourCycle: "h12" });
console.log(locale.hourCycle); // "h12"

Specifications

Specification
ECMAScript® 2027 Internationalization API Specification
# sec-intl-locale-constructor

Browser compatibility

desktop mobile server
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Bun
Deno
Node.js
Locale() constructor
Chrome – Full support
Chrome 74 (Release date: 2019-04-23)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 75 (Release date: 2020-04-07)
footnote Full support
Opera – Full support
Opera 62 (Release date: 2019-06-27)
footnote Full support
Safari – Full support
Safari 14 (Release date: 2020-09-16)
footnote Full support
Chrome Android – Full support
Chrome Android 74 (Release date: 2019-04-24)
footnote Full support
Firefox for Android – Full support
Firefox for Android 79 (Release date: 2020-07-28)
footnote Full support
Opera Android – Full support
Opera Android 53 (Release date: 2019-07-11)
footnote Full support
Safari on iOS – Full support
Safari on iOS 14 (Release date: 2020-09-16)
footnote Full support
Samsung Internet – Full support
Samsung Internet 11 (Release date: 2019-12-05)
footnote Full support
WebView Android – Full support
WebView Android 74 (Release date: 2019-04-24)
footnote Full support
WebView on iOS – Full support
WebView on iOS 14 (Release date: 2020-09-16)
footnote Full support
Bun – Full support
Bun 1 (Release date: 2023-09-08)
footnote Full support
Deno – Full support
Deno 1.8 (Release date: 2021-03-02)
footnote Full support
Node.js – Full support
Node.js 12 (Release date: 2019-04-23)
footnote Full support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

See also