Intl.Locale.prototype.getTextInfo()

Intl.Locale 实例的 getTextInfo() 方法返回该区域设置由 ltr(从左到右)或 rtl(从右到左)指示的字符顺序。

¥The getTextInfo() method of Intl.Locale instances returns the ordering of characters indicated by either ltr (left-to-right) or by rtl (right-to-left) for this locale.

注意:在某些浏览器的某些版本中,此方法被实现为名为 textInfo 的访问器属性。但是,由于它在每次访问时都会返回一个新对象,因此现在将其实现为一种方法,以防止出现 locale.textInfo === locale.textInfo 返回 false 的情况。检查 浏览器兼容性表 了解详细信息。

¥Note: In some versions of some browsers, this method was implemented as an accessor property called textInfo. However, because it returns a new object on each access, it is now implemented as a method to prevent the situation of locale.textInfo === locale.textInfo returning false. Check the browser compatibility table for details.

语法

¥Syntax

js
getTextInfo()

参数

¥Parameters

没有任何。

¥None.

返回值

¥Return value

表示与 UTS 35 的布局元素 中指定的 Locale 数据关联的文本排版信息的对象。它具有以下属性:

¥An object representing text typesetting information associated with the Locale data specified in UTS 35's Layouts Elements. It has the following properties:

direction

指示区域设置文本方向的字符串。可以是 "ltr"(从左到右)或 "rtl"(从右到左)。

示例

¥Examples

获取文本信息

¥Obtaining text info

返回给定 Locale 支持的文本方向。

¥Return the supported text directions for a given Locale.

js
const ar = new Intl.Locale("ar");
console.log(ar.getTextInfo()); // { direction: "rtl" }
console.log(ar.getTextInfo().direction); // "rtl"
js
const es = new Intl.Locale("es");
console.log(es.getTextInfo()); // { direction: "ltr" }
console.log(es.getTextInfo().direction); // "ltr"

规范

Specification
Intl Locale Info Proposal
# sec-Intl.Locale.prototype.getTextInfo

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看

¥See also