JavaScript/Locale information
[i]Learn· Internationalization

Locale information

Locales underlie all behaviors of Intl. A locale is a set of conventions, represented in the Intl API by the Intl.Locale object. All Intl constructors that accept language tags also accept Intl.Locale objects.

Each locale is primarily defined by four things: a language, a script, a region, and sometimes some variants. When connected together by - in that order, they form a BCP 47 language tag.

  • The language is the most important part of the locale and is mandatory. When given a single language, like en or fr, there are algorithms to infer the rest of the information (see Intl.Locale.prototype.maximize()).
  • However, you often want to specify the region as well, because conventions can differ drastically between regions that speak the same language. For example, the date format in the US is MM/DD/YYYY, whereas in the UK it is DD/MM/YYYY, so specifying en-US or en-GB is important.
  • You can also specify a script. The script is the writing system, or the characters used to transcribe the language. In practice, the script is often unnecessary, because the language used in a certain region is only written in one script. However, there are exceptions such as the Serbian language, which can be written in both the Latin and Cyrillic scripts (sr-Latn and sr-Cyrl), or the Chinese language, which can be written in both the Simplified and Traditional scripts (zh-Hans and zh-Hant).
  • The variants are rarely used. Usually, they denote different orthographies; for example, German has the 1901 and 1996 orthography variants, which are written as de-1901 and de-1996.
// These two are equivalent when passed to other Intl APIs
const locale1 = new Intl.Locale("en-US");
const locale2 = new Intl.Locale("en-Latn-US");

console.log(locale1.language, locale1.script, locale1.region); // "en", undefined, "US"
console.log(locale2.language, locale2.script, locale2.region); // "en", "Latn", "US"

A locale also contains a set of conventions used by that particular culture:

Use casePropertyDescriptionExtension subtag
Date/time formatting calendar Used to group days into years, months, and weeks, and to assign names to them. For example, the gregory date "2022-01-01" becomes "28 Tevet 5782" in the hebrew calendar. ca
hourCycle Decides if times are displayed in 12-hour or 24-hour format, and whether the smallest hour number is 0 or 1. hc
Number formatting, including dates, times, durations, etc. numberingSystem Transforms numbers into a locale-specific notation. The regular 0123456789 system is called latn (Latin). Often, each script has a numbering system that is just a digit-by-digit translation, but some scripts have more than one numbering system, some may not typically write numbers in that script (for example, Chinese has its own hanidec numbering system, but most texts use the standard latn system), and others may require special conversion algorithms (for example, Roman numerals — roman). nu
Collation collation Defines the generic collation algorithm. For example, if you use the German phonebk collation, then "ä" is treated as "ae", and will be sorted between "ad" and "af". co
caseFirst Decides whether uppercase or lowercase letters should be sorted first, or if casing is ignored. kf
numeric Decides whether numbers are sorted as numbers or as strings. For example, if true, "10" will be sorted after "2". kn

You can explicitly specify these properties when constructing the Intl.Locale or passing language tags to other Intl constructors. There are two ways to do this — append them to the language tag or specify them as options.

  • To append them to the language tag, you first append the string -u (meaning "Unicode extension"), then the extension subtag as given above, then the value.
  • To specify them as options, you just add the property name as given above, together with its value, to the options object.

Using Intl.DateTimeFormat as an example, both of the following lines create a formatter that formats dates in the Hebrew calendar:

const df1 = new Intl.DateTimeFormat("en-US-u-ca-hebrew");
const df2 = new Intl.DateTimeFormat("en-US", { calendar: "hebrew" });

Unrecognized properties are ignored, so you can use the same syntax as above with Intl.NumberFormat, but it won't do anything different than just passing en-US, because number formatting doesn't use the calendar property.

It is tricky to get the default values of these locale conventions. new Intl.Locale("en-US").calendar returns undefined, because the Locale object only contains the information you passed to it. The default calendar is theoretically dependent on what API you are using the calendar with, so to get the default calendar of en-US as used by Intl.DateTimeFormat, you can use its resolvedOptions() method. The same goes for other properties.

const locale = new Intl.Locale("en-US");
console.log(locale.calendar); // undefined; it's not provided
console.log(new Intl.DateTimeFormat(locale).resolvedOptions().calendar); // "gregory"

Intl.Locale objects do two things simultaneously: they represent a parsed BCP 47 language tag (as demonstrated above), and they provide information about that locale. All of its properties, like calendar, are extracted from the input only, without querying any data source about default values. On the other hand, it has a group of methods for querying real-world information about the locale. For example, the getCalendars(), getHourCycles(), getNumberingSystems(), and getCollations() methods complement the calendar, hourCycle, numberingSystem, and collation properties, and each returns an array of preferred values for that property.

const locale = new Intl.Locale("ar-EG");
console.log(locale.getCalendars()); // ['gregory', 'coptic', 'islamic', 'islamic-civil', 'islamic-tbla']

Intl.Locale instances also contain other methods that expose useful information, such as getTextInfo(), getTimeZones(), and getWeekInfo().

Source: Internationalization by Mozilla Contributors, licensed under CC-BY-SA-2.5. Retrieved 2026-11-18. Changes: Extracted the section "Locale information"; removed the code-block language labels; made links absolute; examples are the page's own code blocks, unchanged.