• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.intl (Internationalization)
2
3 The **intl** module provides basic i18n capabilities, such as time and date formatting, number formatting, and string sorting, through the standard i18n APIs defined in ECMA 402.
4The [i18n](js-apis-i18n.md) module provides enhanced i18n capabilities through supplementary interfaces that are not defined in ECMA 402. It works with the intl module to provide a complete suite of i18n capabilities.
5
6>  **NOTE**
7>  - The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8>
9>  - This module provides basic i18n capabilities, such as time and date formatting, number formatting, and string sorting, through the standard i18n interfaces defined in ECMA 402. For details about the enhanced i18n capabilities, see [i18n](js-apis-i18n.md).
10
11
12## Modules to Import
13
14```ts
15import Intl from '@ohos.intl';
16```
17
18## Locale
19
20
21### Attributes
22
23**System capability**: SystemCapability.Global.I18n
24
25| Name             | Type     | Readable  | Writable  | Description                                      |
26| --------------- | ------- | ---- | ---- | ---------------------------------------- |
27| language        | string  | Yes   | No   | Language associated with the locale, for example, **zh**.                   |
28| script          | string  | Yes   | No   | Script type of the language, for example, **Hans**.                         |
29| region          | string  | Yes   | No   | Region associated with the locale, for example, **CN**.                        |
30| baseName        | string  | Yes   | No   | Basic key information about the locale, which consists of the language, script, and region, for example, **zh-Hans-CN**. |
31| caseFirst       | string  | Yes   | No   | Whether case is taken into account for the locale's collation rules. The value can be **upper**, **lower**, or **false**.|
32| calendar        | string  | Yes   | No   | Calendar for the locale. The value can be any of the following: **buddhist**, **chinese**, **coptic**, **dangi**, **ethioaa**, **ethiopic**, **gregory**, **hebrew**, **indian**, **islamic**, **islamic-umalqura**, **islamic-tbla**, **islamic-civil**, **islamic-rgsa**, **iso8601**, **japanese**, **persian**, **roc**, or **islamicc**.|
33| collation       | string  | Yes   | No   | Rule for sorting regions. The value can be any of the following: **big5han**, **compat**, **dict**, **direct**, **ducet**, **eor**, **gb2312**, **phonebk**, **phonetic**, **pinyin**, **reformed**, **searchjl**, **stroke**, **trad**, **unihan**, **zhuyin**.|
34| hourCycle       | string  | Yes   | No   | Time system for the locale. The value can be any of the following: **h12**, **h23**, **h11**, or **h24**.|
35| numberingSystem | string  | Yes   | No   | Numbering system for the locale. The value can be any of the following: **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**.|
36| numeric         | boolean | Yes   | No   | Whether to apply special collation rules for numeric characters. The default value is **false**.                     |
37
38
39### constructor<sup>8+</sup>
40
41constructor()
42
43Creates a **Locale** object.
44
45**System capability**: SystemCapability.Global.I18n
46
47**Example**
48  ```ts
49  // The default constructor uses the current system locale to create a Locale object.
50  let locale = new Intl.Locale();
51  // Return the current system locale.
52  let localeID = locale.toString();
53  ```
54
55
56### constructor
57
58constructor(locale: string, options?: LocaleOptions)
59
60Creates a **Locale** object.
61
62**System capability**: SystemCapability.Global.I18n
63
64**Parameters**
65
66| Name                 | Type                              | Mandatory  | Description                          |
67| -------------------- | -------------------------------- | ---- | ---------------------------- |
68| locale               | string                           | Yes   | A string containing locale information, including the language, optional script, and region. For details about the international standards and combination modes for the language, script, and country or region, see [intl Development](../../internationalization/intl-guidelines.md#setting-locale-information).|
69| options             | [LocaleOptions](#localeoptions6) | No   | Options for creating the **Locale** object.|
70
71**Example**
72  ```ts
73  // Create a Locale object named zh-CN.
74  let locale = new Intl.Locale("zh-CN");
75  let localeID = locale.toString(); // localeID = "zh-CN"
76  ```
77
78
79### toString
80
81toString(): string
82
83Obtains the string representation of a **Locale** object.
84
85**System capability**: SystemCapability.Global.I18n
86
87**Return value**
88
89| Type    | Description         |
90| ------ | ----------- |
91| string | String representation of the **Locale** object.|
92
93**Example**
94  ```ts
95  // Create a Locale object named en-GB.
96  let locale = new Intl.Locale("en-GB");
97  let localeID = locale.toString(); // localeID = "en-GB"
98  ```
99
100
101### maximize
102
103maximize(): Locale
104
105Maximizes information of the **Locale** object. If the script and locale information is missing, add the information.
106
107**System capability**: SystemCapability.Global.I18n
108
109**Return value**
110
111| Type               | Description        |
112| ----------------- | ---------- |
113| [Locale](#locale) | **Locale** object with the maximized information.|
114
115**Example**
116  ```ts
117  // Create a Locale object named zh.
118  let locale = new Intl.Locale("zh");
119  // Complete the script and region of the Locale object.
120  let maximizedLocale = locale.maximize();
121  let localeID = maximizedLocale.toString(); // localeID = "zh-Hans-CN"
122
123  // Create a Locale object named en-US.
124  locale = new Intl.Locale("en-US");
125  // Complete the script of the Locale object.
126  maximizedLocale = locale.maximize();
127  localeID = maximizedLocale.toString(); // localeID = "en-Latn-US"
128  ```
129
130
131### minimize
132
133minimize(): Locale
134
135Minimizes information of the **Locale** object. If the script and locale information is present, delete the information.
136
137**System capability**: SystemCapability.Global.I18n
138
139**Return value**
140
141| Type               | Description        |
142| ----------------- | ---------- |
143| [Locale](#locale) | **Locale** object with the minimized information.|
144
145**Example**
146  ```ts
147  // Create a Locale object named zh-Hans-CN.
148  let locale = new Intl.Locale("zh-Hans-CN");
149  // Remove the script and region of the Locale object.
150  let minimizedLocale = locale.minimize();
151  let localeID = minimizedLocale.toString(); // localeID = "zh"
152
153  // Create a Locale object named en-US.
154  locale = new Intl.Locale("en-US");
155  // Remove the region of the Locale object.
156  minimizedLocale = locale.minimize();
157  localeID = minimizedLocale.toString(); // localeID = "en"
158  ```
159
160
161## LocaleOptions<sup>6+</sup>
162
163Represents the locale options.
164Since API version 9, the attributes in **LocaleOptions** are optional.
165
166**System capability**: SystemCapability.Global.I18n
167
168| Name             | Type     | Readable  | Writable  | Description                                      |
169| --------------- | ------- | ---- | ---- | ---------------------------------------- |
170| calendar        | string  | Yes   | Yes   | Calendar for the locale. The value can be any of the following: **buddhist**, **chinese**, **coptic**, **dangi**, **ethioaa**, **ethiopic**, **gregory**, **hebrew**, **indian**, **islamic**, **islamic-umalqura**, **islamic-tbla**, **islamic-civil**, **islamic-rgsa**, **iso8601**, **japanese**, **persian**, **roc**, or **islamicc**.|
171| collation       | string  | Yes   | Yes   | Collation rule. The value can be any of the following: **big5han**, **compat**, **dict**, **direct**, **ducet**, **emoji**, **eor**, **gb2312**, **phonebk**, **phonetic**, **pinyin**, **reformed**, **search**, **searchjl**, **standard**, **stroke**, **trad**, **unihan**, **zhuyin**.|
172| hourCycle       | string  | Yes   | Yes   | Time system for the locale. The value can be any of the following: **h11**, **h12**, **h23**, or **h24**.|
173| numberingSystem | string  | Yes   | Yes   | Numbering system for the locale. The value can be any of the following: **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**.|
174| numeric         | boolean | Yes   | Yes   | Whether to use the 12-hour clock. The default value is **false**.                              |
175| caseFirst       | string  | Yes   | Yes   | Whether upper case or lower case is sorted first. The value can be **upper**, **lower**, or **false**.|
176
177
178## DateTimeFormat
179
180
181### constructor<sup>8+</sup>
182
183constructor()
184
185Creates a **DateTimeOptions** object for the specified locale.
186
187**System capability**: SystemCapability.Global.I18n
188
189**Example**
190  ```ts
191  // Use the current system locale to create a DateTimeFormat object.
192  let datefmt= new Intl.DateTimeFormat();
193  ```
194
195
196### constructor
197
198constructor(locale: string | Array&lt;string&gt;, options?: DateTimeOptions)
199
200Creates a **DateTimeOptions** object for the specified locale.
201
202**System capability**: SystemCapability.Global.I18n
203
204**Parameters**
205
206| Name                 | Type                                  | Mandatory  | Description                          |
207| -------------------- | ------------------------------------ | ---- | ---------------------------- |
208| locale               | string \| Array&lt;string&gt;        | Yes   | A string containing locale information, including the language, optional script, and region.|
209| options              | [DateTimeOptions](#datetimeoptions6) | No   | Options for creating a **DateTimeFormat** object. If no options are set, the default values of **year**, **month**, and **day** are **numeric**.|
210
211**Example**
212  ```ts
213  // Use locale zh-CN to create a DateTimeFormat object. Set dateStyle to full and timeStyle to medium.
214  let datefmt= new Intl.DateTimeFormat("zh-CN", { dateStyle: 'full', timeStyle: 'medium' });
215  ```
216
217
218**Example**
219  ```ts
220  // Use the locale list ["ban", "zh"] to create a DateTimeFormat object. Because ban is an invalid locale ID, locale zh is used to create the DateTimeFormat object.
221  let datefmt= new Intl.DateTimeFormat(["ban", "zh"], { dateStyle: 'full', timeStyle: 'medium' });
222  ```
223
224
225### format
226
227format(date: Date): string
228
229Formats the specified date and time.
230
231**System capability**: SystemCapability.Global.I18n
232
233**Parameters**
234
235| Name | Type  | Mandatory  | Description     |
236| ---- | ---- | ---- | ------- |
237| date | Date | Yes   | Date and time to be formatted.|
238
239**Return value**
240
241| Type    | Description          |
242| ------ | ------------ |
243| string | A string containing the formatted date and time.|
244
245**Example**
246  ```ts
247  let date = new Date(2021, 11, 17, 3, 24, 0);
248  // Use locale en-GB to create a DateTimeFormat object.
249  let datefmt = new Intl.DateTimeFormat("en-GB");
250  let formattedDate = datefmt.format(date); // formattedDate "17/12/2021"
251
252  // Use locale en-GB to create a DateTimeFormat object. Set dateStyle to full and timeStyle to medium.
253  datefmt = new Intl.DateTimeFormat("en-GB", { dateStyle: 'full', timeStyle: 'medium' });
254  formattedDate = datefmt.format(date); // formattedDate "Friday, 17 December 2021 at 03:24:00"
255  ```
256
257
258### formatRange
259
260formatRange(startDate: Date, endDate: Date): string
261
262Formats the specified date range.
263
264**System capability**: SystemCapability.Global.I18n
265
266**Parameters**
267
268| Name      | Type  | Mandatory  | Description      |
269| --------- | ---- | ---- | -------- |
270| startDate | Date | Yes   | Start date and time to be formatted.|
271| endDate   | Date | Yes   | End date and time to be formatted.|
272
273**Return value**
274
275| Type    | Description            |
276| ------ | -------------- |
277| string | A string containing the formatted date and time range.|
278
279**Example**
280  ```ts
281  let startDate = new Date(2021, 11, 17, 3, 24, 0);
282  let endDate = new Date(2021, 11, 18, 3, 24, 0);
283  // Use locale en-GB to create a DateTimeFormat object.
284  let datefmt = new Intl.DateTimeFormat("en-GB");
285  let formattedDateRange = datefmt.formatRange(startDate, endDate); // formattedDateRange = "17/12/2021-18/12/2021"
286  ```
287
288
289### resolvedOptions
290
291resolvedOptions(): DateTimeOptions
292
293Obtains the formatting options for **DateTimeFormat** object.
294
295**System capability**: SystemCapability.Global.I18n
296
297**Return value**
298
299| Type                                  | Description                           |
300| ------------------------------------ | ----------------------------- |
301| [DateTimeOptions](#datetimeoptions6) | Formatting options for **DateTimeFormat** objects.|
302
303**Example**
304  ```ts
305  let datefmt = new Intl.DateTimeFormat("en-GB", { dateStyle: 'full', timeStyle: 'medium' });
306  // Obtain the options of the DateTimeFormat object.
307  let options = datefmt.resolvedOptions();
308  let dateStyle = options.dateStyle; // dateStyle = "full"
309  let timeStyle = options.timeStyle; // timeStyle = "medium"
310  ```
311
312
313## DateTimeOptions<sup>6+</sup>
314
315Provides the options for the **DateTimeFormat** object.
316Since API version 9, the attributes in **DateTimeOptions** are optional.
317
318**System capability**: SystemCapability.Global.I18n
319
320| Name             | Type     | Readable  | Writable  | Description                                      |
321| --------------- | ------- | ---- | ---- | ---------------------------------------- |
322| locale          | string  | Yes   | No   | Locale, for example, **zh-Hans-CN**.                |
323| dateStyle       | string  | Yes   | Yes   | Date display format. The value can be **long**, **short**, **medium**, or **full**.|
324| timeStyle       | string  | Yes   | Yes   | Time display format. The value can be **long**, **short**, **medium**, or **full**.|
325| hourCycle       | string  | Yes   | Yes   | Time system for the locale. The value can be any of the following: **h11**, **h12**, **h23**, or **h24**.|
326| timeZone        | string  | Yes   | Yes   | Time zone represented by a valid IANA time zone ID.                     |
327| numberingSystem | string  | Yes   | Yes   | Numbering system for the locale. The value can be any of the following: **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**.|
328| hour12          | boolean | Yes   | Yes   | Whether to use the 12-hour clock. If **hour12** and **hourCycle** are not set and the 24-hour clock is turned on, the default value of **hour12** is **false**.        |
329| weekday         | string  | Yes   | Yes   | Workday display format. The value can be **long**, **short**, or **narrow**.|
330| era             | string  | Yes   | Yes   | Era display format. The value can be **long**, **short**, or **narrow**.|
331| year            | string  | Yes   | Yes   | Year display format. The value can be **numeric** or **2-digit**.  |
332| month           | string  | Yes   | Yes   | Month display format. The value can be any of the following: **numeric**, **2-digit**, **long**, **short**, **narrow**.|
333| day             | string  | Yes   | Yes   | Day display format. The value can be **numeric** or **2-digit**. |
334| hour            | string  | Yes   | Yes   | Hour display format. The value can be **numeric** or **2-digit**. |
335| minute          | string  | Yes   | Yes   | Minute display format. The value can be **numeric** or **2-digit**. |
336| second          | string  | Yes   | Yes   | Seconds display format. The value can be **numeric** or **2-digit**. |
337| timeZoneName    | string  | Yes   | Yes   | Localized representation of a time zone name.                             |
338| dayPeriod       | string  | Yes   | Yes   | Time period display format. The value can be **long**, **short**, or **narrow**.|
339| localeMatcher   | string  | Yes   | Yes   | Locale matching algorithm. The value can be **lookup** or **best fit**.|
340| formatMatcher   | string  | Yes   | Yes   | Format matching algorithm. The value can be **basic** or **best fit**.|
341
342
343## NumberFormat
344
345
346### constructor<sup>8+</sup>
347
348constructor()
349
350Creates a **NumberFormat** object for the specified locale.
351
352**System capability**: SystemCapability.Global.I18n
353
354**Example**
355  ```ts
356  // Use the current system locale to create a NumberFormat object.
357  let numfmt = new Intl.NumberFormat();
358  ```
359
360
361### constructor
362
363constructor(locale: string | Array&lt;string&gt;, options?: NumberOptions)
364
365Creates a **NumberFormat** object for the specified locale.
366
367**System capability**: SystemCapability.Global.I18n
368
369**Parameters**
370
371| Name                 | Type                              | Mandatory  | Description                          |
372| -------------------- | -------------------------------- | ---- | ---------------------------- |
373| locale               | string \| Array&lt;string&gt;    | Yes   | A string containing locale information, including the language, optional script, and region.|
374| options              | [NumberOptions](#numberoptions6) | No   | Options for creating a **NumberFormat** object.               |
375
376**Example**
377  ```ts
378  // Use locale en-GB to create a NumberFormat object. Set style to decimal and notation to scientific.
379  let numfmt = new Intl.NumberFormat("en-GB", {style:'decimal', notation:"scientific"});
380  ```
381
382
383### format
384
385format(number: number): string;
386
387Formats a number.
388
389**System capability**: SystemCapability.Global.I18n
390
391**Parameters**
392
393| Name   | Type    | Mandatory  | Description  |
394| ------ | ------ | ---- | ---- |
395| number | number | Yes   | Number to be formatted.|
396
397**Return value**
398
399| Type    | Description        |
400| ------ | ---------- |
401| string | Formatted number.|
402
403
404**Example**
405  ```ts
406  // Use locale list ["en-GB", "zh"] to create a NumberFormat object. Because en-GB is a valid locale ID, it is used to create the NumberFormat object.
407  let numfmt = new Intl.NumberFormat(["en-GB", "zh"], {style:'decimal', notation:"scientific"});
408  let formattedNumber = numfmt.format(1223); // formattedNumber = 1.223E3
409  ```
410
411
412### resolvedOptions
413
414resolvedOptions(): NumberOptions
415
416Obtains the options of the **NumberFormat** object.
417
418**System capability**: SystemCapability.Global.I18n
419
420**Return value**
421
422| Type                              | Description                         |
423| -------------------------------- | --------------------------- |
424| [NumberOptions](#numberoptions6) | Formatting options for **NumberFormat** objects.|
425
426
427**Example**
428  ```ts
429  let numfmt = new Intl.NumberFormat(["en-GB", "zh"], {style:'decimal', notation:"scientific"});
430  // Obtain the options of the NumberFormat object.
431  let options = numfmt.resolvedOptions();
432  let style = options.style; // style = decimal
433  let notation = options.notation; // notation = scientific
434  ```
435
436
437## NumberOptions<sup>6+</sup>
438
439Defines the device capability.
440Since API version 9, the attributes in **NumberOptions** are optional.
441
442**System capability**: SystemCapability.Global.I18n
443
444| Name                      | Type     | Readable  | Writable  | Description                                      |
445| ------------------------ | ------- | ---- | ---- | ---------------------------------------- |
446| locale                   | string  | Yes   | No   | Locale, for example, **zh-Hans-CN**. The default value is the system locale.              |
447| currency                 | string  | Yes   | Yes   | Currency unit, for example, **EUR**, **CNY**, or **USD**.        |
448| currencySign             | string  | Yes   | Yes   | Currency unit symbol. The value can be **symbol**, **narrowSymbol**, **code**, or **name**. The default value is **symbol**.|
449| currencyDisplay          | string  | Yes   | Yes   | Currency display mode. The value can be **symbol**, **narrowSymbol**, **code**, or **name**. The default value is **symbol**.|
450| unit                     | string  | Yes   | Yes   | Unit name, for example, **meter**, **inch**, or **hectare**.       |
451| unitDisplay              | string  | Yes   | Yes   | Unit display format. The value can be **long**, **short**, or **narrow**. The default value is **short**.|
452| unitUsage<sup>8+</sup>   | string  | Yes   | Yes   | Unit usage scenario. The value can be any of the following: **default**, **area-land-agricult**, **area-land-commercl**, **area-land-residntl**, **length-person**, **length-person-small**, **length-rainfall**, **length-road**, **length-road-small**, **length-snowfall**, **length-vehicle**, **length-visiblty**, **length-visiblty-small**, **length-person-informal**, **length-person-small-informal**, **length-road-informal**, **speed-road-travel**, **speed-wind**, **temperature-person**, **temperature-weather**, **volume-vehicle-fuel**. The default value is **default**.|
453| signDisplay              | string  | Yes   | Yes   | Number sign display format. The value can be **auto**, **never**, **always**, or **expectZero**. The default value is **auto**.|
454| compactDisplay           | string  | Yes   | Yes   | Compact display format. The value can be **long** or **short**. The default value is **short**.     |
455| notation                 | string  | Yes   | Yes   | Number formatting specification. The value can be **standard**, **scientific**, **engineering**, or **compact**. The default value is **standard**.|
456| localeMatcher            | string  | Yes   | Yes   | Locale matching algorithm. The value can be **lookup** or **best fit**. The default value is **best fit**.|
457| style                    | string  | Yes   | Yes   | Number display format. The value can be **decimal**, **currency**, **percent**, or **unit**. The default value is **decimal**.|
458| numberingSystem          | string  | Yes   | Yes   | Numbering system for the locale. The value can be any of the following: **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**. The default value is the default numbering system of the specified locale.|
459| useGrouping              | boolean | Yes   | Yes   | Whether to use grouping for display. The default value is **auto**.                                 |
460| minimumIntegerDigits     | number  | Yes   | Yes   | Minimum number of digits allowed in the integer part of a number. The value ranges from **1** to **21**. The default value of is **1**.                 |
461| minimumFractionDigits    | number  | Yes   | Yes   | Minimum number of digits in the fraction part of a number. The value ranges from **0** to **20**. The default value is **0**.                 |
462| maximumFractionDigits    | number  | Yes   | Yes   | Maximum number of digits in the fraction part of a number. The value ranges from **1** to **21**. The default value is **3**.                 |
463| minimumSignificantDigits | number  | Yes   | Yes   | Minimum number of the least significant digits. The value ranges from **1** to **21**. The default value of is **1**.                 |
464| maximumSignificantDigits | number  | Yes   | Yes   | Maximum number of the least significant digits. The value ranges from **1** to **21**. The default value is **21**.                 |
465
466
467## Collator<sup>8+</sup>
468
469
470### constructor<sup>8+</sup>
471
472constructor()
473
474Creates a **Collator** object.
475
476**System capability**: SystemCapability.Global.I18n
477
478**Example**
479  ```ts
480  // Use the system locale to create a Collator object.
481  let collator = new Intl.Collator();
482  ```
483
484
485### constructor<sup>8+</sup>
486
487constructor(locale: string | Array&lt;string&gt;, options?: CollatorOptions)
488
489Creates a **Collator** object.
490
491**System capability**: SystemCapability.Global.I18n
492
493**Parameters**
494
495| Name                 | Type                                  | Mandatory  | Description                          |
496| -------------------- | ------------------------------------ | ---- | ---------------------------- |
497| locale               | string \| Array&lt;string&gt;        | Yes   | A string containing locale information, including the language, optional script, and region.|
498| options              | [CollatorOptions](#collatoroptions8) | No   | Options for creating a **Collator** object.      |
499
500**Example**
501  ```ts
502  // Use locale zh-CN to create a Collator object. Set localeMatcher to lookup and usage to sort.
503  let collator = new Intl.Collator("zh-CN", {localeMatcher: "lookup", usage: "sort"});
504  ```
505
506
507### compare<sup>8+</sup>
508
509compare(first: string, second: string): number
510
511Compares two strings based on the sorting policy of the **Collator** object.
512
513**System capability**: SystemCapability.Global.I18n
514
515**Parameters**
516
517| Name   | Type    | Mandatory  | Description          |
518| ------ | ------ | ---- | ------------ |
519| first  | string | Yes   | First string to compare. |
520| second | string | Yes   | Second string to compare.|
521
522**Return value**
523
524| Type    | Description                                      |
525| ------ | ---------------------------------------- |
526| number | Comparison result. If the value is a negative number, the first string is before the second string. If the value of number is **0**, the first string is equal to the second string. If the value of number is a positive number, the first string is after the second string.|
527
528**Example**
529  ```ts
530  // Use locale en-GB to create a Collator object.
531  let collator = new Intl.Collator("en-GB");
532  // Compare the sequence of the first and second strings.
533  let compareResult = collator.compare("first", "second"); // compareResult = -1
534  ```
535
536
537### resolvedOptions<sup>8+</sup>
538
539resolvedOptions(): CollatorOptions
540
541Returns properties reflecting the locale and collation options of a **Collator** object.
542
543**System capability**: SystemCapability.Global.I18n
544
545**Return value**
546
547| Type                                  | Description               |
548| ------------------------------------ | ----------------- |
549| [CollatorOptions](#collatoroptions8) | Properties of the **Collator** object.|
550
551**Example**
552  ```ts
553  let collator = new Intl.Collator("zh-Hans", { usage: 'sort', ignorePunctuation: true });
554  // Obtain the options of the Collator object.
555  let options = collator.resolvedOptions();
556  let usage = options.usage; // usage = "sort"
557  let ignorePunctuation = options.ignorePunctuation; // ignorePunctuation = true
558  ```
559
560
561## CollatorOptions<sup>8+</sup>
562
563Represents the properties of a **Collator** object.
564Since API version 9, the attributes in **CollatorOptions** are optional.
565
566**System capability**: SystemCapability.Global.I18n
567
568| Name               | Type     | Readable  | Writable  | Description                                      |
569| ----------------- | ------- | ---- | ---- | ---------------------------------------- |
570| localeMatcher     | string  | Yes   | Yes   | Locale matching algorithm. The value can be **lookup** or **best fit**. The default value is **best fit**.|
571| usage             | string  | Yes   | Yes   | Whether the comparison is for sorting or for searching. The value can be **sort** or **search**. The default value is **sort**.       |
572| sensitivity       | string  | Yes   | Yes   | Differences in the strings that lead to non-zero return values. The value can be **base**, **accent**, **case**, or **letiant**. The default value is **variant**.|
573| ignorePunctuation | boolean | Yes   | Yes   | Whether punctuation is ignored. The value can be **true** or **false**. The default value is **false**.       |
574| collation         | string  | Yes   | Yes   | Rule for sorting regions. The value can be any of the following: **big5han**, **compat**, **dict**, **direct**, **ducet**, **eor**, **gb2312**, **phonebk**, **phonetic**, **pinyin**, **reformed**, **searchjl**, **stroke**, **trad**, **unihan**, **zhuyin**. The default value is **default**.|
575| numeric           | boolean | Yes   | Yes   | Whether numeric collation is used. The value can be **true** or **false**. The default value is **false**.         |
576| caseFirst         | string  | Yes   | Yes   | Whether upper case or lower case is sorted first. The value can be **upper**, **lower**, or **false**. The default value is **false**.|
577
578
579## PluralRules<sup>8+</sup>
580
581
582### constructor<sup>8+</sup>
583
584constructor()
585
586Creates a **PluralRules** object to obtain the singular-plural type of numbers.
587
588**System capability**: SystemCapability.Global.I18n
589
590**Example**
591  ```ts
592  // Use the system locale to create a PluralRules object.
593  let pluralRules = new Intl.PluralRules();
594  ```
595
596
597### constructor<sup>8+</sup>
598
599constructor(locale: string | Array&lt;string&gt;, options?: PluralRulesOptions)
600
601Creates a **PluralRules** object to obtain the singular-plural type of numbers.
602
603**System capability**: SystemCapability.Global.I18n
604
605**Parameters**
606
607| Name                 | Type                                      | Mandatory  | Description                          |
608| -------------------- | ---------------------------------------- | ---- | ---------------------------- |
609| locale               | string \| Array&lt;string&gt;            | Yes   | A string containing locale information, including the language, optional script, and region.|
610| options              | [PluralRulesOptions](#pluralrulesoptions8) | No   | Options for creating a **PluralRules** object.      |
611
612**Example**
613  ```ts
614  // Use locale zh-CN to create a PluralRules object. Set localeMatcher to lookup and type to cardinal.
615  let pluralRules= new Intl.PluralRules("zh-CN", {"localeMatcher": "lookup", "type": "cardinal"});
616  ```
617
618
619### select<sup>8+</sup>
620
621select(n: number): string
622
623Obtains a string that represents the singular-plural type of the specified number.
624
625**System capability**: SystemCapability.Global.I18n
626
627**Parameters**
628
629| Name | Type    | Mandatory  | Description          |
630| ---- | ------ | ---- | ------------ |
631| n    | number | Yes   | Number for which the singular-plural type is to be obtained.|
632
633**Return value**
634
635| Type    | Description                                      |
636| ------ | ---------------------------------------- |
637| string | Singular-plural type. The value can be any of the following: **zero**, **one**, **two**, **few**, **many**, **others**.|
638
639**Example**
640  ```ts
641  // Use locale zh-Hans to create a PluralRules object.
642  let zhPluralRules = new Intl.PluralRules("zh-Hans");
643  // Determine the singular-plural type corresponding to number 1 in locale zh-Hans.
644  let plural = zhPluralRules.select(1); // plural = other
645
646  // Use locale en-US to create a PluralRules object.
647  let enPluralRules = new Intl.PluralRules("en-US");
648  // Determine the singular-plural type corresponding to number 1 in locale en-US.
649  plural = enPluralRules.select(1); // plural = one
650  ```
651
652
653## PluralRulesOptions<sup>8+</sup>
654
655Represents the properties of a **PluralRules** object.
656Since API version 9, the attributes in **PluralRulesOptions** are optional.
657
658**System capability**: SystemCapability.Global.I18n
659
660| Name                      | Type    | Readable  | Writable  | Description                                      |
661| ------------------------ | ------ | ---- | ---- | ---------------------------------------- |
662| localeMatcher            | string | Yes   | Yes   | Locale matching algorithm. The value can be **lookup** or **best fit**. The default value is **best fit**.|
663| type                     | string | Yes   | Yes   | Sorting type. The value can be **cardinal** or **ordinal**. The default value is **cardinal**.  |
664| minimumIntegerDigits     | number | Yes   | Yes   | Minimum number of digits allowed in the integer part of a number. The value ranges from **1** to **21**. The default value of is **1**.                 |
665| minimumFractionDigits    | number | Yes   | Yes   | Minimum number of digits in the fraction part of a number. The value ranges from **0** to **20**. The default value is **0**.                 |
666| maximumFractionDigits    | number | Yes   | Yes   | Maximum number of digits in the fraction part of a number. The value ranges from **1** to **21**. The default value is **3**.                 |
667| minimumSignificantDigits | number | Yes   | Yes   | Minimum number of the least significant digits. The value ranges from **1** to **21**. The default value of is **1**.                 |
668| maximumSignificantDigits | number | Yes   | Yes   | Maximum number of the least significant digits. The value ranges from **1** to **21**. The default value is **21**.                 |
669
670
671## RelativeTimeFormat<sup>8+</sup>
672
673
674### constructor<sup>8+</sup>
675
676constructor()
677
678Creates a **RelativeTimeFormat** object.
679
680**System capability**: SystemCapability.Global.I18n
681
682**Example**
683  ```ts
684  // Use the system locale to create a RelativeTimeFormat object.
685  let relativetimefmt = new Intl.RelativeTimeFormat();
686  ```
687
688
689### constructor<sup>8+</sup>
690
691constructor(locale: string | Array&lt;string&gt;, options?: RelativeTimeFormatInputOptions)
692
693Creates a **RelativeTimeFormat** object.
694
695**System capability**: SystemCapability.Global.I18n
696
697**Parameters**
698
699| Name                 | Type                                      | Mandatory  | Description                          |
700| -------------------- | ---------------------------------------- | ---- | ---------------------------- |
701| locale               | string \| Array&lt;string&gt;            | Yes   | A string containing locale information, including the language, optional script, and region.|
702| options              | [RelativeTimeFormatInputOptions](#relativetimeformatinputoptions8) | No   | Options for creating a **RelativeTimeFormat** object.           |
703
704**Example**
705  ```ts
706  // Use locale zh-CN to create a RelativeTimeFormat object. Set localeMatcher to lookup, numeric to always, and style to long.
707  let relativeTimeFormat = new Intl.RelativeTimeFormat("zh-CN", {"localeMatcher": "lookup", "numeric": "always", "style": "long"});
708  ```
709
710
711### format<sup>8+</sup>
712
713format(value: number, unit: string): string
714
715Formats the value and unit based on the specified locale and formatting options.
716
717**System capability**: SystemCapability.Global.I18n
718
719**Parameters**
720
721| Name  | Type    | Mandatory  | Description                                      |
722| ----- | ------ | ---- | ---------------------------------------- |
723| value | number | Yes   | Value to format.                             |
724| unit  | string | Yes   | Unit to format. The value can be any of the following: **year**, **quarter**, **month**, **week**, **day**, **hour**, **minute**, **second**.|
725
726**Return value**
727
728| Type    | Description        |
729| ------ | ---------- |
730| string | Relative time after formatting.|
731
732**Example**
733  ```ts
734  // Use locale zh-CN to create a RelativeTimeFormat object.
735  let relativetimefmt = new Intl.RelativeTimeFormat("zh-CN");
736  // Obtain the localized representation (in unit of quarter) of number 3 in locale zh-CN.
737  let formatResult = relativetimefmt.format(3, "quarter"); // formatResult = "3 quarters later"
738  ```
739
740
741### formatToParts<sup>8+</sup>
742
743formatToParts(value: number, unit: string): Array&lt;object&gt;
744
745Obtains an array of RelativeTimeFormat objects in parts for locale-aware formatting.
746
747**System capability**: SystemCapability.Global.I18n
748
749**Parameters**
750
751| Name  | Type    | Mandatory  | Description                                      |
752| ----- | ------ | ---- | ---------------------------------------- |
753| value | number | Yes   | Value to format.                             |
754| unit  | string | Yes   | Unit to format. The value can be any of the following: **year**, **quarter**, **month**, **week**, **day**, **hour**, **minute**, **second**.|
755
756**Return value**
757
758| Type                 | Description                         |
759| ------------------- | --------------------------- |
760| Array&lt;object&gt; | An array of **RelativeTimeFormat** objects in parts.|
761
762**Example**
763  ```ts
764  // Use locale en to create a RelativeTimeFormat object. Set numeric to auto.
765  let relativetimefmt = new Intl.RelativeTimeFormat("en", {"numeric": "auto"});
766  let parts = relativetimefmt.formatToParts(10, "seconds"); // parts = [ {type: "literal", value: "in"}, {type: "integer", value: 10, unit: "second"}, {type: "literal", value: "seconds"} ]
767  ```
768
769
770### resolvedOptions<sup>8+</sup>
771
772resolvedOptions(): RelativeTimeFormatResolvedOptions
773
774Obtains the formatting options for **RelativeTimeFormat** objects.
775
776**System capability**: SystemCapability.Global.I18n
777
778**Return value**
779
780| Type                                      | Description                               |
781| ---------------------------------------- | --------------------------------- |
782| [RelativeTimeFormatResolvedOptions](#relativetimeformatresolvedoptions8) | Formatting options for **RelativeTimeFormat** objects.|
783
784**Example**
785  ```ts
786  // Use locale en-GB to create a RelativeTimeFormat object.
787  let relativetimefmt= new Intl.RelativeTimeFormat("en-GB", { style: "short" });
788  // Obtain the options of the RelativeTimeFormat object.
789  let options = relativetimefmt.resolvedOptions();
790  let style = options.style; // style = "short"
791  ```
792
793
794## RelativeTimeFormatInputOptions<sup>8+</sup>
795
796Represents the properties of a **RelativeTimeFormat** object.
797Since API version 9, the attributes in **RelativeTimeFormatInputOptions** are optional.
798
799**System capability**: SystemCapability.Global.I18n
800| Name           | Type    | Readable  | Writable  | Description                                      |
801| ------------- | ------ | ---- | ---- | ---------------------------------------- |
802| localeMatcher | string | Yes   | Yes   | Locale matching algorithm. The value can be **lookup** or **best fit**. The default value is **best fit**.|
803| numeric       | string | Yes   | Yes   | Format of the output message. The value can be **always** or **auto**. The default value is **always**.     |
804| style         | string | Yes   | Yes   | Length of an internationalized message. The value can be **long**, **short**, or **narrow**. The default value is **long**.|
805
806
807## RelativeTimeFormatResolvedOptions<sup>8+</sup>
808
809Represents the properties of a **RelativeTimeFormat** object.
810
811**System capability**: SystemCapability.Global.I18n
812
813| Name             | Type    | Readable  | Writable  | Description                                      |
814| --------------- | ------ | ---- | ---- | ---------------------------------------- |
815| locale          | string | Yes   | Yes   | A string containing locale information, including the language, optional script, and region.            |
816| numeric         | string | Yes   | Yes   | Format of the output message. The value can be **always** or **auto**.     |
817| style           | string | Yes   | Yes   | Length of an internationalized message. The value can be **long**, **short**, or **narrow**.|
818| numberingSystem | string | Yes   | Yes   | Numbering system.                                |
819