Intl.Locale() constructor

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

Try it

Syntax

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.

options

An object that contains configuration for the Locale. Keys are Unicode locale tags, values are valid Unicode tag values. Option values here take priority over extension keys in the locale identifier.

Examples

Basic usage

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

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:

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

Specifications

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

Browser compatibility

BCD tables only load in the browser

See also