Intl.Locale.prototype.toString()

Intl.Locale 实例的 toString() 方法返回此 Locale 的完整 区域设置标识符字符串

¥The toString() method of Intl.Locale instances returns this Locale's full locale identifier string.

Try it

语法

¥Syntax

js
toString()

参数

¥Parameters

没有任何。

¥None.

返回值

¥Return value

语言环境的 Unicode 语言环境标识符字符串。

¥The locale's Unicode locale identifier string.

描述

¥Description

Locale 对象是 Unicode 区域设置标识符概念的 JavaScript 表示。有关特定区域设置(语言、脚本、日历类型等)的信息可以编码在区域设置标识符字符串中。为了更轻松地使用这些区域设置标识符,JavaScript 中引入了 Locale 对象。对 Locale 对象调用 toString 方法将返回该特定 Locale 的标识符字符串。toString 方法允许将 Locale 实例作为参数提供给现有 Intl 构造函数,以 JSON 或任何其他需要使用精确字符串表示的上下文进行序列化。

¥The Locale object is a JavaScript representation of a concept Unicode locale identifier. Information about a particular locale (language, script, calendar type, etc.) can be encoded in a locale identifier string. To make it easier to work with these locale identifiers, the Locale object was introduced to JavaScript. Calling the toString method on a Locale object will return the identifier string for that particular Locale. The toString method allows Locale instances to be provided as an argument to existing Intl constructors, serialized in JSON, or any other context where an exact string representation is useful.

示例

¥Examples

使用 toString

¥Using toString

js
const myLocale = new Intl.Locale("fr-Latn-FR", {
  hourCycle: "h12",
  calendar: "gregory",
});
console.log(myLocale.baseName); // Prints "fr-Latn-FR"
console.log(myLocale.toString()); // Prints "fr-Latn-FR-u-ca-gregory-hc-h12"

规范

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

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看

¥See also