Intl.Locale.prototype.baseName
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 |
瀏覽器相容性
載入中…