Intl.Locale.prototype.language

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2020.

Intl.Locale.prototype.language プロパティは、ロケールに関連付けられた言語を返すアクセサープロパティです。

解説

言語はロケールの中核的な特徴の一つです。 Unicode 仕様書では、ロケールの言語識別子を言語と地域を合わせたものとして扱います(イギリス英語とアメリカ英語などの方言や変化形を区別するためです)。 Localelanguage プロパティは、ロケールの言語サブタグを厳密に返します。

ロケール識別子の文字列引数で言語を設定

有効な Unicode 言語識別子となるためには、文字列は言語サブタグで始めなければなりません。 Locale コンストラクターの主要な引数には、有効な Unicode ロケール識別子がなければならないので、コンストラクターを使用する際には必ず言語サブタグを持つ識別子を渡さなければなりません。

js
let locale = new Intl.Locale("en-Latn-US");
console.log(locale.language); // "en" と表示

構成オブジェクトにより言語を上書き

言語サブタグは指定する必要がありますが、 Locale コンストラクターは構成オブジェクトを取り、これを用いて言語サブタグを上書きすることができます。

js
let locale = new Intl.Locale("en-Latn-US", { language: "es" });
console.log(locale.language); // "es" と表示

仕様書

Specification
ECMAScript® 2025 Internationalization API Specification
# sec-Intl.Locale.prototype.language

ブラウザーの互換性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
language

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support

関連情報