Intl.Locale.prototype.script
Intl.Locale
实例的 script
访问器属性返回用于编写此语言环境中使用的特定语言的脚本。
¥The script
accessor property of Intl.Locale
instances returns the script used for writing the particular language used in this locale.
描述
¥Description
脚本,有时称为书写系统,是语言环境的核心属性之一。它表示用于编写特定语言的符号或字形集。例如,与英语相关的文字是拉丁文,而与韩语相关的文字通常是韩文。在许多情况下,表示脚本并不是严格必要的,因为语言(这是必要的)仅用单个脚本编写。但是,此规则有例外,当多个脚本适用时,指示脚本很重要。script
属性的值在构造时设置,可以通过语言环境标识符的 script
子标签(第二部分,如果存在)或通过 Intl.Locale()
构造函数的 script
选项设置。如果两者都存在,则后者优先;如果两者都不存在,则该属性的值为 undefined
。
¥Script, sometimes called writing system, is one of the core attributes of a locale. It indicates the set of symbols, or glyphs, that are used to write a particular language. For instance, the script associated with English is Latin, whereas the script typically associated with Korean is Hangul. In many cases, denoting a script is not strictly necessary, since the language (which is necessary) is only written in a single script. There are exceptions to this rule, however, and it is important to indicate the script when multiple scripts are applicable. The script
property's value is set at construction time, either through the script
subtag (second part, if present) of the locale identifier or through the script
option of the Intl.Locale()
constructor. The latter takes priority if they are both present; and if neither is present, the property has value undefined
.
script
的集合访问器是 undefined
。你不能直接更改此属性。
¥The set accessor of script
is undefined
. You cannot change this property directly.
示例
¥Examples
与其他语言环境子标签一样,脚本可以通过语言环境字符串或构造函数的配置对象参数添加到 Intl.Locale
对象。
¥Like other locale subtags, the script can be added to the Intl.Locale
object via the locale string, or a configuration object argument to the constructor.
通过语言环境字符串添加脚本
¥Adding a script via the locale string
如果存在脚本,则它是有效 Unicode 语言标识符字符串的第二部分,可以添加到传递到 Intl.Locale()
构造函数中的初始语言环境标识符字符串中。请注意,该脚本不是区域设置标识符的必需部分。
¥The script, if present, is the second part of a valid Unicode language identifier string, and can be added to the initial locale identifier string that is passed into the Intl.Locale()
constructor. Note that the script is not a required part of a locale identifier.
const locale = new Intl.Locale("en-Latn-US");
console.log(locale.script); // Prints "Latn"
通过配置对象参数添加脚本
¥Adding a script via the configuration object argument
Intl.Locale()
构造函数有一个可选的配置对象参数。将配置对象的 script
属性设置为所需的脚本,然后将其传递到构造函数中。
¥The Intl.Locale()
constructor has an optional configuration object argument. Set the script
property of the configuration object to your desired script, and then pass it into the constructor.
const locale = new Intl.Locale("fr-FR", { script: "Latn" });
console.log(locale.script); // Prints "Latn"
规范
Specification |
---|
ECMAScript Internationalization API Specification # sec-Intl.Locale.prototype.script |
浏览器兼容性
BCD tables only load in the browser
也可以看看
¥See also
Intl.Locale
- Unicode 区域设置数据标记语言规范中的 Unicode 脚本子标签