Intl.Locale.prototype.toString()

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.toString() は、このロケールの完全なロケール識別子文字列を返します。

試してみましょう

const french = new Intl.Locale("fr-Latn-FR", {
  calendar: "gregory",
  hourCycle: "h12",
});
const korean = new Intl.Locale("ko-Kore-KR", {
  numeric: true,
  caseFirst: "upper",
});

console.log(french.toString());
// Expected output: "fr-Latn-FR-u-ca-gregory-hc-h12"

console.log(korean.toString());
// Expected output: "ko-Kore-KR-u-kf-upper-kn"

構文

js
toString();

返値

このロケールの Unicode ロケール識別子文字列です。

解説

Locale オブジェクトは、概念的な Unicode ロケール識別子を JavaScript で表現したものです。特定のロケールに関する情報 (言語、文字体系、カレンダーの種類など) を、ロケール識別子文字列で符号化することができます。これらのロケール識別子をより簡単に扱えるようにするために、 Locale オブジェクトが JavaScript に導入されました。 Locale オブジェクトの toString メソッドをコールすると、そのロケールの識別子文字列を返します。 toString メソッドを使用すると、 Locale のインスタンスが既存の Intl のコンストラクターへの引数ととして JSON におけるシリアライズにおいて、またはその他のコンテキストで正確な文字列表現が有用な場合に提供することができます。

toString の使用

js
let myLocale = new Intl.Locale("ja-Jpan-JP", {
  hourCycle: "h24",
  calendar: "gregory",
});
console.log(myLocale.baseName); // "ja-Jpan-JP" と表示
console.log(myLocale.toString()); // "ja-Jpan-JP-u-ca-gregory-hc-h24" と表示

仕様書

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

ブラウザーの互換性

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
toString

Legend

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

Full support
Full support

関連情報