Intl.Locale.prototype.baseName

Baseline 已广泛支持

此功能已成熟,并可在许多设备和浏览器版本上使用。自 2020 年 9 月起,所有浏览器均已提供此功能。

Intl.Locale 实例的 baseName 访问器属性会返回此区域设置字符串表示形式的一个子字符串,其中包含此区域设置的核心信息,包括语言、脚本、地区和变体(如果可用)。

描述

baseName 返回 unicode_language_id 语法language ["-" script] ["-" region] *("-" variant) 子序列。它仅包含通过区域设置标识符字符串或选项对象在构造函数中显式指定的信息。

baseName 的设置器为 undefined。您不能直接更改此属性。

示例

基本示例

js
const myLoc = new Intl.Locale("fr-Latn-CA"); // Sets locale to Canadian French
console.log(myLoc.toString()); // "fr-Latn-CA-u-ca-gregory"
console.log(myLoc.baseName); // "fr-Latn-CA"

输入字符串中包含扩展标签的示例

js
// Sets language to Japanese, region to Japan,
// calendar to Gregorian, hour cycle to 24 hours
const japan = new Intl.Locale("ja-JP-u-ca-gregory-hc-24");
console.log(japan.toString()); // "ja-JP-u-ca-gregory-hc-h24"
console.log(japan.baseName); // "ja-JP"

使用覆盖输入字符串的选项的示例

js
// Input string indicates language as Dutch and region as Belgium,
// but options object overrides the region and sets it to the Netherlands
const dutch = new Intl.Locale("nl-Latn-BE", { region: "NL" });

console.log(dutch.baseName); // "nl-Latn-NL"

规范

规范
ECMAScript® 2026 国际化 API 规范
# sec-Intl.Locale.prototype.baseName

浏览器兼容性

另见