1# Internationalization – Intl 2 3 This 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. 4 5The [I18N](js-apis-i18n.md) module provides enhanced I18N capabilities through supplementary APIs that are not defined in ECMA 402. It works with the Intl module to provide a complete suite of I18N capabilities. 6 7> **NOTE**<br> 8> 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. 9 10 11## Modules to Import 12 13```js 14import Intl from '@ohos.intl'; 15``` 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**, **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**, **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. | 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 ```js 49 var locale = new Intl.Locale(); 50 ``` 51 52 53### constructor 54 55constructor(locale: string, options?: LocaleOptions) 56 57Creates a Locale object. 58 59**System capability**: SystemCapability.Global.I18n 60 61**Parameters** 62| Name | Type | Mandatory | Description | 63| ------- | ------------- | --------- | ---------------------------------------- | 64| locale | string | Yes | A string containing locale information, including the language, optional script, and region. | 65| options | LocaleOptions | No | Options for creating the **Locale** object. | 66 67**Example** 68 ```js 69 var locale = new Intl.Locale("zh-CN"); 70 ``` 71 72 73### toString 74 75toString(): string 76 77Converts locale information to a string. 78 79**System capability**: SystemCapability.Global.I18n 80 81**Return Value** 82| Type | Description | 83| ------ | ------------------------------------- | 84| string | String containing locale information. | 85 86**Example** 87 ```js 88 var locale = new Intl.Locale("zh-CN"); 89 locale.toString(); 90 ``` 91 92 93### maximize 94 95maximize(): Locale 96 97Maximizes information of the **Locale** object. If the script and locale information is missing, add the information. 98 99**System capability**: SystemCapability.Global.I18n 100 101**Return Value** 102| Type | Description | 103| ----------------- | ---------------------------------------- | 104| [Locale](#locale) | **Locale** object with the maximized information. | 105 106**Example** 107 ```js 108 var locale = new Intl.Locale("zh-CN"); 109 locale.maximize(); 110 ``` 111 112 113### minimize 114 115minimize(): Locale 116 117Minimizes information of the **Locale** object. If the script and locale information is present, delete the information. 118 119**System capability**: SystemCapability.Global.I18n 120 121**Return Value** 122| Type | Description | 123| ----------------- | ---------------------------------------- | 124| [Locale](#locale) | **Locale** object with the minimized information. | 125 126**Example** 127 ```js 128 var locale = new Intl.Locale("zh-CN"); 129 locale.minimize(); 130 ``` 131 132 133## LocaleOptions 134 135Represents the locale options. 136 137**System capability**: SystemCapability.Global.I18n 138 139| Name | Type | Readable | Writable | Description | 140| --------------- | ------- | -------- | -------- | ---------------------------------------- | 141| calendar | string | Yes | Yes | Calendar for the locale. The calue 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**, **islamicc**. | 142| 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**. | 143| hourCycle | string | Yes | Yes | Time system for the locale. The value can be any of the following: **h11**, **h12**, **h23**, **h24**. | 144| 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**. | 145| numeric | boolean | Yes | Yes | Whether to use the 12-hour clock. | 146| caseFirst | string | Yes | Yes | Whether upper case or lower case is sorted first. The value can be **upper**, **lower**, or **false**. | 147 148 149## DateTimeFormat 150 151 152### constructor<sup>8+</sup> 153 154constructor() 155 156Creates a **DateTimeOptions** object for the specified locale. 157 158**System capability**: SystemCapability.Global.I18n 159 160**Example** 161 ```js 162 var datefmt= new Intl.DateTimeFormat(); 163 ``` 164 165 166### constructor 167 168constructor(locale: string | Array<string>, options?: DateTimeOptions) 169 170Creates a **DateTimeOptions** object for the specified locale. 171 172**System capability**: SystemCapability.Global.I18n 173 174**Parameters** 175| Name | Type | Mandatory | Description | 176| ------- | ----------------------------------- | --------- | ---------------------------------------- | 177| locale | string \| Array<string> | Yes | A string containing locale information, including the language, optional script, and region. | 178| options | [DateTimeOptions](#datetimeoptions) | No | Options for creating a **DateTimeFormat** object. | 179 180**Example** 181 ```js 182 var datefmt= new Intl.DateTimeFormat("zh-CN", { dateStyle: 'full', timeStyle: 'medium' }); 183 ``` 184 185 186**Example** 187 ```js 188 var datefmt= new Intl.DateTimeFormat(["ban", "zh"], { dateStyle: 'full', timeStyle: 'medium' }); 189 ``` 190 191 192### format 193 194format(date: Date): string 195 196Formats the specified date and time. 197 198**System capability**: SystemCapability.Global.I18n 199 200**Parameters** 201| Name | Type | Mandatory | Description | 202| ---- | ---- | --------- | ------------------------------ | 203| date | Date | Yes | Date and time to be formatted. | 204 205**Return Value** 206| Type | Description | 207| ------ | ---------------------------------------- | 208| string | A string containing the formatted date and time. | 209 210**Example** 211 ```js 212 var date = new Date(2021, 11, 17, 3, 24, 0); 213 var datefmt = new Intl.DateTimeFormat("en-GB"); 214 datefmt.format(date); 215 ``` 216 217 218### formatRange 219 220formatRange(startDate: Date, endDate: Date): string 221 222Formats the specified date range. 223 224**System capability**: SystemCapability.Global.I18n 225 226**Parameters** 227| Name | Type | Mandatory | Description | 228| --------- | ---- | --------- | ------------------------------------ | 229| startDate | Date | Yes | Start date and time to be formatted. | 230| endDate | Date | Yes | End date and time to be formatted. | 231 232**Return Value** 233| Type | Description | 234| ------ | ---------------------------------------- | 235| string | A string containing the formatted date and time range. | 236 237**Example** 238 ```js 239 var startDate = new Date(2021, 11, 17, 3, 24, 0); 240 var endDate = new Date(2021, 11, 18, 3, 24, 0); 241 var datefmt = new Intl.DateTimeFormat("en-GB"); 242 datefmt.formatRange(startDate, endDate); 243 ``` 244 245 246### resolvedOptions 247 248resolvedOptions(): DateTimeOptions 249 250Obtains the formatting options for **DateTimeFormat** object. 251 252**System capability**: SystemCapability.Global.I18n 253 254**Return Value** 255| Type | Description | 256| ----------------------------------- | ---------------------------------------- | 257| [DateTimeOptions](#datetimeoptions) | Formatting options for **DateTimeFormat** objects. | 258 259**Example** 260 ```js 261 var datefmt = new Intl.DateTimeFormat("en-GB"); 262 datefmt.resolvedOptions(); 263 ``` 264 265 266## DateTimeOptions 267 268Provides the options for the **DateTimeFormat** object. 269 270**System capability**: SystemCapability.Global.I18n 271 272| Name | Type | Readable | Writable | Description | 273| --------------- | ------- | -------- | -------- | ---------------------------------------- | 274| locale | string | Yes | No | Locale, for example, **zh-Hans-CN**. | 275| dateStyle | string | Yes | Yes | Date display format. The value can be **long**, **short**, **medium**, or **full**. | 276| timeStyle | string | Yes | Yes | Time display format. The value can be **long**, **short**, **medium**, or **full**. | 277| hourCycle | string | Yes | Yes | Time system for the locale. The value can be any of the following: **h11**, **h12**, **h23**, **h24**. | 278| timeZone | string | Yes | Yes | Time zone represented by a valid IANA time zone ID. | 279| 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**. | 280| hour12 | boolean | Yes | Yes | Whether to use the 12-hour clock. | 281| weekday | string | Yes | Yes | Workday display format. The value can be **long**, **short**, or **narrow**. | 282| era | string | Yes | Yes | Era display format. The value can be **long**, **short**, or **narrow**. | 283| year | string | Yes | Yes | Year display format. The value can be **numeric** or **2-digit**. | 284| month | string | Yes | Yes | Month display format. The value can be any of the following: **numeric**, **2-digit**, **long**, **short**, **narrow**. | 285| day | string | Yes | Yes | Day display format. The value can be **numeric** or **2-digit**. | 286| hour | string | Yes | Yes | Hour display format. The value can be **numeric** or **2-digit**. | 287| minute | string | Yes | Yes | Minute display format. The value can be **numeric** or **2-digit**. | 288| second | string | Yes | Yes | Seconds display format. The value can be **numeric** or **2-digit**. | 289| timeZoneName | string | Yes | Yes | Localized representation of a time zone name. | 290| dayPeriod | string | Yes | Yes | Time period display format. The value can be **long**, **short**, or **narrow**. | 291| localeMatcher | string | Yes | Yes | Locale matching algorithm. The value can be **lookup** or **best fit**. | 292| formatMatcher | string | Yes | Yes | Format matching algorithm. The value can be **basic** or **best fit**. | 293 294 295## NumberFormat 296 297 298### constructor<sup>8+</sup> 299 300constructor() 301 302Creates a **NumberFormat** object for the specified locale. 303 304**System capability**: SystemCapability.Global.I18n 305 306**Example** 307 ```js 308 var numfmt = new Intl.NumberFormat(); 309 ``` 310 311 312### constructor 313 314constructor(locale: string | Array<string>, options?: NumberOptions) 315 316Creates a **NumberFormat** object for the specified locale. 317 318**System capability**: SystemCapability.Global.I18n 319 320Parameters 321| Name | Type | Mandatory | Description | 322| ------- | ------------------------------- | --------- | ---------------------------------------- | 323| locale | string \| Array<string> | Yes | A string containing locale information, including the language, optional script, and region. | 324| options | [NumberOptions](#numberoptions) | No | Options for creating a **NumberFormat** object. | 325 326**Example** 327 ```js 328 var numfmt = new Intl.NumberFormat("en-GB", {style:'decimal', notation:"scientific"}); 329 ``` 330 331 332### format 333 334format(number: number): string; 335 336Formats a number. 337 338**System capability**: SystemCapability.Global.I18n 339 340**Parameters** 341| Name | Type | Mandatory | Description | 342| ------ | ------ | --------- | ----------------------- | 343| number | number | Yes | Number to be formatted. | 344 345**Return Value** 346| Type | Description | 347| ------ | ----------------- | 348| string | Formatted number. | 349 350 351**Example** 352 ```js 353 var numfmt = new Intl.NumberFormat(["en-GB", "zh"], {style:'decimal', notation:"scientific"}); 354 numfmt.format(1223); 355 ``` 356 357 358### resolvedOptions 359 360resolvedOptions(): NumberOptions 361 362Obtains the options of the **NumberFormat** object. 363 364**System capability**: SystemCapability.Global.I18n 365 366**Return Value** 367| Type | Description | 368| ------------------------------- | ---------------------------------------- | 369| [NumberOptions](#numberoptions) | Formatting options for **NumberFormat** objects. | 370 371 372**Example** 373 ```js 374 var numfmt = new Intl.NumberFormat(["en-GB", "zh"], {style:'decimal', notation:"scientific"}); 375 numfmt.resolvedOptions(); 376 ``` 377 378 379## NumberOptions 380 381Provides the device capability. 382 383**System capability**: SystemCapability.Global.I18n 384 385| Name | Type | Readable | Writable | Description | 386| ------------------------ | ------- | -------- | -------- | ---------------------------------------- | 387| locale | string | Yes | No | Locale, for example, **zh-Hans-CN**. | 388| currency | string | Yes | Yes | Currency unit, for example, **EUR**, **CNY**, or **USD**. | 389| currencySign | string | Yes | Yes | Currency unit symbol. The value can be **symbol**, **narrowSymbol**, **code**, or **name**. | 390| currencyDisplay | string | Yes | Yes | Currency display mode. The value can be **symbol**, **narrowSymbol**, **code**, or **name**. | 391| unit | string | Yes | Yes | Unit name, for example, **meter**, **inch**, or **hectare**. | 392| unitDisplay | string | Yes | Yes | Unit display format. The value can be **long**, **short**, or **medium**. | 393| 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**. | 394| signDisplay | string | Yes | Yes | Number sign display format. The value can be **auto**, **never**, **always**, or **expectZero**. | 395| compactDisplay | string | Yes | Yes | Compact display format. The value can be **long** or **short**. | 396| notation | string | Yes | Yes | Number formatting specification. The value can be **standard**, **scientific**, **engineering**, or **compact**. | 397| localeMatcher | string | Yes | Yes | Locale matching algorithm. The value can be **lookup** or **best fit**. | 398| style | string | Yes | Yes | Number display format. The value can be **decimal**, **currency**, **percent**, or **unit**. | 399| 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**. | 400| useGrouping | boolean | Yes | Yes | Whether to use grouping for display. | 401| minimumIntegerDigits | number | Yes | Yes | Minimum number of digits allowed in the integer part of a number. The value ranges from **1** to **21**. | 402| minimumFractionDigits | number | Yes | Yes | Minimum number of digits in the fraction part of a number. The value ranges from **0** to **20**. | 403| maximumFractionDigits | number | Yes | Yes | Maximum number of digits in the fraction part of a number. The value ranges from **1** to **21**. | 404| minimumSignificantDigits | number | Yes | Yes | Minimum number of the least significant digits. The value ranges from **1** to **21**. | 405| maximumSignificantDigits | number | Yes | Yes | Maximum number of the least significant digits. The value ranges from **1** to **21**. | 406 407 408## Collator<sup>8+</sup> 409 410 411### constructor<sup>8+</sup> 412 413constructor() 414 415Creates a Collator object. 416 417**System capability**: SystemCapability.Global.I18n 418 419**Example** 420 ```js 421 var collator = new Intl.Collator(); 422 ``` 423 424 425### constructor<sup>8+</sup> 426 427constructor(locale: string | Array<string>, options?: CollatorOptions) 428 429Creates a Collator object. 430 431**System capability**: SystemCapability.Global.I18n 432 433**Parameters** 434 435| Name | Type | Mandatory | Description | 436| ------- | ----------------------------------- | --------- | ---------------------------------------- | 437| locale | string \| Array<string> | Yes | A string containing locale information, including the language, optional script, and region. | 438| options | [CollatorOptions](#collatoroptions) | No | Options for creating a **Collator** object. | 439 440**Example** 441 ```js 442 var collator = new Intl.Collator("zh-CN", {localeMatcher: "lookup", usage: "sort"}); 443 ``` 444 445 446### compare<sup>8+</sup> 447 448compare(first: string, second: string): number 449 450Compares two strings based on the sorting policy of the **Collator** object. 451 452**System capability**: SystemCapability.Global.I18n 453 454**Parameters** 455| Name | Type | Mandatory | Description | 456| ------ | ------ | --------- | ------------------------- | 457| first | string | Yes | First string to compare. | 458| second | string | Yes | Second string to compare. | 459 460**Return Value** 461| Type | Description | 462| ------ | ---------------------------------------- | 463| 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. | 464 465**Example** 466 ```js 467 var collator = new Intl.Collator("zh-Hans"); 468 collator.compare("first", "second"); 469 ``` 470 471 472### resolvedOptions<sup>8+</sup> 473 474resolvedOptions(): CollatorOptions 475 476Returns properties reflecting the locale and collation options of a **Collator** object. 477 478**System capability**: SystemCapability.Global.I18n 479 480**Return Value** 481| Type | Description | 482| ----------------------------------- | -------------------------------------- | 483| [CollatorOptions](#collatoroptions) | Properties of the **Collator** object. | 484 485**Example** 486 ```js 487 var collator = new Intl.Collator("zh-Hans"); 488 var options = collator.resolvedOptions(); 489 ``` 490 491 492## CollatorOptions<sup>8+</sup> 493 494Represents the properties of a **Collator** object. 495 496**System capability**: SystemCapability.Global.I18n 497 498| Name | Type | Readable | Writable | Description | 499| ----------------- | ------- | -------- | -------- | ---------------------------------------- | 500| localeMatcher | string | Yes | Yes | Locale matching algorithm. The value can be **lookup** or **best fit**. | 501| usage | string | Yes | Yes | Whether the comparison is for sorting or for searching. The value can be **sort** or **search**. | 502| sensitivity | string | Yes | Yes | Differences in the strings that lead to non-zero return values. The value can be **base**, **accent**, **case**, or **variant**. | 503| ignorePunctuation | boolean | Yes | Yes | Whether punctuation is ignored. The value can be **true** or **false**. | 504| 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**. | 505| numeric | boolean | Yes | Yes | Whether numeric collation is used. The value can be **true** or **false**. | 506| caseFirst | string | Yes | Yes | Whether upper case or lower case is sorted first. The value can be **upper**, **lower**, or **false**. | 507 508 509## PluralRules<sup>8+</sup> 510 511 512### constructor<sup>8+</sup> 513 514constructor() 515 516Create a **PluralRules** object. 517 518**System capability**: SystemCapability.Global.I18n 519 520**Example** 521 ```js 522 var pluralRules = new Intl.PluralRules(); 523 ``` 524 525 526### constructor<sup>8+</sup> 527 528constructor(locale: string | Array<string>, options?: PluralRulesOptions) 529 530Create a **PluralRules** object. 531 532**System capability**: SystemCapability.Global.I18n 533 534Parameters 535| Name | Type | Mandatory | Description | 536| ------- | ---------------------------------------- | --------- | ---------------------------------------- | 537| locale | string \| Array<string> | Yes | A string containing locale information, including the language, optional script, and region. | 538| options | [PluralRulesOptions](#pluralrulesoptions) | No | Options for creating a **PluralRules** object. | 539 540**Example** 541 ```js 542 var pluralRules= new Intl.PluralRules("zh-CN", {"localeMatcher": "lookup", "type": "cardinal"}); 543 ``` 544 545 546### select<sup>8+</sup> 547 548select(n: number): string 549 550Obtains a string that represents the singular-plural type of the specified number. 551 552**System capability**: SystemCapability.Global.I18n 553 554**Parameters** 555| Name | Type | Mandatory | Description | 556| ---- | ------ | --------- | ---------------------------------------- | 557| n | number | Yes | Number for which the singular-plural type is to be obtained. | 558 559**Return Value** 560| Type | Description | 561| ------ | ---------------------------------------- | 562| string | Singular-plural type. The value can be any of the following: **one**, **two**, **few**, **many**, **others**. | 563 564**Example** 565 ```js 566 var pluralRules = new Intl.PluralRules("zh-Hans"); 567 pluralRules.select(1); 568 ``` 569 570 571## PluralRulesOptions<sup>8+</sup> 572 573Represents the properties of a **PluralRules** object. 574 575**System capability**: SystemCapability.Global.I18n 576 577| Name | Type | Readable | Writable | Description | 578| ------------------------ | ------ | -------- | -------- | ---------------------------------------- | 579| localeMatcher | string | Yes | Yes | Locale matching algorithm. The value can be **lookup** or **best fit**. | 580| type | string | Yes | Yes | Sorting type. The value can be **cardinal** or **ordinal**. | 581| minimumIntegerDigits | number | Yes | Yes | Minimum number of digits allowed in the integer part of a number. The value ranges from **1** to **21**. | 582| minimumFractionDigits | number | Yes | Yes | Minimum number of digits in the fraction part of a number. The value ranges from **0** to **20**. | 583| maximumFractionDigits | number | Yes | Yes | Maximum number of digits in the fraction part of a number. The value ranges from **1** to **21**. | 584| minimumSignificantDigits | number | Yes | Yes | Minimum number of the least significant digits. The value ranges from **1** to **21**. | 585| maximumSignificantDigits | number | Yes | Yes | Maximum number of the least significant digits. The value ranges from **1** to **21**. | 586 587 588## RelativeTimeFormat<sup>8+</sup> 589 590 591### constructor<sup>8+</sup> 592 593constructor() 594 595Creates a **RelativeTimeFormat** object. 596 597**System capability**: SystemCapability.Global.I18n 598 599**Example** 600 ```js 601 var relativetimefmt = new Intl.RelativeTimeFormat(); 602 ``` 603 604 605### constructor<sup>8+</sup> 606 607constructor(locale: string | Array<string>, options?: RelativeTimeFormatInputOptions) 608 609Creates a **RelativeTimeFormat** object. 610 611**System capability**: SystemCapability.Global.I18n 612 613Parameters 614| Name | Type | Mandatory | Description | 615| ------- | ---------------------------------------- | --------- | ---------------------------------------- | 616| locale | string \| Array<string> | Yes | A string containing locale information, including the language, optional script, and region. | 617| options | [RelativeTimeFormatInputOptions](#relativetimeformatinputoptions) | No | Options for creating a **RelativeTimeFormat** object. | 618 619**Example** 620 ```js 621 var relativeTimeFormat = new Intl.RelativeTimeFormat("zh-CN", {"localeMatcher": "lookup", "numeric": "always", "style": "long"}); 622 ``` 623 624 625### format<sup>8+</sup> 626 627format(value: number, unit: string): string 628 629Formats the value and unit based on the specified locale and formatting options. 630 631**System capability**: SystemCapability.Global.I18n 632 633**Parameters** 634| Name | Type | Mandatory | Description | 635| ----- | ------ | --------- | ---------------------------------------- | 636| value | number | Yes | Value to format. | 637| unit | string | Yes | Unit to format. The value can be any of the following: **year**, **quarter**, **month**, **week**, **day**, **hour**, **minute**, **second**. | 638 639**Return Value** 640| Type | Description | 641| ------ | ------------------------------- | 642| string | Relative time after formatting. | 643 644**Example** 645 ```js 646 var relativetimefmt = new Intl.RelativeTimeFormat("zh-CN"); 647 relativetimefmt.format(3, "quarter") 648 ``` 649 650 651### formatToParts<sup>8+</sup> 652 653formatToParts(value: number, unit: string): Array<object> 654 655Returns an array of RelativeTimeFormat objects in parts for locale-aware formatting. 656 657**System capability**: SystemCapability.Global.I18n 658 659**Parameters** 660| Name | Type | Mandatory | Description | 661| ----- | ------ | --------- | ---------------------------------------- | 662| value | number | Yes | Value to format. | 663| unit | string | Yes | Unit to format. The value can be any of the following: **year**, **quarter**, **month**, **week**, **day**, **hour**, **minute**, **second**. | 664 665**Return Value** 666| Type | Description | 667| ------------------- | ---------------------------------------- | 668| Array<object> | An array of **RelativeTimeFormat** objects in parts. | 669 670**Example** 671 ```js 672 var relativetimefmt = new Intl.RelativeTimeFormat("en", {"numeric": "auto"}); 673 var parts = relativetimefmt.format(10, "seconds"); 674 ``` 675 676 677### resolvedOptions<sup>8+</sup> 678 679resolvedOptions(): RelativeTimeFormatResolvedOptions 680 681Obtains the formatting options for **RelativeTimeFormat** objects. 682 683**System capability**: SystemCapability.Global.I18n 684 685**Return Value** 686| Type | Description | 687| ---------------------------------------- | ---------------------------------------- | 688| [RelativeTimeFormatResolvedOptions](#relativetimeformatresolvedoptions) | Formatting options for **RelativeTimeFormat** objects. | 689 690**Example** 691 ```js 692 var relativetimefmt= new Intl.RelativeTimeFormat("en-GB"); 693 relativetimefmt.resolvedOptions(); 694 ``` 695 696 697## RelativeTimeFormatInputOptions<sup>8+</sup> 698 699Represents the properties of a **RelativeTimeFormat** object. 700 701**System capability**: SystemCapability.Global.I18n 702 703| Name | Type | Readable | Writable | Description | 704| ------------- | ------ | -------- | -------- | ---------------------------------------- | 705| localeMatcher | string | Yes | Yes | Locale matching algorithm. The value can be **lookup** or **best fit**. | 706| numeric | string | Yes | Yes | Format of the output message. The value can be **always** or **auto**. | 707| style | string | Yes | Yes | Length of an internationalized message. The value can be **long**, **short**, or **narrow**. | 708 709 710## RelativeTimeFormatResolvedOptions<sup>8+</sup> 711 712Represents the properties of a **RelativeTimeFormat** object. 713 714**System capability**: SystemCapability.Global.I18n 715 716| Name | Type | Readable | Writable | Description | 717| --------------- | ------ | -------- | -------- | ---------------------------------------- | 718| locale | string | Yes | Yes | A string containing locale information, including the language, optional script, and region. | 719| numeric | string | Yes | Yes | Format of the output message. The value can be **always** or **auto**. | 720| style | string | Yes | Yes | Length of an internationalized message. The value can be **long**, **short**, or **narrow**. | 721| numberingSystem | string | Yes | Yes | Numbering system. | 722