• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# 国际化-Intl
2
3 本模块提供提供基础的应用国际化能力,包括时间日期格式化、数字格式化、排序等,相关接口在ECMA 402标准中定义。
4[I18N模块](js-apis-i18n.md)提供其他非ECMA 402定义的国际化接口,与本模块共同使用可提供完整地国际化支持能力。
5
6>  **说明:**
7> - 本模块首批接口从API version 6开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8>
9> - Intl模块包含国际化能力基础接口(在ECMA 402中定义),包括时间日期格式化、数字格式化、排序等,国际化增强能力请参考[I18N模块](js-apis-i18n.md)。
10
11
12## 导入模块
13
14```js
15import Intl from '@ohos.intl';
16```
17
18
19## Locale
20
21
22### 属性
23
24**系统能力**:以下各项对应的系统能力均为SystemCapability.Global.I18n
25
26| 名称              | 参数类型    | 可读   | 可写   | 说明                                       |
27| --------------- | ------- | ---- | ---- | ---------------------------------------- |
28| language        | string  | 是    | 否    | 与区域设置关联的语, 如:zh。                    |
29| script          | string  | 是    | 否    | 语言的书写方式,如:Hans。                          |
30| region          | string  | 是    | 否    | 与区域设置相关的地区,如:CN。                         |
31| baseName        | string  | 是    | 否    | Locale的基本核心信息(由语言脚本与地区组成),如:zh-Hans-CN。  |
32| caseFirst       | string  | 是    | 否    | 区域的整理规则是否考虑大小写,取值包括:"upper", "lower", "false"。 |
33| calendar        | string  | 是    | 否    | 区域的日历信息,取值包括:"buddhist", "chinese", "coptic","dangi", "ethioaa", "ethiopic", "gregory", "hebrew", "indian", "islamic", "islamic-umalqura", "islamic-tbla", "islamic-civil", "islamic-rgsa", "iso8601", "japanese", "persian", "roc", "islamicc"。 |
34| collation       | string  | 是    | 否    | 区域的排序规则,取值包括:"big5han", "compat", "dict", "direct", "ducet", "eor", "gb2312", "phonebk", "phonetic", "pinyin", "reformed", "searchjl", "stroke", "trad", "unihan", "zhuyin"。 |
35| hourCycle       | string  | 是    | 否    | 区域的时制信息,取值包括:"h12", "h23", "h11", "h24"。 |
36| numberingSystem | string  | 是    | 否    | 区域使用的数字系统,取值包括:"adlm", "ahom", "arab", "arabext", "bali", "beng", "bhks", "brah", "cakm", "cham", "deva", "diak", "fullwide", "gong", "gonm", "gujr", "guru", "hanidec", "hmng", "hmnp", "java", "kali", "khmr", "knda", "lana", "lanatham", "laoo", "latn", "lepc", "limb", "mathbold", "mathdbl", "mathmono", "mathsanb", "mathsans", "mlym", "modi", "mong", "mroo", "mtei", "mymr", "mymrshan", "mymrtlng", "newa", "nkoo", "olck", "orya", "osma", "rohg", "saur", "segment", "shrd", "sind", "sinh", "sora", "sund", "takr", "talu", "tamldec", "telu", "thai", "tibt", "tirh", "vaii", "wara", "wcho"。 |
37| numeric         | boolean | 是    | 否    | 是否对数字字符具有特殊的排序规则处理。                      |
38
39
40### constructor<sup>8+</sup>
41
42constructor()
43
44创建区域对象
45
46**系统能力**:SystemCapability.Global.I18n
47
48**示例:**
49  ```js
50  var locale = new Intl.Locale();
51  ```
52
53
54### constructor
55
56constructor(locale: string, options?: LocaleOptions)
57
58创建区域对象
59
60**系统能力**:SystemCapability.Global.I18n
61
62**参数:**
63| 参数名     | 类型            | 必填   | 说明                           |
64| ------- | ------------- | ---- | ---------------------------- |
65| locale  | string        | 是    | 包含区域设置信息的字符串,包括语言以及可选的脚本和区域。 |
66| options | LocaleOptions | 否    | 用于创建区域对象的选项。                 |
67
68**示例:**
69  ```js
70  var locale = new Intl.Locale("zh-CN");
71  ```
72
73
74### toString
75
76toString(): string
77
78将区域信息转换为字符串
79
80**系统能力**:SystemCapability.Global.I18n
81
82**返回值:**
83| 类型     | 说明          |
84| ------ | ----------- |
85| string | 字符串形式的区域信息。 |
86
87**示例:**
88  ```js
89  var locale = new Intl.Locale("zh-CN");
90  locale.toString();
91  ```
92
93
94### maximize
95
96maximize(): Locale
97
98最大化区域信息,若缺少脚本与地区信息,则补齐。
99
100**系统能力**:SystemCapability.Global.I18n
101
102**返回值:**
103| 类型                | 说明         |
104| ----------------- | ---------- |
105| [Locale](#locale) | 最大化后的区域对象。 |
106
107**示例:**
108  ```js
109  var locale = new Intl.Locale("zh-CN");
110  locale.maximize();
111  ```
112
113
114### minimize
115
116minimize(): Locale
117
118最小化区域信息,若包含脚本与地区信息,则去除。
119
120**系统能力**:SystemCapability.Global.I18n
121
122**返回值:**
123| 类型                | 说明         |
124| ----------------- | ---------- |
125| [Locale](#locale) | 最小化后的区域对象。 |
126
127**示例:**
128  ```js
129  var locale = new Intl.Locale("zh-CN");
130  locale.minimize();
131  ```
132
133
134## LocaleOptions
135
136表示区域初始化选项。
137
138**系统能力**:SystemCapability.Global.I18n
139
140| 名称              | 参数类型    | 可读   | 可写   | 说明                                       |
141| --------------- | ------- | ---- | ---- | ---------------------------------------- |
142| calendar        | string  | 是    | 是    | 日历参数,如:"buddhist", "chinese", "coptic", "dangi", "ethioaa", "ethiopic", "gregory", "hebrew", "indian", "islamic", "islamic-umalqura", "islamic-tbla", "islamic-civil", "islamic-rgsa", "iso8601", "japanese", "persian", "roc", "islamicc"。 |
143| collation       | string  | 是    | 是    | 排序参数,取值包括:"big5han", "compat", "dict", "direct", "ducet", "emoji", "eor", "gb2312", "phonebk", "phonetic", "pinyin", "reformed	", "search", "searchjl", "standard", "stroke", "trad", "unihan", "zhuyin"。 |
144| hourCycle       | string  | 是    | 是    | 时制格式,取值包括:"h11",&nbsp;"h12",&nbsp;"h23",&nbsp;"h24"。 |
145| numberingSystem | string  | 是    | 是    | 数字系统,取值包括:"adlm",&nbsp;"ahom",&nbsp;"arab",&nbsp;"arabext",&nbsp;"bali",&nbsp;"beng",&nbsp;"bhks",&nbsp;"brah",&nbsp;"cakm",&nbsp;"cham",&nbsp;"deva",&nbsp;"diak",&nbsp;"fullwide",&nbsp;"gong",&nbsp;"gonm",&nbsp;"gujr",&nbsp;"guru",&nbsp;"hanidec",&nbsp;"hmng",&nbsp;"hmnp",&nbsp;"java",&nbsp;"kali",&nbsp;"khmr",&nbsp;"knda",&nbsp;"lana",&nbsp;"lanatham",&nbsp;"laoo",&nbsp;"latn",&nbsp;"lepc",&nbsp;"limb",&nbsp;"mathbold",&nbsp;"mathdbl",&nbsp;"mathmono",&nbsp;"mathsanb",&nbsp;"mathsans",&nbsp;"mlym",&nbsp;"modi",&nbsp;"mong",&nbsp;"mroo",&nbsp;"mtei",&nbsp;"mymr",&nbsp;"mymrshan",&nbsp;"mymrtlng",&nbsp;"newa",&nbsp;"nkoo",&nbsp;"olck",&nbsp;"orya",&nbsp;"osma",&nbsp;"rohg",&nbsp;"saur",&nbsp;"segment",&nbsp;"shrd",&nbsp;"sind",&nbsp;"sinh",&nbsp;"sora",&nbsp;"sund",&nbsp;"takr",&nbsp;"talu",&nbsp;"tamldec",&nbsp;"telu",&nbsp;"thai",&nbsp;"tibt",&nbsp;"tirh",&nbsp;"vaii",&nbsp;"wara",&nbsp;"wcho"。 |
146| numeric         | boolean | 是    | 是    | 是否使用12小时制。                               |
147| caseFirst       | string  | 是    | 是    | 表示大写、小写的排序顺序,取值范围:"upper",&nbsp;"lower",&nbsp;"false"。 |
148
149
150## DateTimeFormat
151
152
153### constructor<sup>8+</sup>
154
155constructor()
156
157创建时间日期格式化对象。
158
159**系统能力**:SystemCapability.Global.I18n
160
161**示例:**
162  ```js
163  var datefmt= new Intl.DateTimeFormat();
164  ```
165
166
167### constructor
168
169constructor(locale: string | Array&lt;string&gt;, options?: DateTimeOptions)
170
171创建时间日期格式化对象。
172
173**系统能力**:SystemCapability.Global.I18n
174
175**参数:**
176| 参数名     | 类型                                  | 必填   | 说明                           |
177| ------- | ----------------------------------- | ---- | ---------------------------- |
178| locale  | string \| Array&lt;string&gt;       | 是    | 包含区域设置信息的字符串,包括语言以及可选的脚本和区域。 |
179| options | [DateTimeOptions](#datetimeoptions) | 否    | 用于创建时间日期格式化的选项。              |
180
181**示例:**
182  ```js
183  var datefmt= new Intl.DateTimeFormat("zh-CN", { dateStyle: 'full', timeStyle: 'medium' });
184  ```
185
186
187**示例:**
188  ```js
189  var datefmt= new Intl.DateTimeFormat(["ban", "zh"], { dateStyle: 'full', timeStyle: 'medium' });
190  ```
191
192
193### format
194
195format(date: Date): string
196
197格式化时间日期字符串。
198
199**系统能力**:SystemCapability.Global.I18n
200
201**参数:**
202| 参数名  | 类型   | 必填   | 说明      |
203| ---- | ---- | ---- | ------- |
204| date | Date | 是    | 时间日期对象。 |
205
206**返回值:**
207| 类型     | 说明           |
208| ------ | ------------ |
209| string | 格式化后的时间日期字符串 |
210
211**示例:**
212  ```js
213  var date = new Date(2021, 11, 17, 3, 24, 0);
214  var datefmt = new Intl.DateTimeFormat("en-GB");
215  datefmt.format(date);
216  ```
217
218
219### formatRange
220
221formatRange(startDate: Date, endDate: Date): string
222
223格式化时间日期段字符串。
224
225**系统能力**:SystemCapability.Global.I18n
226
227**参数:**
228| 参数名       | 类型   | 必填   | 说明       |
229| --------- | ---- | ---- | -------- |
230| startDate | Date | 是    | 起始的时间日期。 |
231| endDate   | Date | 是    | 结束的时间日期。 |
232
233**返回值:**
234| 类型     | 说明             |
235| ------ | -------------- |
236| string | 格式化后的时间日期段字符串。 |
237
238**示例:**
239  ```js
240  var startDate = new Date(2021, 11, 17, 3, 24, 0);
241  var endDate = new Date(2021, 11, 18, 3, 24, 0);
242  var datefmt = new Intl.DateTimeFormat("en-GB");
243  datefmt.formatRange(startDate, endDate);
244  ```
245
246
247### resolvedOptions
248
249resolvedOptions(): DateTimeOptions
250
251获取DateTimeFormat对象的格式化选项。
252
253**系统能力**:SystemCapability.Global.I18n
254
255**返回值:**
256| 类型                                  | 说明                            |
257| ----------------------------------- | ----------------------------- |
258| [DateTimeOptions](#datetimeoptions) | DateTimeFormat&nbsp;对象的格式化选项。 |
259
260**示例:**
261  ```js
262  var datefmt = new Intl.DateTimeFormat("en-GB");
263  datefmt.resolvedOptions();
264  ```
265
266
267## DateTimeOptions
268
269表示时间日期格式化选项。
270
271**系统能力**:SystemCapability.Global.I18n
272
273| 名称              | 参数类型    | 可读   | 可写   | 说明                                       |
274| --------------- | ------- | ---- | ---- | ---------------------------------------- |
275| locale          | string  | 是    | 否    | 区域参数,&nbsp;如:zh-Hans-CN。                 |
276| dateStyle       | string  | 是    | 是    | 日期显示格式,取值包括:"long",&nbsp;"short",&nbsp;"medium",&nbsp;"full"。 |
277| timeStyle       | string  | 是    | 是    | 时间显示格式,取值包括:"long",&nbsp;"short",&nbsp;"medium",&nbsp;"full"。 |
278| hourCycle       | string  | 是    | 是    | 时制格式,取值包括:"h11",&nbsp;"h12",&nbsp;"h23",&nbsp;"h24"。 |
279| timeZone        | string  | 是    | 是    | 使用的时区(合法的IANA时区ID)。                      |
280| numberingSystem | string  | 是    | 是    | 数字系统,取值包括:"adlm",&nbsp;"ahom",&nbsp;"arab",&nbsp;"arabext",&nbsp;"bali",&nbsp;"beng",&nbsp;"bhks",&nbsp;"brah",&nbsp;"cakm",&nbsp;"cham",&nbsp;"deva",&nbsp;"diak",&nbsp;"fullwide",&nbsp;"gong",&nbsp;"gonm",&nbsp;"gujr",&nbsp;"guru",&nbsp;"hanidec",&nbsp;"hmng",&nbsp;"hmnp",&nbsp;"java",&nbsp;"kali",&nbsp;"khmr",&nbsp;"knda",&nbsp;"lana",&nbsp;"lanatham",&nbsp;"laoo",&nbsp;"latn",&nbsp;"lepc",&nbsp;"limb",&nbsp;"mathbold",&nbsp;"mathdbl",&nbsp;"mathmono",&nbsp;"mathsanb",&nbsp;"mathsans",&nbsp;"mlym",&nbsp;"modi",&nbsp;"mong",&nbsp;"mroo",&nbsp;"mtei",&nbsp;"mymr",&nbsp;"mymrshan",&nbsp;"mymrtlng",&nbsp;"newa",&nbsp;"nkoo",&nbsp;"olck",&nbsp;"orya",&nbsp;"osma",&nbsp;"rohg",&nbsp;"saur",&nbsp;"segment",&nbsp;"shrd",&nbsp;"sind",&nbsp;"sinh",&nbsp;"sora",&nbsp;"sund",&nbsp;"takr",&nbsp;"talu",&nbsp;"tamldec",&nbsp;"telu",&nbsp;"thai",&nbsp;"tibt",&nbsp;"tirh",&nbsp;"vaii",&nbsp;"wara",&nbsp;"wcho"。 |
281| hour12          | boolean | 是    | 是    | 是否使用12小时制。                               |
282| weekday         | string  | 是    | 是    | 工作日的显示格式,取值包括:"long",&nbsp;"short",&nbsp;"narrow"。 |
283| era             | string  | 是    | 是    | 时代的显示格式,取值包括:"long",&nbsp;"short",&nbsp;"narrow"。 |
284| year            | string  | 是    | 是    | 年份的显示格式,取值包括:"numeric",&nbsp;"2-digit"。  |
285| month           | string  | 是    | 是    | 月份的显示格式,取值包括:"numeric",&nbsp;"2-digit",&nbsp;"long",&nbsp;"short",&nbsp;"narrow"。 |
286| day             | string  | 是    | 是    | 日期的显示格式,取值包括:"numeric",&nbsp;"2-digit"。  |
287| hour            | string  | 是    | 是    | 小时的显示格式,取值包括:"numeric",&nbsp;"2-digit"。  |
288| minute          | string  | 是    | 是    | 分钟的显示格式,取值包括:"numeric",&nbsp;"2-digit"。  |
289| second          | string  | 是    | 是    | 秒钟的显示格式,取值包括:"numeric",&nbsp;"2-digit"。  |
290| timeZoneName    | string  | 是    | 是    | 时区名称的本地化表示。                              |
291| dayPeriod       | string  | 是    | 是    | 时段的显示格式,取值包括:"long",&nbsp;"short",&nbsp;"narrow"。 |
292| localeMatcher   | string  | 是    | 是    | 要使用的区域匹配算法,取值包括:"lookup",&nbsp;"best&nbsp;fit"。 |
293| formatMatcher   | string  | 是    | 是    | 要使用的格式匹配算法,取值包括:"basic",&nbsp;"best&nbsp;fit"。 |
294
295
296## NumberFormat
297
298
299### constructor<sup>8+</sup>
300
301constructor()
302
303创建数字格式化对象。
304
305**系统能力**:SystemCapability.Global.I18n
306
307**示例:**
308  ```js
309  var numfmt = new Intl.NumberFormat();
310  ```
311
312
313### constructor
314
315constructor(locale: string | Array&lt;string&gt;, options?: NumberOptions)
316
317创建数字格式化对象。
318
319**系统能力**:SystemCapability.Global.I18n
320
321参数:
322| 参数名     | 类型                              | 必填   | 说明                           |
323| ------- | ------------------------------- | ---- | ---------------------------- |
324| locale  | string \| Array&lt;string&gt;   | 是    | 包含区域设置信息的字符串,包括语言以及可选的脚本和区域。 |
325| options | [NumberOptions](#numberoptions) | 否    | 用于创建数字格式化的选项。                |
326
327**示例:**
328  ```js
329  var numfmt = new Intl.NumberFormat("en-GB", {style:'decimal', notation:"scientific"});
330  ```
331
332
333### format
334
335format(number: number): string;
336
337格式化数字字符串。
338
339**系统能力**:SystemCapability.Global.I18n
340
341**参数:**
342| 参数名    | 类型     | 必填   | 说明   |
343| ------ | ------ | ---- | ---- |
344| number | number | 是    | 数字对象 |
345
346**返回值:**
347| 类型     | 说明         |
348| ------ | ---------- |
349| string | 格式化后的数字字符串 |
350
351
352**示例:**
353  ```js
354  var numfmt = new Intl.NumberFormat(["en-GB", "zh"], {style:'decimal', notation:"scientific"});
355  numfmt.format(1223);
356  ```
357
358
359### resolvedOptions
360
361resolvedOptions(): NumberOptions
362
363获取NumberFormat 对象的格式化选项。
364
365**系统能力**:SystemCapability.Global.I18n
366
367**返回值:**
368| 类型                              | 说明                          |
369| ------------------------------- | --------------------------- |
370| [NumberOptions](#numberoptions) | NumberFormat&nbsp;对象的格式化选项。 |
371
372
373**示例:**
374  ```js
375  var numfmt = new Intl.NumberFormat(["en-GB", "zh"], {style:'decimal', notation:"scientific"});
376  numfmt.resolvedOptions();
377  ```
378
379
380## NumberOptions
381
382表示设备支持的能力。
383
384**系统能力**:以下各项对应的系统能力均为SystemCapability.Global.I18n
385
386| 名称                       | 参数类型    | 可读   | 可写   | 说明                                       |
387| ------------------------ | ------- | ---- | ---- | ---------------------------------------- |
388| locale                   | string  | 是    | 否    | 区域参数,&nbsp;如:"zh-Hans-CN"。               |
389| currency                 | string  | 是    | 是    | 货币单位,&nbsp;如:"EUR","CNY","USD"等。         |
390| currencySign             | string  | 是    | 是    | 货币单位的符号显示,取值包括:&nbsp;"symbol","narrowSymbol","code","name"&nbsp;。 |
391| currencyDisplay          | string  | 是    | 是    | 货币的显示方式,取值包括:"symbol",&nbsp;"narrowSymbol",&nbsp;"code",&nbsp;"name"。 |
392| unit                     | string  | 是    | 是    | 单位名称,如:"meter","inch",“hectare”等。        |
393| unitDisplay              | string  | 是    | 是    | 单位的显示格式,取值包括:"long",&nbsp;"short",&nbsp;"narrow"。 |
394| unitUsage<sup>8+</sup>   | string  | 是    | 是    | 单位的使用场景,取值包括:"default",&nbsp;"area-land-agricult",&nbsp;"area-land-commercl",&nbsp;"area-land-residntl",&nbsp;"length-person",&nbsp;"length-person-small",&nbsp;"length-rainfall",&nbsp;"length-road",&nbsp;"length-road-small",&nbsp;"length-snowfall",&nbsp;"length-vehicle",&nbsp;"length-visiblty",&nbsp;"length-visiblty-small",&nbsp;"length-person-informal",&nbsp;"length-person-small-informal",&nbsp;"length-road-informal",&nbsp;"speed-road-travel",&nbsp;"speed-wind",&nbsp;"temperature-person",&nbsp;"temperature-weather",&nbsp;"volume-vehicle-fuel"。 |
395| signDisplay              | string  | 是    | 是    | 数字符号的显示格式,取值包括:"auto",&nbsp;"never",&nbsp;"always",&nbsp;"expectZero"。 |
396| compactDisplay           | string  | 是    | 是    | 紧凑型的显示格式,取值包括:"long",&nbsp;"short"。      |
397| notation                 | string  | 是    | 是    | 数字的格式化规格,取值包括:"standard",&nbsp;"scientific",&nbsp;"engineering",&nbsp;"compact"。 |
398| localeMatcher            | string  | 是    | 是    | 要使用的区域匹配算法,取值包括:"lookup",&nbsp;"best&nbsp;fit"。 |
399| style                    | string  | 是    | 是    | 数字的显示格式,取值包括:"decimal",&nbsp;"currency",&nbsp;"percent",&nbsp;"unit"。 |
400| numberingSystem          | string  | 是    | 是    | 数字系统,取值包括:"adlm",&nbsp;"ahom",&nbsp;"arab",&nbsp;"arabext",&nbsp;"bali",&nbsp;"beng",&nbsp;"bhks",&nbsp;"brah",&nbsp;"cakm",&nbsp;"cham",&nbsp;"deva",&nbsp;"diak",&nbsp;"fullwide",&nbsp;"gong",&nbsp;"gonm",&nbsp;"gujr",&nbsp;"guru",&nbsp;"hanidec",&nbsp;"hmng",&nbsp;"hmnp",&nbsp;"java",&nbsp;"kali",&nbsp;"khmr",&nbsp;"knda",&nbsp;"lana",&nbsp;"lanatham",&nbsp;"laoo",&nbsp;"latn",&nbsp;"lepc",&nbsp;"limb",&nbsp;"mathbold",&nbsp;"mathdbl",&nbsp;"mathmono",&nbsp;"mathsanb",&nbsp;"mathsans",&nbsp;"mlym",&nbsp;"modi",&nbsp;"mong",&nbsp;"mroo",&nbsp;"mtei",&nbsp;"mymr",&nbsp;"mymrshan",&nbsp;"mymrtlng",&nbsp;"newa",&nbsp;"nkoo",&nbsp;"olck",&nbsp;"orya",&nbsp;"osma",&nbsp;"rohg",&nbsp;"saur",&nbsp;"segment",&nbsp;"shrd",&nbsp;"sind",&nbsp;"sinh",&nbsp;"sora",&nbsp;"sund",&nbsp;"takr",&nbsp;"talu",&nbsp;"tamldec",&nbsp;"telu",&nbsp;"thai",&nbsp;"tibt",&nbsp;"tirh",&nbsp;"vaii",&nbsp;"wara",&nbsp;"wcho"。 |
401| useGrouping              | boolean | 是    | 是    | 是否分组显示。                                  |
402| minimumIntegerDigits     | number  | 是    | 是    | 表示要使用的最小整数位数,取值范围:1~21。                  |
403| minimumFractionDigits    | number  | 是    | 是    | 表示要使用的最小分数位数,取值范围:0~20。                  |
404| maximumFractionDigits    | number  | 是    | 是    | 表示要使用的最大分数位数,取值范围:1~21。                  |
405| minimumSignificantDigits | number  | 是    | 是    | 表示要使用的最低有效位数,取值范围:1~21。                  |
406| maximumSignificantDigits | number  | 是    | 是    | 表示要使用的最大有效位数,取值范围:1~21。                  |
407
408
409## Collator<sup>8+</sup>
410
411
412### constructor<sup>8+</sup>
413
414constructor()
415
416创建排序对象。
417
418**系统能力**:SystemCapability.Global.I18n
419
420**示例:**
421  ```js
422  var collator = new Intl.Collator();
423  ```
424
425
426### constructor<sup>8+</sup>
427
428constructor(locale: string | Array&lt;string&gt;, options?: CollatorOptions)
429
430创建排序对象。
431
432**系统能力**:SystemCapability.Global.I18n
433
434**参数:**
435
436| 参数名     | 类型                                  | 必填   | 说明                           |
437| ------- | ----------------------------------- | ---- | ---------------------------- |
438| locale  | string \| Array&lt;string&gt;       | 是    | 包含区域设置信息的字符串,包括语言以及可选的脚本和区域。 |
439| options | [CollatorOptions](#collatoroptions) | 否    | 用于创建排序对象的选项。                 |
440
441**示例:**
442  ```js
443  var collator = new Intl.Collator("zh-CN", {localeMatcher: "lookup", usage: "sort"});
444  ```
445
446
447### compare<sup>8+</sup>
448
449compare(first: string, second: string): number
450
451依据Collator的排序策略对两个字符串进行比较。
452
453**系统能力**:SystemCapability.Global.I18n
454
455**参数:**
456| 参数名    | 类型     | 必填   | 说明           |
457| ------ | ------ | ---- | ------------ |
458| first  | string | 是    | 进行比较第一个字符串。  |
459| second | string | 是    | 进行比较的第二个字符串。 |
460
461**返回值:**
462| 类型     | 说明                                       |
463| ------ | ---------------------------------------- |
464| number | 比较结果。当number为负数,表示first排序在second之前;当number为0,表示first与second排序相同;当number为正数,表示first排序在second之后。 |
465
466**示例:**
467  ```js
468  var collator = new Intl.Collator("zh-Hans");
469  collator.compare("first", "second");
470  ```
471
472
473### resolvedOptions<sup>8+</sup>
474
475resolvedOptions(): CollatorOptions
476
477返回Collator对象的属性。
478
479**系统能力**:SystemCapability.Global.I18n
480
481**返回值:**
482| 类型                                  | 说明                |
483| ----------------------------------- | ----------------- |
484| [CollatorOptions](#collatoroptions) | 返回的Collator对象的属性。 |
485
486**示例:**
487  ```js
488  var collator = new Intl.Collator("zh-Hans");
489  var options = collator.resolvedOptions();
490  ```
491
492
493## CollatorOptions<sup>8+</sup>
494
495表示Collator可设置的属性。
496
497**系统能力**:SystemCapability.Global.I18n
498
499| 名称                | 参数类型    | 可读   | 可写   | 说明                                       |
500| ----------------- | ------- | ---- | ---- | ---------------------------------------- |
501| localeMatcher     | string  | 是    | 是    | locale匹配算法,取值范围:"best&nbsp;fit",&nbsp;"lookup"。 |
502| usage             | string  | 是    | 是    | 比较的用途,取值范围:"sort",&nbsp;"search"。        |
503| sensitivity       | string  | 是    | 是    | 表示字符串中的哪些差异会导致非零结果值,取值范围:"base",&nbsp;"accent",&nbsp;"case",&nbsp;"variant"。 |
504| ignorePunctuation | boolean | 是    | 是    | 表示是否忽略标点符号,取值范围:true,&nbsp;false。        |
505| collation         | string  | 是    | 是    | 排序规则,取值范围:"big5han",&nbsp;"compat",&nbsp;"dict",&nbsp;"direct",&nbsp;"ducet",&nbsp;"eor",&nbsp;"gb2312",&nbsp;"phonebk",&nbsp;"phonetic",&nbsp;"pinyin",&nbsp;"reformed",&nbsp;"searchjl",&nbsp;"stroke",&nbsp;"trad",&nbsp;"unihan",&nbsp;"zhuyin"。 |
506| numeric           | boolean | 是    | 是    | 是否使用数字排序,取值范围:true,&nbsp;false。          |
507| caseFirst         | string  | 是    | 是    | 表示大写、小写的排序顺序,取值范围:"upper",&nbsp;"lower",&nbsp;"false"。 |
508
509
510## PluralRules<sup>8+</sup>
511
512
513### constructor<sup>8+</sup>
514
515constructor()
516
517创建PluralRules对象。
518
519**系统能力**:SystemCapability.Global.I18n
520
521**示例:**
522  ```js
523  var pluralRules = new Intl.PluralRules();
524  ```
525
526
527### constructor<sup>8+</sup>
528
529constructor(locale: string | Array&lt;string&gt;, options?: PluralRulesOptions)
530
531创建PluralRules对象。
532
533**系统能力**:SystemCapability.Global.I18n
534
535参数:
536| 参数名     | 类型                                       | 必填   | 说明                           |
537| ------- | ---------------------------------------- | ---- | ---------------------------- |
538| locale  | string \| Array&lt;string&gt;            | 是    | 包含区域设置信息的字符串,包括语言以及可选的脚本和区域。 |
539| options | [PluralRulesOptions](#pluralrulesoptions) | 否    | 用于创建单复数对象的选项。                |
540
541**示例:**
542  ```js
543  var pluralRules= new Intl.PluralRules("zh-CN", {"localeMatcher": "lookup", "type": "cardinal"});
544  ```
545
546
547### select<sup>8+</sup>
548
549select(n: number): string
550
551返回一个字符串表示该数字的单复数类别。
552
553**系统能力**:SystemCapability.Global.I18n
554
555**参数:**
556| 参数名  | 类型     | 必填   | 说明           |
557| ---- | ------ | ---- | ------------ |
558| n    | number | 是    | 待获取单复数类别的数字。 |
559
560**返回值:**
561| 类型     | 说明                                       |
562| ------ | ---------------------------------------- |
563| string | 单复数类别,取值包括:"zero","one","two",&nbsp;"few",&nbsp;"many",&nbsp;"others"。 |
564
565**示例:**
566  ```js
567  var pluralRules = new Intl.PluralRules("zh-Hans");
568  pluralRules.select(1);
569  ```
570
571
572## PluralRulesOptions<sup>8+</sup>
573
574表示PluralRules对象可设置的属性。
575
576**系统能力**:SystemCapability.Global.I18n
577
578| 名称                       | 参数类型   | 可读   | 可写   | 说明                                       |
579| ------------------------ | ------ | ---- | ---- | ---------------------------------------- |
580| localeMatcher            | string | 是    | 是    | locale匹配算法,取值包括:"best&nbsp;fit",&nbsp;"lookup"。 |
581| type                     | string | 是    | 是    | 排序的类型,取值包括:"cardinal",&nbsp;"ordinal"。   |
582| minimumIntegerDigits     | number | 是    | 是    | 表示要使用的最小整数位数,取值范围:1~21。                  |
583| minimumFractionDigits    | number | 是    | 是    | 表示要使用的最小分数位数,取值范围:0~20。                  |
584| maximumFractionDigits    | number | 是    | 是    | 表示要使用的最大分数位数,取值范围:1~21。                  |
585| minimumSignificantDigits | number | 是    | 是    | 表示要使用的最低有效位数,取值范围:1~21。                  |
586| maximumSignificantDigits | number | 是    | 是    | 表示要使用的最大有效位数,取值范围:1~21。                  |
587
588
589## RelativeTimeFormat<sup>8+</sup>
590
591
592### constructor<sup>8+</sup>
593
594constructor()
595
596创建相对时间格式化对象。
597
598**系统能力**:SystemCapability.Global.I18n
599
600**示例:**
601  ```js
602  var relativetimefmt = new Intl.RelativeTimeFormat();
603  ```
604
605
606### constructor<sup>8+</sup>
607
608constructor(locale: string | Array&lt;string&gt;, options?: RelativeTimeFormatInputOptions)
609
610创建相对时间格式化对象。
611
612**系统能力**:SystemCapability.Global.I18n
613
614参数:
615| 参数名     | 类型                                       | 必填   | 说明                           |
616| ------- | ---------------------------------------- | ---- | ---------------------------- |
617| locale  | string \| Array&lt;string&gt;            | 是    | 包含区域设置信息的字符串,包括语言以及可选的脚本和区域。 |
618| options | [RelativeTimeFormatInputOptions](#relativetimeformatinputoptions) | 否    | 用于创建相对时间格式化对象的选项。            |
619
620**示例:**
621  ```js
622  var relativeTimeFormat = new Intl.RelativeTimeFormat("zh-CN", {"localeMatcher": "lookup", "numeric": "always", "style": "long"});
623  ```
624
625
626### format<sup>8+</sup>
627
628format(value: number, unit: string): string
629
630依据locale和格式化选项,对value和unit进行格式化。
631
632**系统能力**:SystemCapability.Global.I18n
633
634**参数:**
635| 参数名   | 类型     | 必填   | 说明                                       |
636| ----- | ------ | ---- | ---------------------------------------- |
637| value | number | 是    | 相对时间格式化的数值。                              |
638| unit  | string | 是    | 相对时间格式化的单位,取值包括:"year",&nbsp;"quarter",&nbsp;"month",&nbsp;"week",&nbsp;"day",&nbsp;"hour",&nbsp;"minute",&nbsp;"second"。 |
639
640**返回值:**
641| 类型     | 说明         |
642| ------ | ---------- |
643| string | 格式化后的相对时间。 |
644
645**示例:**
646  ```js
647  var relativetimefmt = new Intl.RelativeTimeFormat("zh-CN");
648  relativetimefmt.format(3, "quarter")
649  ```
650
651
652### formatToParts<sup>8+</sup>
653
654formatToParts(value: number, unit: string): Array&lt;object&gt;
655
656返回一个对象数组,表示可用于自定义区域设置格式的相对时间格式。
657
658**系统能力**:SystemCapability.Global.I18n
659
660**参数:**
661| 参数名   | 类型     | 必填   | 说明                                       |
662| ----- | ------ | ---- | ---------------------------------------- |
663| value | number | 是    | 相对时间格式化的数值。                              |
664| unit  | string | 是    | 相对时间格式化的单位,取值包括:"year",&nbsp;"quarter",&nbsp;"month",&nbsp;"week",&nbsp;"day",&nbsp;"hour",&nbsp;"minute",&nbsp;"second"。 |
665
666**返回值:**
667| 类型                  | 说明                          |
668| ------------------- | --------------------------- |
669| Array&lt;object&gt; | 返回可用于自定义区域设置格式的相对时间格式的对象数组。 |
670
671**示例:**
672  ```js
673  var relativetimefmt = new Intl.RelativeTimeFormat("en", {"numeric": "auto"});
674  var parts = relativetimefmt.format(10, "seconds");
675  ```
676
677
678### resolvedOptions<sup>8+</sup>
679
680resolvedOptions(): RelativeTimeFormatResolvedOptions
681
682获取RelativeTimeFormat对象的格式化选项。
683
684**系统能力**:SystemCapability.Global.I18n
685
686**返回值:**
687| 类型                                       | 说明                                |
688| ---------------------------------------- | --------------------------------- |
689| [RelativeTimeFormatResolvedOptions](#relativetimeformatresolvedoptions) | RelativeTimeFormat&nbsp;对象的格式化选项。 |
690
691**示例:**
692  ```js
693  var relativetimefmt= new Intl.RelativeTimeFormat("en-GB");
694  relativetimefmt.resolvedOptions();
695  ```
696
697
698## RelativeTimeFormatInputOptions<sup>8+</sup>
699
700表示RelativeTimeFormat对象可设置的属性。
701
702**系统能力**:SystemCapability.Global.I18n
703
704| 名称            | 参数类型   | 可读   | 可写   | 说明                                       |
705| ------------- | ------ | ---- | ---- | ---------------------------------------- |
706| localeMatcher | string | 是    | 是    | locale匹配算法,取值包括:"best&nbsp;fit",&nbsp;"lookup"。 |
707| numeric       | string | 是    | 是    | 输出消息的格式,取值包括:"always",&nbsp;"auto"。      |
708| style         | string | 是    | 是    | 国际化消息的长度,取值包括:"long",&nbsp;"short",&nbsp;"narrow"。 |
709
710
711## RelativeTimeFormatResolvedOptions<sup>8+</sup>
712
713表示RelativeTimeFormat对象可设置的属性。
714
715**系统能力**:SystemCapability.Global.I18n
716
717| 名称              | 参数类型   | 可读   | 可写   | 说明                                       |
718| --------------- | ------ | ---- | ---- | ---------------------------------------- |
719| locale          | string | 是    | 是    | 包含区域设置信息的字符串,包括语言以及可选的脚本和区域。             |
720| numeric         | string | 是    | 是    | 输出消息的格式,取值包括:"always",&nbsp;"auto"。      |
721| style           | string | 是    | 是    | 国际化消息的长度,取值包括:"long",&nbsp;"short",&nbsp;"narrow"。 |
722| numberingSystem | string | 是    | 是    | 使用的数字系统。                                 |
723