大网数据广告活动
Web 标准与前端开发

Intl.Locale() constructor

· 52CE 我爱测

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

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

JavaScript Demo: Intl.Locale() constructor

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

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
      • caseFirst
      • hourCycle
      • numeric

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

Browser compatibility

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。