js-apis-i18n.md 38.8 KB
Newer Older
S
shawn_he 已提交
1
# Internationalization – i18n
Z
zengyawen 已提交
2

S
shawn_he 已提交
3 4 5 6
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
> - The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> 
> - This module contains enhanced i18n APIs, which are not defined in ECMA 402.
Z
zengyawen 已提交
7

S
shawn_he 已提交
8 9

## Modules to Import
Z
zengyawen 已提交
10 11 12 13 14 15

```
import i18n from '@ohos.i18n';
```


S
shawn_he 已提交
16
## i18n.getDisplayLanguage
Z
zengyawen 已提交
17

S
shawn_he 已提交
18
getDisplayLanguage(language: string, locale: string, sentenceCase?: boolean): string
Z
zengyawen 已提交
19 20 21

Obtains the localized script for the specified language.

S
shawn_he 已提交
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
**System capability**: SystemCapability.Global.I18n

- Parameters
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | language | string | Yes| Specified language.|
  | locale | string | Yes| Locale ID.|
  | sentenceCase | boolean | No| Whether to use sentence case for the localized script.|

- Return value
  | Type| Description|
  | -------- | -------- |
  | string | Localized script for the specified language.|

- Example
  ```
  i18n.getDisplayLanguage("zh", "en-GB", true);
  i18n.getDisplayLanguage("zh", "en-GB");
  ```


## i18n.getDisplayCountry

getDisplayCountry(country: string, locale: string, sentenceCase?: boolean): string
Z
zengyawen 已提交
46 47 48

Obtains the localized script for the specified country.

S
shawn_he 已提交
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
**System capability**: SystemCapability.Global.I18n

- Parameters
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | country | string | Yes| Specified country.|
  | locale | string | Yes| Locale ID.|
  | sentenceCase | boolean | No| Whether to use sentence case for the localized script.|

- Return value
  | Type| Description|
  | -------- | -------- |
  | string | Localized script for the specified country.|

- Example
  ```
  i18n.getDisplayCountry("zh-CN", "en-GB", true);
  i18n.getDisplayCountry("zh-CN", "en-GB");
  ```


S
shawn_he 已提交
70
## i18n.isRTL<sup>7+</sup>
S
shawn_he 已提交
71 72

isRTL(locale: string): boolean
Z
zengyawen 已提交
73 74 75

Checks whether the localized script for the specified language is displayed from right to left.

S
shawn_he 已提交
76
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
77

S
shawn_he 已提交
78 79 80 81
- Parameters
  | Name| Type| Description|
  | -------- | -------- | -------- |
  | locale | string | Locale ID.|
Z
zengyawen 已提交
82

S
shawn_he 已提交
83 84 85
- Return value
  | Type| Description|
  | -------- | -------- |
S
shawn_he 已提交
86
  | boolean | Returns **true** if the localized script is displayed from right to left; returns **false** otherwise.|
Z
zengyawen 已提交
87

S
shawn_he 已提交
88 89 90 91 92
- Example
  ```
  i18n.isRTL("zh-CN");// Since Chinese is not written from right to left, false is returned.
  i18n.isRTL("ar-EG");// Since Arabic is written from right to left, true is returned.
  ```
Z
zengyawen 已提交
93 94


S
shawn_he 已提交
95
## i18n.getSystemLanguage
Z
zengyawen 已提交
96

S
shawn_he 已提交
97
getSystemLanguage(): string
Z
zengyawen 已提交
98

S
shawn_he 已提交
99
Obtains the system language.
Z
zengyawen 已提交
100

S
shawn_he 已提交
101 102 103 104 105 106 107 108 109 110 111
**System capability**: SystemCapability.Global.I18n

- Return value
  | Type| Description|
  | -------- | -------- |
  | string | System language ID.|

- Example
  ```
  i18n.getSystemLanguage();
  ```
Z
zengyawen 已提交
112 113


S
shawn_he 已提交
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180
## i18n.setSystemLanguage

setSystemLanguage(language: string): boolean

Sets the system language.

**System capability**: SystemCapability.Global.I18n

- Parameters
  | Name| Type| Description|
  | -------- | -------- | -------- |
  | language | string | Language ID.|

- Return value
  | Type| Description|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

- Example
  ```
  i18n.setSystemLanguage('zh');
  ```


## i18n.getSystemLanguages

getSystemLanguages(): Array<string>

Obtains the list of system languages.

**System capability**: SystemCapability.Global.I18n

- Return value
  | Type| Description|
  | -------- | -------- |
  | Array<string> | List of the IDs of system languages.|

- Example
  ```
  i18n.getSystemLanguages();
  ```


## i18n.getSystemCountries

getSystemCountries(language: string): Array<string>

Obtains the list of countries and regions supported for the specified language.

**System capability**: SystemCapability.Global.I18n

- Parameters
  | Name| Type| Description|
  | -------- | -------- | -------- |
  | language | string | Language ID.|

- Return value
  | Type| Description|
  | -------- | -------- |
  | Array<string> | List of the IDs of the countries and regions supported for the specified language.|

- Example
  ```
  i18n.getSystemCountries('zh');
  ```


S
shawn_he 已提交
181
## i18n.getSystemRegion
Z
zengyawen 已提交
182

S
shawn_he 已提交
183
getSystemRegion(): string
Z
zengyawen 已提交
184

S
shawn_he 已提交
185 186 187 188 189 190 191 192
Obtains the system region.

**System capability**: SystemCapability.Global.I18n

- Return value
  | Type| Description|
  | -------- | -------- |
  | string | System region ID.|
Z
zengyawen 已提交
193

S
shawn_he 已提交
194 195 196 197
- Example
  ```
  i18n.getSystemRegion();
  ```
Z
zengyawen 已提交
198 199


S
shawn_he 已提交
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
## i18n.setSystemRegion

setSystemRegion(region: string): boolean

Sets the system region.

**System capability**: SystemCapability.Global.I18n

- Parameters
  | Name| Type| Description|
  | -------- | -------- | -------- |
  | region | string | Region ID.|

- Return value
  | Type| Description|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

- Example
  ```
  i18n.setSystemRegion();
  ```


S
shawn_he 已提交
224
## i18n.getSystemLocale
Z
zengyawen 已提交
225

S
shawn_he 已提交
226
getSystemLocale(): string
Z
zengyawen 已提交
227 228 229

Obtains the system locale.

S
shawn_he 已提交
230
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
231

S
shawn_he 已提交
232 233 234 235
- Return value
  | Type| Description|
  | -------- | -------- |
  | string | System locale ID.|
Z
zengyawen 已提交
236

S
shawn_he 已提交
237 238 239 240
- Example
  ```
  i18n.getSystemLocale();
  ```
Z
zengyawen 已提交
241 242


S
shawn_he 已提交
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
## i18n.setSystemLocale

setSystemLocale(locale: string): boolean

Sets the system locale.

**System capability**: SystemCapability.Global.I18n

- Parameters
  | Name| Type| Description|
  | -------- | -------- | -------- |
  | locale | string | System locale ID, for example, **zh-CN**.|

- Return value
  | Type| Description|
  | -------- | -------- |
  | boolean | Returns **true** if the operation is successful; returns **false** otherwise.|

- Example
  ```
  i18n.setSystemLocale('zh-CN');
  ```


## i18n.isSuggested

isSuggested(language: string, region?: string): boolean

Checks whether the system language matches the specified region.

**System capability**: SystemCapability.Global.I18n

- Parameters
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | language | string | Yes| Valid language ID, for example, **zh**.|
  | region | string | No| Valid region ID, for example, **CN**.|

- Return value
  | Type| Description|
  | -------- | -------- |
  | boolean | Returns **true** if the system language matches the specified region; returns **false** otherwise.|

- Example
  ```
  i18n.isSuggested('zh', 'CN');
  ```


S
shawn_he 已提交
292
## i18n.getCalendar<sup>8+</sup>
Z
zengyawen 已提交
293

S
shawn_he 已提交
294
getCalendar(locale: string, type? : string): Calendar
Z
zengyawen 已提交
295

S
shawn_he 已提交
296
Obtains a **Calendar** object.
Z
zengyawen 已提交
297

S
shawn_he 已提交
298
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
299

S
shawn_he 已提交
300 301 302 303
- Parameters
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | locale | string | Yes| Valid locale value, for example, **zh-Hans-CN**.|
S
shawn_he 已提交
304
  | type | string | No| Valid calendar type. Currently, the valid types are as follows: **buddhist**, **chinese**, **coptic**, **ethiopic**, **hebrew**, **gregory**, **indian**, **islamic\_civil**, **islamic\_tbla**, **islamic\_umalqura**, **japanese**, and **persian**. If this parameter is left unspecified, the default calendar type of the specified locale is used.|
S
shawn_he 已提交
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437

- Return value
  | Type| Description|
  | -------- | -------- |
  | [Calendar](#calendar8) | **Calendar** object.|

- Example
  ```
  i18n.getCalendar("zh-Hans", "gregory");
  ```


## Calendar<sup>8+</sup>


### setTime<sup>8+</sup>

setTime(date: Date): void

Sets the date for this **Calendar** object.

**System capability**: SystemCapability.Global.I18n

- Parameters
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | date | Date | Yes| Date to be set for the **Calendar** object.|

- Example
  ```
  var calendar = I18n.getCalendar("en-US", "gregory");
  var date = new Date(2021, 10, 7, 8, 0, 0, 0);
  calendar.setTime(date);
  ```


### setTime<sup>8+</sup>

setTime(time: number): void

Sets the date and time for this **Calendar** object. The value is represented by the number of milliseconds that have elapsed since the Unix epoch (00:00:00 UTC on January 1, 1970).

**System capability**: SystemCapability.Global.I18n

- Parameters
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | time | number | Yes| Number of milliseconds that have elapsed since the Unix epoch.|

- Example
  ```
  var calendar = I18n.getCalendar("en-US", "gregory");
  calendar.setTime(10540800000);
  ```


### set<sup>8+</sup>

set(year: number, month: number, date:number, hour?: number, minute?: number, second?: number): void

Sets the year, month, day, hour, minute, and second for this **Calendar** object.

**System capability**: SystemCapability.Global.I18n

- Parameters
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | year | number | Yes| Year to set.|
  | month | number | Yes| Month to set.|
  | date | number | Yes| Day to set.|
  | hour | number | No| Hour to set.|
  | minute | number | No| Minute to set.|
  | second | number | No| Second to set.|

- Example
  ```
  var calendar = i18n.getCalendar("zh-Hans");
  calendar.setTime(2021, 10, 1, 8, 0, 0); // set time to 2021.10.1 08:00:00
  ```


### setTimeZone<sup>8+</sup>

setTimeZone(timezone: string): void

Sets the time zone of this **Calendar** object.

**System capability**: SystemCapability.Global.I18n

- Parameters
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | timezone | string | Yes| Time zone, for example, **Asia/Shanghai**.|

- Example
  ```
  var calendar = i18n.getCalendar("zh-Hans");
  calendar.setTimeZone("Asia/Shanghai");
  ```


### getTimeZone<sup>8+</sup>

getTimeZone(): string

Obtains the time zone of this **Calendar** object.

**System capability**: SystemCapability.Global.I18n

- Return value
  | Type| Description|
  | -------- | -------- |
  | string | Time zone of the **Calendar** object.|

- Example
  ```
  var calendar = i18n.getCalendar("zh-Hans");
  calendar.setTimeZone("Asia/Shanghai");
  calendar.getTimeZone(); // Asia/Shanghai"
  ```


### getFirstDayOfWeek<sup>8+</sup>

getFirstDayOfWeek(): number

Obtains the start day of a week for this **Calendar** object.

**System capability**: SystemCapability.Global.I18n

- Return value
  | Type| Description|
  | -------- | -------- |
S
shawn_he 已提交
438
  | number | Start day of a week. The value **1** indicates Sunday, and the value **7** indicates Saturday.|
S
shawn_he 已提交
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457

- Example
  ```
  var calendar = I18n.getCalendar("en-US", "gregory");
  calendar.getFirstDayOfWeek();
  ```


### setFirstDayOfWeek<sup>8+</sup>

setFirstDayOfWeek(value: number): void

Sets the start day of a week for this **Calendar** object.

**System capability**: SystemCapability.Global.I18n

- Parameters
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
458
  | value | number | No| Start day of a week. The value **1** indicates Sunday, and the value **7** indicates Saturday.|
Z
zengyawen 已提交
459

S
shawn_he 已提交
460 461 462 463 464
- Example
  ```
  var calendar = i18n.getCalendar("zh-Hans");
  calendar.setFirstDayOfWeek(0);
  ```
Z
zengyawen 已提交
465 466


S
shawn_he 已提交
467
### getMinimalDaysInFirstWeek<sup>8+</sup>
Z
zengyawen 已提交
468

S
shawn_he 已提交
469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484
getMinimalDaysInFirstWeek(): number

Obtains the minimum number of days in the first week of a year.

**System capability**: SystemCapability.Global.I18n

- Return value
  | Type| Description|
  | -------- | -------- |
  | number | Minimum number of days in the first week of a year.|

- Example
  ```
  var calendar = i18n.getCalendar("zh-Hans");
  calendar.getMinimalDaysInFirstWeek();
  ```
Z
zengyawen 已提交
485 486


S
shawn_he 已提交
487
### setMinimalDaysInFirstWeek<sup>8+</sup>
Z
zengyawen 已提交
488

S
shawn_he 已提交
489
setMinimalDaysInFirstWeek(value: number): void
Z
zengyawen 已提交
490 491 492

Sets the minimum number of days in the first week of a year.

S
shawn_he 已提交
493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517
**System capability**: SystemCapability.Global.I18n

- Parameters
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | value | number | No| Minimum number of days in the first week of a year.|

- Example
  ```
  var calendar = i18n.getCalendar("zh-Hans");
  calendar.setMinimalDaysInFirstWeek(3);
  ```


### get<sup>8+</sup>

get(field: string): number

Obtains the value of the specified field in the **Calendar** object.

**System capability**: SystemCapability.Global.I18n

- Parameters
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
518
  | field | string | Yes| Value of the specified field in the **Calendar** object. Currently, a valid field can be any of the following: **era**, **year**, **month**, **week\_of\_year**, **week\_of\_month**, **date**, **day\_of\_year**, **day\_of\_week**, **day\_of\_week\_in\_month**, **hour**, **hour\_of\_day**, **minute**, **second**, **millisecond**, **zone\_offset**, **dst\_offset**, **year\_woy**, **dow\_local**, **extended\_year**, **julian\_day**, **milliseconds\_in\_day**, **is\_leap\_month**.|
S
shawn_he 已提交
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573

- Return value
  | Type| Description|
  | -------- | -------- |
  | number | Value of the specified field. For example, if the year in the internal date of this **Calendar** object is **1990**, the **get("year")** function will return **1990**.|

- Example
  ```
  var calendar = i18n.getCalendar("zh-Hans");
  calendar.setTime(2021, 10, 1, 8, 0, 0); // set time to 2021.10.1 08:00:00
  calendar.get("hour_of_day"); // 8
  ```


### getDisplayName<sup>8+</sup>

getDisplayName(locale: string): string

Obtains the name of the **Calendar** object displayed for the specified locale.

**System capability**: SystemCapability.Global.I18n

- Parameters
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | locale | string | Yes| Locale for which the name of the **Calendar** object is displayed. For example, if **locale** is **en-US**, the name of the Buddhist calendar will be **Buddhist Calendar**.|

- Return value
  | Type| Description|
  | -------- | -------- |
  | string | Name of the **Calendar** object displayed for the specified locale.|

- Example
  ```
  var calendar = i18n.getCalendar("en-US", "buddhist");
  calendar.getDisplayName("zh"); // Obtain the name of the Buddhist calendar in zh.
  ```


### isWeekend<sup>8+</sup>

isWeekend(date?: Date): boolean

Checks whether the specified date in this **Calendar** object is a weekend.

**System capability**: SystemCapability.Global.I18n

- Parameters
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | date | Date | No| Specified date in this **Calendar** object. If this parameter is left unspecified, the system checks whether the current date in the **Calendar** object is a weekend.|

- Return value
  | Type| Description|
  | -------- | -------- |
S
shawn_he 已提交
574
  | boolean | Returns **true** if the date is a weekend; returns **false** if the date is a weekday.|
S
shawn_he 已提交
575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595

- Example
  ```
  var calendar = i18n.getCalendar("zh-Hans");
  calendar.setTime(2021, 11, 11, 8, 0, 0); // set time to 2021.11.11 08:00:00
  calendar.isWeekend(); // false
  var date = new Date(2011, 11, 6, 9, 0, 0);
  calendar.isWeekend(date); // true
  ```


## PhoneNumberFormat<sup>8+</sup>


### constructor<sup>8+</sup>

constructor(country: string, options?: PhoneNumberFormatOptions)

Creates a **PhoneNumberFormat** object.

**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
596 597

Parameters
S
shawn_he 已提交
598 599 600 601
| Name| Type| Mandatory| Description|
| -------- | -------- | -------- | -------- |
| country | string | Yes| Country or region to which the phone number to be formatted belongs.|
| options | [PhoneNumberFormatOptions](#phonenumberformatoptions8) | No| Options of the **PhoneNumberFormat** object.|
Z
zengyawen 已提交
602

S
shawn_he 已提交
603 604 605 606 607 608 609 610 611
- Example
  ```
  var phoneNumberFormat= new i18n.PhoneNumberFormat("CN", {"type": "E164"});
  ```


### isValidNumber<sup>8+</sup>

isValidNumber(number: string): boolean
Z
zengyawen 已提交
612 613 614

Checks whether the format of the specified phone number is valid.

S
shawn_he 已提交
615 616 617 618 619 620 621 622 623 624
**System capability**: SystemCapability.Global.I18n

- Parameters
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | number | string | Yes| Phone number to be checked.|

- Return value
  | Type| Description|
  | -------- | -------- |
S
shawn_he 已提交
625
  | boolean | Returns **true** if the phone number format is valid; returns **false** otherwise.|
S
shawn_he 已提交
626 627 628 629 630 631 632 633 634 635 636

- Example
  ```
  var phonenumberfmt = new i18n.PhoneNumberFormat("CN");
  phonenumberfmt.isValidNumber("15812312312");
  ```


### format<sup>8+</sup>

format(number: string): string
Z
zengyawen 已提交
637 638 639

Formats a phone number.

S
shawn_he 已提交
640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662
**System capability**: SystemCapability.Global.I18n

- Parameters
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | number | string | Yes| Phone number to be formatted.|

- Return value
  | Type| Description|
  | -------- | -------- |
  | string | Formatted phone number.|

- Example
  ```
  var phonenumberfmt = new i18n.PhoneNumberFormat("CN");
  phonenumberfmt.format("15812312312");
  ```


## PhoneNumberFormatOptions<sup>8+</sup>

Defines the options for this PhoneNumberFormat object.

S
shawn_he 已提交
663
**System capability**: SystemCapability.Global.I18n
S
shawn_he 已提交
664 665 666

| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
667
| type | string | Yes| Yes| Format type of a phone number. The value can be **E164**, **INTERNATIONAL**, **NATIONAL**, or **RFC3966**.|
S
shawn_he 已提交
668 669 670


## UnitInfo<sup>8+</sup>
Z
zengyawen 已提交
671 672 673

Defines the measurement unit information.

S
shawn_he 已提交
674
**System capability**: SystemCapability.Global.I18n
S
shawn_he 已提交
675 676 677 678

| Name| Type| Readable| Writable| Description|
| -------- | -------- | -------- | -------- | -------- |
| unit | string | Yes| Yes| Name of the measurement unit, for example, **meter**, **inch**, or **cup**.|
S
shawn_he 已提交
679
| measureSystem | string | Yes| Yes| Measurement system. The value can be **SI**, **US**, or **UK**.|
S
shawn_he 已提交
680 681 682 683 684 685 686 687


## Util<sup>8+</sup>


### unitConvert<sup>8+</sup>

unitConvert(fromUnit: UnitInfo, toUnit: UnitInfo, value: number, locale: string, style?: string): string
Z
zengyawen 已提交
688 689 690

Converts one measurement unit into another and formats the unit based on the specified locale and style.

S
shawn_he 已提交
691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712
**System capability**: SystemCapability.Global.I18n

- Parameters
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | fromUnit | [UnitInfo](#unitinfo8) | Yes| Measurement unit to be converted.|
  | toUnit | [UnitInfo](#unitinfo8) | Yes| Measurement unit to be converted to.|
  | value | number | Yes| Value of the measurement unit to be converted.|
  | locale | string | Yes| Locale used for formatting, for example, **zh-Hans-CN**.|
  | style | string | No| Style used for formatting. The value can be **long**, **short**, or **medium**.|

- Return value
  | Type| Description|
  | -------- | -------- |
  | string | Character string obtained after formatting based on the measurement unit specified by **toUnit**.|

- Example
  ```
  I18n.Util.unitConvert({unit: "cup", measureSystem: "US"}, {unit: "liter", measureSystem: "SI"}, 1000, "en-US", "long");
  ```


S
shawn_he 已提交
713
## getInstance<sup>8+</sup>
S
shawn_he 已提交
714

S
shawn_he 已提交
715
getInstance(locale?:string): IndexUtil
S
shawn_he 已提交
716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736

Creates an **IndexUtil** object.

**System capability**: SystemCapability.Global.I18n

- Parameters
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | locale | string | No| A string containing locale information, including the language, optional script, and region.|

- Return value
  | Type| Description|
  | -------- | -------- |
  | [IndexUtil](#indexutil8) | **IndexUtil** object mapping to the specified locale.|

- Example
  ```
  var indexUtil= i18n.IndexUtil.getInstance("zh-CN");
  ```


S
shawn_he 已提交
737 738 739
## IndexUtil<sup>8+</sup>


S
shawn_he 已提交
740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761
### getIndexList<sup>8+</sup>

getIndexList(): Array&lt;string&gt;

Obtains the index list for this **locale** object.

**System capability**: SystemCapability.Global.I18n

- Return value
  | Type| Description|
  | -------- | -------- |
  | Array&lt;string&gt; | Index list for this **locale** object.|

- Example
  ```
  var indexUtil = i18n.getInstance("zh-CN");
  var indexList = indexUtil.getIndexList();
  ```


### addLocale<sup>8+</sup>

S
shawn_he 已提交
762
addLocale(locale: string): void
S
shawn_he 已提交
763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823

Adds the index of the new **locale** object to the index list.

**System capability**: SystemCapability.Global.I18n

- Parameters
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | locale | string | Yes| A string containing locale information, including the language, optional script, and region.|

- Example
  ```
  var indexUtil = i18n.getInstance("zh-CN");
  indexUtil.addLocale("en-US");
  ```


### getIndex<sup>8+</sup>

getIndex(text: string): string

Obtains the index of a text object.

**System capability**: SystemCapability.Global.I18n

- Parameters
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | text | string | Yes| **text** object whose index is to be obtained.|

- Return value
  | Type| Description|
  | -------- | -------- |
  | string | Index of the **text** object.|

- Example
  ```
  var indexUtil= i18n.getInstance("zh-CN");
  indexUtil.getIndex("hi"); // Return h.
  ```


## Character<sup>8+</sup>


### isDigit<sup>8+</sup>

isDigit(char: string): boolean

Checks whether the input character string is composed of digits.

**System capability**: SystemCapability.Global.I18n

- Parameters
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | char | string | Yes| Input character.|

- Return value
  | Type| Description|
  | -------- | -------- |
S
shawn_he 已提交
824
  | boolean | Returns **true** if the input character is a digit; returns **false** otherwise.|
S
shawn_he 已提交
825 826 827 828 829 830 831 832 833 834

- Example
  ```
  var isdigit = Character.isDigit("1"); // Return true.
  ```


### isSpaceChar<sup>8+</sup>

isSpaceChar(char: string): boolean
Z
zengyawen 已提交
835

Z
zengyawen 已提交
836
Checks whether the input character is a space.
Z
zengyawen 已提交
837

S
shawn_he 已提交
838 839 840 841 842 843 844 845 846 847
**System capability**: SystemCapability.Global.I18n

- Parameters
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | char | string | Yes| Input character.|

- Return value
  | Type| Description|
  | -------- | -------- |
S
shawn_he 已提交
848
  | boolean | Returns **true** if the input character is a space; returns **false** otherwise.|
S
shawn_he 已提交
849 850 851 852 853 854 855 856 857 858

- Example
  ```
  var isspacechar = Character.isSpaceChar("a"); // Return false.
  ```


### isWhitespace<sup>8+</sup>

isWhitespace(char: string): boolean
Z
zengyawen 已提交
859

Z
zengyawen 已提交
860
Checks whether the input character is a white space.
Z
zengyawen 已提交
861

S
shawn_he 已提交
862 863 864 865 866 867 868 869 870 871
**System capability**: SystemCapability.Global.I18n

- Parameters
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | char | string | Yes| Input character.|

- Return value
  | Type| Description|
  | -------- | -------- |
S
shawn_he 已提交
872
  | boolean | Returns **true** if the input character is a white space; returns **false** otherwise.|
S
shawn_he 已提交
873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895

- Example
  ```
  var iswhitespace = Character.isWhitespace("a"); // Return false.
  ```


### isRTL<sup>8+</sup>

isRTL(char: string): boolean

Checks whether the input character is of the right to left (RTL) language.

**System capability**: SystemCapability.Global.I18n

- Parameters
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | char | string | Yes| Input character.|

- Return value
  | Type| Description|
  | -------- | -------- |
S
shawn_he 已提交
896
  | boolean | Returns **true** if the input character is of the RTL language; returns **false** otherwise.|
S
shawn_he 已提交
897 898 899 900 901 902 903 904 905 906

- Example
  ```
  var isrtl = Character.isRTL("a"); // Return false.
  ```


### isIdeograph<sup>8+</sup>

isIdeograph(char: string): boolean
Z
zengyawen 已提交
907

Z
zengyawen 已提交
908
Checks whether the input character is an ideographic character.
Z
zengyawen 已提交
909

S
shawn_he 已提交
910 911 912 913 914 915 916 917 918 919
**System capability**: SystemCapability.Global.I18n

- Parameters
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | char | string | Yes| Input character.|

- Return value
  | Type| Description|
  | -------- | -------- |
S
shawn_he 已提交
920
  | boolean | Returns **true** if the input character is an ideographic character; returns **false** otherwise.|
S
shawn_he 已提交
921 922 923 924 925 926 927 928 929 930

- Example
  ```
  var isideograph = Character.isIdeograph("a"); // Return false.
  ```


### isLetter<sup>8+</sup>

isLetter(char: string): boolean
Z
zengyawen 已提交
931

Z
zengyawen 已提交
932
Checks whether the input character is a letter.
Z
zengyawen 已提交
933

S
shawn_he 已提交
934 935 936 937 938 939 940 941 942 943
**System capability**: SystemCapability.Global.I18n

- Parameters
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | char | string | Yes| Input character.|

- Return value
  | Type| Description|
  | -------- | -------- |
S
shawn_he 已提交
944
  | boolean | Returns **true** if the input character is a letter; returns **false** otherwise.|
S
shawn_he 已提交
945 946 947 948 949 950 951 952 953 954

- Example
  ```
  var isletter = Character.isLetter("a"); // Return true.
  ```


### isLowerCase<sup>8+</sup>

isLowerCase(char: string): boolean
Z
zengyawen 已提交
955

Z
zengyawen 已提交
956
Checks whether the input character is a lowercase letter.
Z
zengyawen 已提交
957

S
shawn_he 已提交
958 959 960 961 962 963 964 965 966 967
**System capability**: SystemCapability.Global.I18n

- Parameters
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | char | string | Yes| Input character.|

- Return value
  | Type| Description|
  | -------- | -------- |
S
shawn_he 已提交
968
  | boolean | Returns **true** if the input character is a lowercase letter; returns **false** otherwise.|
S
shawn_he 已提交
969 970 971 972 973 974 975 976 977 978

- Example
  ```
  var islowercase = Character.isLowerCase("a"); // Return true.
  ```


### isUpperCase<sup>8+</sup>

isUpperCase(char: string): boolean
Z
zengyawen 已提交
979

Z
zengyawen 已提交
980
Checks whether the input character is an uppercase letter.
Z
zengyawen 已提交
981

S
shawn_he 已提交
982 983 984 985 986 987 988 989 990 991
**System capability**: SystemCapability.Global.I18n

- Parameters
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | char | string | Yes| Input character.|

- Return value
  | Type| Description|
  | -------- | -------- |
S
shawn_he 已提交
992
  | boolean | Returns **true** if the input character is an uppercase letter; returns **false** otherwise.|
S
shawn_he 已提交
993 994 995 996 997 998 999 1000 1001 1002

- Example
  ```
  var isuppercase = Character.isUpperCase("a"); // Return false.
  ```


### getType<sup>8+</sup>

getType(char: string): string
Z
zengyawen 已提交
1003 1004 1005

Obtains the type of the input character string.

S
shawn_he 已提交
1006
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1007

S
shawn_he 已提交
1008 1009 1010 1011
- Parameters
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | char | string | Yes| Input character.|
Z
zengyawen 已提交
1012

S
shawn_he 已提交
1013 1014 1015 1016
- Return value
  | Type| Description|
  | -------- | -------- |
  | string | Type of the input character.|
Z
zengyawen 已提交
1017

S
shawn_he 已提交
1018 1019 1020 1021
- Example
  ```
  var type = Character.getType("a");
  ```
Z
zengyawen 已提交
1022 1023


S
shawn_he 已提交
1024
## i18n.getLineInstance<sup>8+</sup>
Z
zengyawen 已提交
1025

S
shawn_he 已提交
1026
getLineInstance(locale: string): BreakIterator
Z
zengyawen 已提交
1027

S
shawn_he 已提交
1028
Obtains a [BreakIterator](#breakiterator8) object for text segmentation.
Z
zengyawen 已提交
1029

S
shawn_he 已提交
1030
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1031

S
shawn_he 已提交
1032 1033 1034 1035
- Parameters
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | locale | string | Yes| Valid locale value, for example, **zh-Hans-CN**. The [BreakIterator](#breakiterator8) object segments text according to the rules of the specified locale.|
Z
zengyawen 已提交
1036

S
shawn_he 已提交
1037 1038 1039 1040
- Return value
  | Type| Description|
  | -------- | -------- |
  | [BreakIterator](#breakiterator8) | [BreakIterator](#breakiterator8) object used for text segmentation.|
Z
zengyawen 已提交
1041

S
shawn_he 已提交
1042 1043 1044 1045
- Example
  ```
  i18n.getLineInstance("en");
  ```
Z
zengyawen 已提交
1046 1047


S
shawn_he 已提交
1048
## BreakIterator<sup>8+</sup>
Z
zengyawen 已提交
1049 1050


S
shawn_he 已提交
1051
### setLineBreakText<sup>8+</sup>
Z
zengyawen 已提交
1052

S
shawn_he 已提交
1053
setLineBreakText(text: string): void
Z
zengyawen 已提交
1054

S
shawn_he 已提交
1055
Sets the text to be processed by the [BreakIterator](#breakiterator8) object.
Z
zengyawen 已提交
1056

S
shawn_he 已提交
1057
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1058

S
shawn_he 已提交
1059 1060 1061 1062
- Parameters
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | text | string | Yes| Text to be processed by the **BreakIterator** object.|
Z
zengyawen 已提交
1063

S
shawn_he 已提交
1064 1065 1066 1067 1068
- Example
  ```
  iterator = I18n.getLineInstance("en");
  iterator.setLineBreakText("Apple is my favorite fruit.");
  ```
Z
zengyawen 已提交
1069 1070


S
shawn_he 已提交
1071
### getLineBreakText<sup>8+</sup>
Z
zengyawen 已提交
1072

S
shawn_he 已提交
1073
getLineBreakText(): string
Z
zengyawen 已提交
1074

S
shawn_he 已提交
1075
Obtains the text being processed by the [BreakIterator](#breakiterator8) object.
Z
zengyawen 已提交
1076

S
shawn_he 已提交
1077
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1078

S
shawn_he 已提交
1079 1080 1081 1082
- Return value
  | Type| Description|
  | -------- | -------- |
  | string | Text being processed by the **BreakIterator** object.|
Z
zengyawen 已提交
1083

S
shawn_he 已提交
1084 1085 1086 1087 1088 1089
- Example
  ```
  iterator = I18n.getLineInstance("en");
  iterator.setLineBreakText("Apple is my favorite fruit.");
  iterator.getLineBreakText(); // Apple is my favorite fruit.
  ```
Z
zengyawen 已提交
1090 1091


S
shawn_he 已提交
1092
### current<sup>8+</sup>
Z
zengyawen 已提交
1093

S
shawn_he 已提交
1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194
current(): number

Obtains the position of the [BreakIterator](#breakiterator8) object in the text being processed.

**System capability**: SystemCapability.Global.I18n

- Return value
  | Type| Description|
  | -------- | -------- |
  | number | Position of the **BreakIterator** object in the text being processed.|

- Example
  ```
  iterator = I18n.getLineInstance("en");
  iterator.setLineBreakText("Apple is my favorite fruit.");
  breakIter.current(); // 0
  ```


### first<sup>8+</sup>

first(): number

Puts the [BreakIterator](#breakiterator8) object to the first text boundary, which is always at the beginning of the processed text.

**System capability**: SystemCapability.Global.I18n

- Return value
  | Type| Description|
  | -------- | -------- |
  | number | Offset to the first text boundary of the processed text.|

- Example
  ```
  iterator = I18n.getLineInstance("en");
  iterator.setLineBreakText("Apple is my favorite fruit.");
  breakIter.first(); // 0
  ```


### last<sup>8+</sup>

last(): number

Puts the [BreakIterator](#breakiterator8) object to the last text boundary, which is always the next position after the end of the processed text.

**System capability**: SystemCapability.Global.I18n

- Return value
  | Type| Description|
  | -------- | -------- |
  | number | Offset of the last text boundary of the processed text.|

- Example
  ```
  iterator = I18n.getLineInstance("en");
  iterator.setLineBreakText("Apple is my favorite fruit.");
  iterator.last(); // 27
  ```


### next<sup>8+</sup>

next(index?: number): number

Moves the [BreakIterator](#breakiterator8) object backward by the specified number of text boundaries if the specified index is a positive number. If the index is a negative number, the [BreakIterator](#breakiterator8) object will be moved forward by the corresponding number of text boundaries. If no index is specified, the index will be treated as **1**.

**System capability**: SystemCapability.Global.I18n

- Parameters
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | index | number | No| Number of text boundaries by which the [BreakIterator](#breakiterator8) object is moved. A positive value indicates that the text boundary is moved backward, and a negative value indicates the opposite. If no index is specified, the index will be treated as **1**.|

- Return value
  | Type| Description|
  | -------- | -------- |
  | number | Position of the [BreakIterator](#breakiterator8) object in the text after it is moved by the specified number of text boundaries. The value **-1** is returned if the position of the [BreakIterator](#breakiterator8) object is outside of the processed text after it is moved by the specified number of text boundaries.|

- Example
  ```
  iterator = I18n.getLineInstance("en");
  iterator.setLineBreakText("Apple is my favorite fruit.");
  iterator.first(); // 0
  iterator.next(); // 6
  iterator.next(10); // -1
  ```


### previous<sup>8+</sup>

previous(): number

Moves the [BreakIterator](#breakiterator8) object to the previous text boundary.

**System capability**: SystemCapability.Global.I18n

- Return value
  | Type| Description|
  | -------- | -------- |
  | number | Position of the [BreakIterator](#breakiterator8) object in the text after it is moved to the previous text boundary. The value **-1** is returned if the position of the [BreakIterator](#breakiterator8) object is outside of the processed text after it is moved by the specified number of text boundaries.|
Z
zengyawen 已提交
1195

S
shawn_he 已提交
1196 1197 1198 1199 1200 1201 1202 1203
- Example
  ```
  iterator = I18n.getLineInstance("en");
  iterator.setLineBreakText("Apple is my favorite fruit.");
  iterator.first(); // 0
  iterator.next(3); // 12
  iterator.previous(); // 9
  ```
Z
zengyawen 已提交
1204 1205


S
shawn_he 已提交
1206
### following<sup>8+</sup>
Z
zengyawen 已提交
1207

S
shawn_he 已提交
1208
following(offset: number): number
Z
zengyawen 已提交
1209

S
shawn_he 已提交
1210
Moves the [BreakIterator](#breakiterator8) object to the text boundary after the position specified by the offset. Position of the [BreakIterator](#breakiterator8) object after it is moved to the text boundary after the position specified by the offset.
Z
zengyawen 已提交
1211

S
shawn_he 已提交
1212
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1213

S
shawn_he 已提交
1214 1215 1216 1217
- Parameters
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | offset | number | Yes| Offset to the position before the text boundary to which the [BreakIterator](#breakiterator8) object is moved.|
Z
zengyawen 已提交
1218

S
shawn_he 已提交
1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249
- Return value
  | Type| Description|
  | -------- | -------- |
  | number | The value **-1** is returned if the text boundary to which the [BreakIterator](#breakiterator8) object is moved is outside of the processed text.|

- Example
  ```
  iterator = I18n.getLineInstance("en");
  iterator.setLineBreakText("Apple is my favorite fruit.");
  iterator.following(0); // 6
  iterator.following(100); // -1
  iterator.current(); // 27
  ```


### isBoundary<sup>8+</sup>

isBoundary(offset: number): boolean

Checks whether the position specified by the offset is a text boundary. If **true** is returned, the [BreakIterator](#breakiterator8) object is moved to the position specified by the offset. If **false** is returned, the [BreakIterator](#breakiterator8) object is moved to the text boundary after the position specified by the offset, which is equivalent to calling [following](#following8)(offset).

**System capability**: SystemCapability.Global.I18n

- Parameters
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | offset | number | Yes| Position to check.|

- Return value
  | Type| Description|
  | -------- | -------- |
S
shawn_he 已提交
1250
  | boolean | Returns **true** if the position specified by the offset is a text boundary; returns **false** otherwise.|
S
shawn_he 已提交
1251 1252 1253 1254 1255 1256 1257 1258 1259 1260

- Example
  ```
  iterator = I18n.getLineInstance("en");
  iterator.setLineBreakText("Apple is my favorite fruit.");
  iterator.isBoundary(0); // true;
  iterator.isBoundary(5); // false;
  ```


S
shawn_he 已提交
1261
## i18n.is24HourClock<sup>7+</sup>
S
shawn_he 已提交
1262 1263 1264 1265 1266 1267 1268 1269 1270 1271

is24HourClock(): boolean

Checks whether the 24-hour clock is used.

**System capability**: SystemCapability.Global.I18n

- Return value
  | Type| Description|
  | -------- | -------- |
S
shawn_he 已提交
1272
  | boolean | Returns **true** if the 24-hour clock is used; returns **false** otherwise.|
S
shawn_he 已提交
1273 1274 1275 1276 1277 1278 1279

- Example
  ```
  var is24HourClock = i18n.is24HourClock();
  ```


S
shawn_he 已提交
1280
## i18n.set24HourClock<sup>7+</sup>
S
shawn_he 已提交
1281 1282

set24HourClock(option: boolean): boolean
Z
zengyawen 已提交
1283 1284 1285

Sets the 24-hour clock.

S
shawn_he 已提交
1286 1287 1288 1289 1290
**System capability**: SystemCapability.Global.I18n

- Parameters
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
S
shawn_he 已提交
1291
  | option | boolean | Yes| Whether to enable the 24-hour clock. The value **true** means to enable the 24-hour clock, and the value **false** means the opposite.|
S
shawn_he 已提交
1292 1293 1294 1295

- Return value
  | Type| Description|
  | -------- | -------- |
S
shawn_he 已提交
1296
  | boolean | Returns **true** if the 24-hour clock is enabled; returns **false** otherwise.|
S
shawn_he 已提交
1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307

- Example
  ```
  // Set the system time to the 24-hour clock.
  var success = I18n.set24HourClock(true);
  ```


## i18n.addPreferredLanguage<sup>8+</sup>

addPreferredLanguage(language: string, index?: number): boolean
Z
zengyawen 已提交
1308 1309 1310

Adds a preferred language to the specified position on the preferred language list.

S
shawn_he 已提交
1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321
**System capability**: SystemCapability.Global.I18n

- Parameters
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | language | string | Yes| Preferred language to add.|
  | index | number | No| Position to which the preferred language is added.|

- Return value
  | Type| Description|
  | -------- | -------- |
S
shawn_he 已提交
1322
  | boolean | Returns **true** if the preferred language is successfully added; returns **false** otherwise.|
S
shawn_he 已提交
1323 1324 1325 1326 1327 1328 1329 1330 1331 1332

- Example
  ```
  // Add zh-CN to the preferred language list.
  var language = 'zh-CN';
  var index = 0;
  var success = i18n.addPreferredLanguage(language, index);
  ```


S
shawn_he 已提交
1333
## i18n.removePreferredLanguage<sup>8+</sup>
S
shawn_he 已提交
1334

S
shawn_he 已提交
1335
removePreferredLanguage(index: number): boolean
Z
zengyawen 已提交
1336 1337 1338

Deletes a preferred language from the specified position on the preferred language list.

S
shawn_he 已提交
1339
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1340

S
shawn_he 已提交
1341 1342 1343 1344
- Parameters
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | index | number | Yes| Position of the preferred language to delete.|
Z
zengyawen 已提交
1345

S
shawn_he 已提交
1346 1347 1348
- Return value
  | Type| Description|
  | -------- | -------- |
S
shawn_he 已提交
1349
  | boolean | Returns **true** if the preferred language is deleted; returns **false** otherwise.|
Z
zengyawen 已提交
1350

S
shawn_he 已提交
1351 1352 1353 1354 1355 1356
- Example
  ```
  // Delete the first preferred language from the preferred language list.
  var index = 0;
  var success = i18n.removePreferredLanguage(index);
  ```
Z
zengyawen 已提交
1357 1358


S
shawn_he 已提交
1359
## i18n.getPreferredLanguageList<sup>8+</sup>
Z
zengyawen 已提交
1360

S
shawn_he 已提交
1361
getPreferredLanguageList(): Array<string>
Z
zengyawen 已提交
1362

S
shawn_he 已提交
1363
Obtains the list of preferred languages.
Z
zengyawen 已提交
1364

S
shawn_he 已提交
1365
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1366

S
shawn_he 已提交
1367 1368 1369
- Return value
  | Type| Description|
  | -------- | -------- |
S
shawn_he 已提交
1370
  | Array<string> | List of preferred languages.|
Z
zengyawen 已提交
1371

S
shawn_he 已提交
1372 1373 1374 1375
- Example
  ```
  var preferredLanguageList = i18n.getPreferredLanguageList();
  ```
Z
zengyawen 已提交
1376 1377


S
shawn_he 已提交
1378
## i18n.getFirstPreferredLanguage<sup>8+</sup>
Z
zengyawen 已提交
1379

S
shawn_he 已提交
1380 1381
getFirstPreferredLanguage(): string

S
shawn_he 已提交
1382
Obtains the first language in the preferred language list.
Z
zengyawen 已提交
1383

S
shawn_he 已提交
1384
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1385

S
shawn_he 已提交
1386 1387 1388
- Return value
  | Type| Description|
  | -------- | -------- |
S
shawn_he 已提交
1389
  | string | First language in the preferred language list.|
Z
zengyawen 已提交
1390

S
shawn_he 已提交
1391 1392 1393 1394
- Example
  ```
  var firstPreferredLanguage = i18n.getFirstPreferredLanguage();
  ```
S
shawn_he 已提交
1395 1396


S
shawn_he 已提交
1397
## i18n.getTimeZone<sup>7+</sup>
S
shawn_he 已提交
1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507

getTimeZone(zoneID?: string): TimeZone

Obtains the **TimeZone** object corresponding to the specified time zone ID.

**System capability**: SystemCapability.Global.I18n

- Parameters
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | zondID | string | No| Time zone ID.|

- Return value
  | Type| Description|
  | -------- | -------- |
  | TimeZone | **TimeZone** object corresponding to the time zone ID.|

- Example
  ```
  var timezone = i18n.getTimeZone();
  ```


## RelativeTimeFormat<sup>8+</sup>


### getID<sup>8+</sup>

getID(): string

Obtains the ID of the specified **TimeZone** object.

**System capability**: SystemCapability.Global.I18n

- Return value
  | Type| Description|
  | -------- | -------- |
  | string | Time zone ID corresponding to the **TimeZone** object.|

- Example
  ```
  var timezone = i18n.getTimeZone();
  timezone.getID();
  ```


### getDisplayName<sup>8+</sup>

getDisplayName(locale?: string, isDST?: boolean): string

Obtains the representation of a **TimeZone** object in the specified locale.

**System capability**: SystemCapability.Global.I18n

- Parameters
  | Name| Type| Mandatory| Description|
  | -------- | -------- | -------- | -------- |
  | locale | string | No| System locale ID.|
  | isDST | boolean | No| Whether to consider DST when obtaining the representation of the **TimeZone** object.|

- Return value
  | Type| Description|
  | -------- | -------- |
  | string | Representation of the **TimeZone** object in the specified locale.|

- Example
  ```
  var timezone = i18n.getTimeZone();
  timezone.getDisplayName("zh-CN", false);
  ```


### getRawOffset<sup>8+</sup>

getRawOffset(): number

Obtains the offset between the time zone represented by a **TimeZone** object and the UTC time zone.

**System capability**: SystemCapability.Global.I18n

- Return value
  | Type| Description|
  | -------- | -------- |
  | number | Offset between the time zone represented by the **TimeZone** object and the UTC time zone.|

- Example
  ```
  var timezone = i18n.getTimeZone();
  timezone.getRawOffset();
  ```


### getOffset<sup>8+</sup>

getOffset(date?: number): number

Obtains the offset between the time zone represented by a **TimeZone** object and the UTC time zone at a certain time point.

**System capability**: SystemCapability.Global.I18n

- Return value
  | Type| Description|
  | -------- | -------- |
  | number | Offset between the time zone represented by the **TimeZone** object and the UTC time zone at a certain time point.|

- Example
  ```
  var timezone = i18n.getTimeZone();
  timezone.getOffset(1234567890);
  ```