1# @ohos.i18n (Internationalization) 2 3 This module provides system-related or enhanced i18n capabilities, such as locale management, phone number formatting, and calendar, through supplementary i18n APIs that are not defined in ECMA 402. 4The [intl](js-apis-intl.md) module provides basic i18n capabilities through the standard i18n APIs defined in ECMA 402. It works with the **i18n** module to provide a complete suite of i18n capabilities. 5 6> **NOTE** 7> - 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. 8> 9> - This module provides system-related or enhanced i18n capabilities, such as locale management, phone number formatting, and calendar, through supplementary i18n APIs that are not defined in ECMA 402. For details about the basic I18N capabilities, see [intl](js-apis-intl.md). 10> 11> - Since API version 11, some APIs of this module are supported in ArkTS widgets. 12 13 14 15## Modules to Import 16 17```ts 18import I18n from '@ohos.i18n'; 19``` 20 21 22## System<sup>9+</sup> 23 24### getDisplayCountry<sup>9+</sup> 25 26static getDisplayCountry(country: string, locale: string, sentenceCase?: boolean): string 27 28Obtains the localized script for the specified country. 29 30**System capability**: SystemCapability.Global.I18n 31 32**Parameters** 33 34| Name | Type | Mandatory | Description | 35| ------------ | ------- | ---- | ---------------- | 36| country | string | Yes | Specified country. | 37| locale | string | Yes | Locale ID. | 38| sentenceCase | boolean | No | Whether to use sentence case for the localized script. The default value is **true**.| 39 40**Return value** 41 42| Type | Description | 43| ------ | ------------- | 44| string | Localized script for the specified country.| 45 46**Error codes** 47 48For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md). 49 50| ID | Error Message | 51| ------ | ---------------------- | 52| 890001 | param value not valid | 53 54**Example** 55 ```ts 56 import { BusinessError } from '@ohos.base'; 57 58 try { 59 let displayCountry: string = I18n.System.getDisplayCountry("zh-CN", "en-GB"); // displayCountry = "China" 60 } catch (error) { 61 let err: BusinessError = error as BusinessError; 62 console.error(`call System.getDisplayCountry failed, error code: ${err.code}, message: ${err.message}.`); 63 } 64 ``` 65 66### getDisplayLanguage<sup>9+</sup> 67 68static getDisplayLanguage(language: string, locale: string, sentenceCase?: boolean): string 69 70Obtains the localized script for the specified language. 71 72**System capability**: SystemCapability.Global.I18n 73 74**Parameters** 75 76| Name | Type | Mandatory | Description | 77| ------------ | ------- | ---- | ---------------- | 78| language | string | Yes | Specified language. | 79| locale | string | Yes | Locale ID. | 80| sentenceCase | boolean | No | Whether to use sentence case for the localized script. The default value is **true**.| 81 82**Return value** 83 84| Type | Description | 85| ------ | ------------- | 86| string | Localized script for the specified language.| 87 88**Error codes** 89 90For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md). 91 92| ID | Error Message | 93| ------ | ---------------------- | 94| 890001 | param value not valid | 95 96**Example** 97 ```ts 98 import { BusinessError } from '@ohos.base'; 99 100 try { 101 let displayLanguage: string = I18n.System.getDisplayLanguage("zh", "en-GB"); // displayLanguage = Chinese 102 } catch(error) { 103 let err: BusinessError = error as BusinessError; 104 console.error(`call System.getDisplayLanguage failed, error code: ${err.code}, message: ${err.message}.`); 105 } 106 ``` 107 108### getSystemLanguages<sup>9+</sup> 109 110static getSystemLanguages(): Array<string> 111 112Obtains the list of system languages. 113 114**System capability**: SystemCapability.Global.I18n 115 116**Return value** 117 118| Type | Description | 119| ------------------- | ------------ | 120| Array<string> | List of the IDs of system languages.| 121 122**Example** 123 ```ts 124 import { BusinessError } from '@ohos.base'; 125 126 try { 127 let systemLanguages: Array<string> = I18n.System.getSystemLanguages(); // [ "en-Latn-US", "zh-Hans" ] 128 } catch(error) { 129 let err: BusinessError = error as BusinessError; 130 console.error(`call System.getSystemLanguages failed, error code: ${err.code}, message: ${err.message}.`); 131 } 132 ``` 133 134### getSystemCountries<sup>9+</sup> 135 136static getSystemCountries(language: string): Array<string> 137 138Obtains the list of countries and regions supported for the specified language. 139 140**System capability**: SystemCapability.Global.I18n 141 142**Parameters** 143 144| Name | Type | Mandatory | Description | 145| -------- | ------ | ---- | ----- | 146| language | string | Yes | Language ID.| 147 148**Return value** 149 150| Type | Description | 151| ------------------- | ------------ | 152| Array<string> | List of the IDs of the countries and regions supported for the specified language.| 153 154**Error codes** 155 156For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md). 157 158| ID | Error Message | 159| ------ | ---------------------- | 160| 890001 | param value not valid | 161 162**Example** 163 ```ts 164 import { BusinessError } from '@ohos.base'; 165 166 try { 167 let systemCountries: Array<string> = I18n.System.getSystemCountries('zh'); // systemCountries = [ "ZW", "YT", "YE", ..., "ER", "CN", "DE" ], 240 countries or regions in total 168 } catch(error) { 169 let err: BusinessError = error as BusinessError; 170 console.error(`call System.getSystemCountries failed, error code: ${err.code}, message: ${err.message}.`); 171 } 172 ``` 173 174### isSuggested<sup>9+</sup> 175 176static isSuggested(language: string, region?: string): boolean 177 178Checks whether the system language matches the specified region. 179 180**System capability**: SystemCapability.Global.I18n 181 182**Parameters** 183 184| Name | Type | Mandatory | Description | 185| -------- | ------ | ---- | ------------- | 186| language | string | Yes | Valid language ID, for example, **zh**.| 187| region | string | No | Valid region ID, for example, **CN**. The default value is the country or region where the SIM card is used. | 188 189**Return value** 190 191| Type | Description | 192| ------- | ---------------------------------------- | 193| boolean | The value **true** indicates that the system language matches the specified region, and the value **false** indicates the opposite.| 194 195**Error codes** 196 197For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md). 198 199| ID | Error Message | 200| ------ | ---------------------- | 201| 890001 | param value not valid | 202 203**Example** 204 ```ts 205 import { BusinessError } from '@ohos.base'; 206 207 try { 208 let res: boolean = I18n.System.isSuggested('zh', 'CN'); // res = true 209 } catch(error) { 210 let err: BusinessError = error as BusinessError; 211 console.error(`call System.isSuggested failed, error code: ${err.code}, message: ${err.message}.`); 212 } 213 ``` 214 215### getSystemLanguage<sup>9+</sup> 216 217static getSystemLanguage(): string 218 219Obtains the system language. 220 221Since API version 11, this API is supported in ArkTS widgets. 222 223**System capability**: SystemCapability.Global.I18n 224 225**Return value** 226 227| Type | Description | 228| ------ | ------- | 229| string | System language ID.| 230 231**Example** 232 ```ts 233 import { BusinessError } from '@ohos.base'; 234 235 try { 236 let systemLanguage: string = I18n.System.getSystemLanguage(); // systemLanguage indicates the current system language. 237 } catch(error) { 238 let err: BusinessError = error as BusinessError; 239 console.error(`call System.getSystemLanguage failed, error code: ${err.code}, message: ${err.message}.`); 240 } 241 ``` 242 243### setSystemLanguage<sup>9+</sup> 244 245static setSystemLanguage(language: string): void 246 247Sets the system language. Currently, this API does not support real-time updating of the system language. 248 249To listen for [common_event_locale_changed](./commonEventManager-definitions.md#common_event_locale_changed) events after the system language is set, you need to add an [event subscriber](./js-apis-commonEventManager.md#commoneventmanagercreatesubscriber-1). 250 251**System API**: This is a system API. 252 253**Permission required**: ohos.permission.UPDATE_CONFIGURATION 254 255**System capability**: SystemCapability.Global.I18n 256 257**Parameters** 258 259| Name | Type | Mandatory | Description | 260| -------- | ------ | ---- | ----- | 261| language | string | Yes | Language ID.| 262 263**Error codes** 264 265For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md). 266 267| ID | Error Message | 268| ------ | ---------------------- | 269| 890001 | param value not valid | 270 271**Example** 272 ```ts 273 import { BusinessError } from '@ohos.base'; 274 import CommonEventManager from '@ohos.commonEventManager'; 275 276 // Set the system language 277 try { 278 I18n.System.setSystemLanguage('zh'); // Set the current system language to zh. 279 } catch(error) { 280 let err: BusinessError = error as BusinessError; 281 console.error(`call System.setSystemLanguage failed, error code: ${err.code}, message: ${err.message}.`); 282 } 283 284 // Subscribe to a common event. 285 let subscriber: CommonEventManager.CommonEventSubscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription. 286 let subscribeInfo: CommonEventManager.CommonEventSubscribeInfo = { // Define the subscriber information. 287 events: [CommonEventManager.Support.COMMON_EVENT_LOCALE_CHANGED] 288 }; 289 CommonEventManager.createSubscriber(subscribeInfo).then((commonEventSubscriber:CommonEventManager.CommonEventSubscriber) => { // Create a subscriber. 290 console.info("createSubscriber"); 291 subscriber = commonEventSubscriber; 292 CommonEventManager.subscribe(subscriber, (err, data) => { 293 if (err) { 294 console.error(`Failed to subscribe common event. error code: ${err.code}, message: ${err.message}.`); 295 return; 296 } 297 console.info("the subscribed event has occurred."); // Triggered when the subscribed event occurs. 298 }) 299 }).catch((err: BusinessError) => { 300 console.error(`createSubscriber failed, code is ${err.code}, message is ${err.message}`); 301 }); 302 ``` 303 304### getSystemRegion<sup>9+</sup> 305 306static getSystemRegion(): string 307 308Obtains the system region. 309 310**System capability**: SystemCapability.Global.I18n 311 312**Return value** 313 314| Type | Description | 315| ------ | ------- | 316| string | System region ID.| 317 318**Example** 319 ```ts 320 import { BusinessError } from '@ohos.base'; 321 322 try { 323 let systemRegion: string = I18n.System.getSystemRegion(); // Obtain the current system region. 324 } catch(error) { 325 let err: BusinessError = error as BusinessError; 326 console.error(`call System.getSystemRegion failed, error code: ${err.code}, message: ${err.message}.`); 327 } 328 ``` 329 330### setSystemRegion<sup>9+</sup> 331 332static setSystemRegion(region: string): void 333 334Sets the system region. 335 336**System API**: This is a system API. 337 338**Permission required**: ohos.permission.UPDATE_CONFIGURATION 339 340**System capability**: SystemCapability.Global.I18n 341 342**Parameters** 343 344| Name | Type | Mandatory | Description | 345| ------ | ------ | ---- | ----- | 346| region | string | Yes | System region ID.| 347 348**Error codes** 349 350For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md). 351 352| ID | Error Message | 353| ------ | ---------------------- | 354| 890001 | param value not valid | 355 356**Example** 357 ```ts 358 import { BusinessError } from '@ohos.base'; 359 360 try { 361 I18n.System.setSystemRegion('CN'); // Set the current system region to CN. 362 } catch(error) { 363 let err: BusinessError = error as BusinessError; 364 console.error(`call System.setSystemRegion failed, error code: ${err.code}, message: ${err.message}.`); 365 } 366 ``` 367 368### getSystemLocale<sup>9+</sup> 369 370static getSystemLocale(): string 371 372Obtains the system locale. 373 374**System capability**: SystemCapability.Global.I18n 375 376**Return value** 377 378| Type | Description | 379| ------ | ------- | 380| string | System locale ID.| 381 382**Example** 383 ```ts 384 import { BusinessError } from '@ohos.base'; 385 386 try { 387 let systemLocale: string = I18n.System.getSystemLocale(); // Obtain the current system locale. 388 } catch(error) { 389 let err: BusinessError = error as BusinessError; 390 console.error(`call System.getSystemLocale failed, error code: ${err.code}, message: ${err.message}.`); 391 } 392 ``` 393 394### setSystemLocale<sup>9+</sup> 395 396static setSystemLocale(locale: string): void 397 398Sets the system locale. 399 400**System API**: This is a system API. 401 402**Permission required**: ohos.permission.UPDATE_CONFIGURATION 403 404**System capability**: SystemCapability.Global.I18n 405 406**Parameters** 407 408| Name | Type | Mandatory | Description | 409| ------ | ------ | ---- | --------------- | 410| locale | string | Yes | System locale ID, for example, **zh-CN**.| 411 412**Error codes** 413 414For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md). 415 416| ID | Error Message | 417| ------ | ---------------------- | 418| 890001 | param value not valid | 419 420**Example** 421 ```ts 422 import { BusinessError } from '@ohos.base'; 423 424 try { 425 I18n.System.setSystemLocale('zh-CN'); // Set the current system locale to zh-CN. 426 } catch(error) { 427 let err: BusinessError = error as BusinessError; 428 console.error(`call System.setSystemLocale failed, error code: ${err.code}, message: ${err.message}.`); 429 } 430 ``` 431 432### is24HourClock<sup>9+</sup> 433 434static is24HourClock(): boolean 435 436Checks whether the 24-hour clock is used. 437 438Since API version 11, this API is supported in ArkTS widgets. 439 440**System capability**: SystemCapability.Global.I18n 441 442**Return value** 443 444| Type | Description | 445| ------- | ---------------------------------------- | 446| boolean | The value **true** indicates that the 24-hour clock is used, and the value **false** indicates the opposite.| 447 448**Example** 449 ```ts 450 import { BusinessError } from '@ohos.base'; 451 452 try { 453 let is24HourClock: boolean = I18n.System.is24HourClock(); // Check whether the 24-hour clock is enabled. 454 } catch(error) { 455 let err: BusinessError = error as BusinessError; 456 console.error(`call System.is24HourClock failed, error code: ${err.code}, message: ${err.message}.`); 457 } 458 ``` 459 460### set24HourClock<sup>9+</sup> 461 462static set24HourClock(option: boolean): void 463 464Sets the system time to the 24-hour clock. 465 466**System API**: This is a system API. 467 468**Permission required**: ohos.permission.UPDATE_CONFIGURATION 469 470**System capability**: SystemCapability.Global.I18n 471 472**Parameters** 473 474| Name | Type | Mandatory | Description | 475| ------ | ------- | ---- | ---------------------------------------- | 476| 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.| 477 478**Error codes** 479 480For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md). 481 482| ID | Error Message | 483| ------ | ---------------------- | 484| 890001 | param value not valid | 485 486**Example** 487 ```ts 488 import { BusinessError } from '@ohos.base'; 489 490 // Set the system time to the 24-hour clock. 491 try { 492 I18n.System.set24HourClock(true); 493 } catch(error) { 494 let err: BusinessError = error as BusinessError; 495 console.error(`call System.set24HourClock failed, error code: ${err.code}, message: ${err.message}.`); 496 } 497 ``` 498 499### addPreferredLanguage<sup>9+</sup> 500 501static addPreferredLanguage(language: string, index?: number): void 502 503Adds a preferred language to the specified position on the preferred language list. 504 505**System API**: This is a system API. 506 507**Permission required**: ohos.permission.UPDATE_CONFIGURATION 508 509**System capability**: SystemCapability.Global.I18n 510 511**Parameters** 512 513| Name | Type | Mandatory | Description | 514| -------- | ------ | ---- | ---------- | 515| language | string | Yes | Preferred language to add. | 516| index | number | No | Position to which the preferred language is added. The default value is the length of the preferred language list.| 517 518**Error codes** 519 520For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md). 521 522| ID | Error Message | 523| ------ | ---------------------- | 524| 890001 | param value not valid | 525 526**Example** 527 ```ts 528 import { BusinessError } from '@ohos.base'; 529 530 // Add zh-CN to the preferred language list. 531 let language = 'zh-CN'; 532 let index = 0; 533 try { 534 I18n.System.addPreferredLanguage(language, index); // Add zh-CN to the first place in the preferred language list. 535 } catch(error) { 536 let err: BusinessError = error as BusinessError; 537 console.error(`call System.addPreferredLanguage failed, error code: ${err.code}, message: ${err.message}.`); 538 } 539 ``` 540 541### removePreferredLanguage<sup>9+</sup> 542 543static removePreferredLanguage(index: number): void 544 545Deletes a preferred language from the specified position on the preferred language list. 546 547**System API**: This is a system API. 548 549**Permission required**: ohos.permission.UPDATE_CONFIGURATION 550 551**System capability**: SystemCapability.Global.I18n 552 553**Parameters** 554 555| Name | Type | Mandatory | Description | 556| ----- | ------ | ---- | --------------------- | 557| index | number | Yes | Position of the preferred language to delete.| 558 559**Error codes** 560 561For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md). 562 563| ID | Error Message | 564| ------ | ---------------------- | 565| 890001 | param value not valid | 566 567**Example** 568 ```ts 569 import { BusinessError } from '@ohos.base'; 570 571 // Delete the first preferred language from the preferred language list. 572 let index: number = 0; 573 try { 574 I18n.System.removePreferredLanguage(index); 575 } catch(error) { 576 let err: BusinessError = error as BusinessError; 577 console.error(`call System.removePreferredLanguage failed, error code: ${err.code}, message: ${err.message}.`); 578 } 579 ``` 580 581### getPreferredLanguageList<sup>9+</sup> 582 583static getPreferredLanguageList(): Array<string> 584 585Obtains the list of preferred languages. 586 587**System capability**: SystemCapability.Global.I18n 588 589**Return value** 590 591| Type | Description | 592| ------------------- | --------- | 593| Array<string> | List of preferred languages.| 594 595**Example** 596 ```ts 597 import { BusinessError } from '@ohos.base'; 598 599 try { 600 let preferredLanguageList: Array<string> = I18n.System.getPreferredLanguageList(); // Obtain the current preferred language list. 601 } catch(error) { 602 let err: BusinessError = error as BusinessError; 603 console.error(`call System.getPreferredLanguageList failed, error code: ${err.code}, message: ${err.message}.`); 604 } 605 ``` 606 607### getFirstPreferredLanguage<sup>9+</sup> 608 609static getFirstPreferredLanguage(): string 610 611Obtains the first language in the preferred language list. 612 613**System capability**: SystemCapability.Global.I18n 614 615**Return value** 616 617| Type | Description | 618| ------ | -------------- | 619| string | First language in the preferred language list.| 620 621**Example** 622 ```ts 623 import { BusinessError } from '@ohos.base'; 624 625 try { 626 let firstPreferredLanguage: string = I18n.System.getFirstPreferredLanguage(); // Obtain the first language in the preferred language list. 627 } catch(error) { 628 let err: BusinessError = error as BusinessError; 629 console.error(`call System.getFirstPreferredLanguage failed, error code: ${err.code}, message: ${err.message}.`); 630 } 631 ``` 632 633### setAppPreferredLanguage<sup>11+</sup> 634 635static setAppPreferredLanguage(language: string): void 636 637Sets the preferred language of the application. 638 639**System capability**: SystemCapability.Global.I18n 640 641**Parameters** 642 643| Name | Type | Mandatory | Description | 644| -------- | ------ | ---- | ----- | 645| language | string | Yes | Language ID.| 646 647**Error codes** 648 649For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md). 650 651| ID | Error Message | 652| ------ | ---------------------- | 653| 890001 | param value not valid | 654 655**Example** 656 ```ts 657 import { BusinessError } from '@ohos.base'; 658 659 try { 660 I18n.System.setAppPreferredLanguage('zh'); // Set the current language of the application to zh. 661 } catch(error) { 662 let err: BusinessError = error as BusinessError; 663 console.error(`call System.setAppPreferredLanguage failed, error code: ${err.code}, message: ${err.message}.`); 664 } 665 ``` 666 667### getAppPreferredLanguage<sup>9+</sup> 668 669static getAppPreferredLanguage(): string 670 671Obtains the preferred language of an application. 672 673**System capability**: SystemCapability.Global.I18n 674 675**Return value** 676 677| Type | Description | 678| ------ | -------- | 679| string | Preferred language of the application.| 680 681**Example** 682 ```ts 683 import { BusinessError } from '@ohos.base'; 684 685 try { 686 let appPreferredLanguage: string = I18n.System.getAppPreferredLanguage(); // Obtain the preferred language of an application. 687 } catch(error) { 688 let err: BusinessError = error as BusinessError; 689 console.error(`call System.getAppPreferredLanguage failed, error code: ${err.code}, message: ${err.message}.`); 690 } 691 ``` 692 693### setUsingLocalDigit<sup>9+</sup> 694 695static setUsingLocalDigit(flag: boolean): void 696 697Specifies whether to enable use of local digits. 698 699**System API**: This is a system API. 700 701**Permission required**: ohos.permission.UPDATE_CONFIGURATION 702 703**System capability**: SystemCapability.Global.I18n 704 705**Parameters** 706 707| Name | Type | Mandatory | Description | 708| ---- | ------- | ---- | ------------------------------- | 709| flag | boolean | Yes | Whether to turn on the local digit switch. The value **true** means to turn on the local digit switch, and the value **false** indicates the opposite.| 710 711**Error codes** 712 713For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md). 714 715| ID | Error Message | 716| ------ | ---------------------- | 717| 890001 | param value not valid | 718 719**Example** 720 ```ts 721 import { BusinessError } from '@ohos.base'; 722 723 try { 724 I18n.System.setUsingLocalDigit(true); // Enable the local digit switch. 725 } catch(error) { 726 let err: BusinessError = error as BusinessError; 727 console.error(`call System.setUsingLocalDigit failed, error code: ${err.code}, message: ${err.message}.`); 728 } 729 ``` 730 731### getUsingLocalDigit<sup>9+</sup> 732 733static getUsingLocalDigit(): boolean 734 735Checks whether use of local digits is enabled. 736 737**System capability**: SystemCapability.Global.I18n 738 739**Return value** 740 741| Type | Description | 742| ------- | ---------------------------------------- | 743| boolean | The value **true** indicates that the local digit switch is turned on, and the value **false** indicates the opposite.| 744 745**Example** 746 ```ts 747 import { BusinessError } from '@ohos.base'; 748 749 try { 750 let status: boolean = I18n.System.getUsingLocalDigit(); // Check whether the local digit switch is enabled. 751 } catch(error) { 752 let err: BusinessError = error as BusinessError; 753 console.error(`call System.getUsingLocalDigit failed, error code: ${err.code}, message: ${err.message}.`); 754 } 755 ``` 756 757 758## I18n.isRTL 759 760isRTL(locale: string): boolean 761 762Checks whether a locale uses an RTL language. 763 764**System capability**: SystemCapability.Global.I18n 765 766**Parameters** 767 768| Name | Type | Mandatory | Description | 769| ------ | ------ | ---- | ------- | 770| locale | string | Yes | Locale ID.| 771 772**Return value** 773 774| Type | Description | 775| ------- | ---------------------------------------- | 776| boolean | The value **true** indicates that the localized script is displayed from right to left, and the value **false** indicates the opposite.| 777 778**Example** 779 ```ts 780 i18n.isRTL("zh-CN");// Since Chinese is not written from right to left, false is returned. 781 i18n.isRTL("ar-EG");// Since Arabic is written from right to left, true is returned. 782 ``` 783 784 785## I18n.getCalendar<sup>8+</sup> 786 787getCalendar(locale: string, type? : string): Calendar 788 789Obtains a **Calendar** object. 790 791**System capability**: SystemCapability.Global.I18n 792 793**Parameters** 794 795| Name | Type | Mandatory | Description | 796| ------ | ------ | ---- | ---------------------------------------- | 797| locale | string | Yes | Valid locale value, for example, **zh-Hans-CN**. | 798| 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**. The default value is the default calendar type of the locale.| 799 800**Return value** 801 802| Type | Description | 803| ---------------------- | ----- | 804| [Calendar](#calendar8) | **Calendar** object.| 805 806**Example** 807 ```ts 808 I18n.getCalendar("zh-Hans", "chinese"); // Obtain the Calendar object for the Chinese lunar calendar. 809 ``` 810 811## EntityRecognizer<sup>11+</sup> 812 813### constructor<sup>11+</sup> 814 815constructor(locale?: string) 816 817Creates an **entityRecognizer** object. 818 819**System capability**: SystemCapability.Global.I18n 820 821**Parameters** 822 823| Name | Type | Mandatory | Description | 824| ---- | ---- | ---- | ----------------- | 825| locale | string | No | Locale ID.| 826 827**Error codes** 828 829For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md). 830 831| ID | Error Message | 832| ------ | ---------------------- | 833| 890001 | param value not valid | 834 835**Example** 836 ```ts 837 let entityRecognizer: I18n.EntityRecognizer = new I18n.EntityRecognizer("zh-CN"); 838 ``` 839 840### findEntityInfo<sup>11+</sup> 841 842findEntityInfo(text: string): Array<EntityInfoItem> 843 844Recognizes entities in text. 845 846**System capability**: SystemCapability.Global.I18n 847 848**Parameters** 849 850| Name | Type | Mandatory | Description | 851| ---- | ---- | ---- | ----------------- | 852| text | string | Yes | Text for entity recognition.| 853 854**Return value** 855 856| Type | Description | 857| ---- | ----------------- | 858| Array<[EntityInfoItem](#entityinfoitem11)> | List of recognized entities.| 859 860**Example** 861 ```ts 862 let entityRecognizer: I18n.EntityRecognizer = new I18n.EntityRecognizer("zh-CN"); 863 let text1: string = " If you have any questions, call us by phone 12345678"; 864 let result1: Array<I18n.EntityInfoItem> = entityRecognizer.findEntityInfo(text1); // result1[0].type = "phone_number", result1[0].begin = 8, result1[0].end = 19 865 let text2: string = "Let's have dinner on December 1, 2023." 866 let result2: Array<I18n.EntityInfoItem> = entityRecognizer.findEntityInfo(text2); // result2[0].type = "date", result2[0].begin = 2, result2[0].end = 12 867 ``` 868 869## EntityInfoItem<sup>11+</sup> 870 871Defines an entity information object. 872 873**System capability**: SystemCapability.Global.I18n 874 875| Name | Type | Readable | Writable | Description | 876| ---- | ---- | ---- | ---- | ----------------- | 877| type | string | Yes | Yes | Entity type, which can be **phone_number** or **date**.| 878| begin | number | Yes | Yes | Start position of an entity.| 879| end | number | Yes | Yes | End position of an entity.| 880 881## Calendar<sup>8+</sup> 882 883 884### setTime<sup>8+</sup> 885 886setTime(date: Date): void 887 888Sets the date for this **Calendar** object. 889 890**System capability**: SystemCapability.Global.I18n 891 892**Parameters** 893 894| Name | Type | Mandatory | Description | 895| ---- | ---- | ---- | ----------------- | 896| date | Date | Yes | Date to be set for the **Calendar** object.| 897 898**Example** 899 ```ts 900 let calendar: I18n.Calendar = I18n.getCalendar("en-US", "gregory"); 901 let date: Date = new Date(2021, 10, 7, 8, 0, 0, 0); 902 calendar.setTime(date); 903 ``` 904 905 906### setTime<sup>8+</sup> 907 908setTime(time: number): void 909 910Sets 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). 911 912**System capability**: SystemCapability.Global.I18n 913 914**Parameters** 915 916| Name | Type | Mandatory | Description | 917| ---- | ------ | ---- | ---------------------------------------- | 918| time | number | Yes | Number of milliseconds that have elapsed since the Unix epoch.| 919 920**Example** 921 ```ts 922 let calendar: I18n.Calendar = I18n.getCalendar("en-US", "gregory"); 923 calendar.setTime(10540800000); 924 ``` 925 926 927### set<sup>8+</sup> 928 929set(year: number, month: number, date:number, hour?: number, minute?: number, second?: number): void 930 931Sets the year, month, day, hour, minute, and second for this **Calendar** object. 932 933**System capability**: SystemCapability.Global.I18n 934 935**Parameters** 936 937| Name | Type | Mandatory | Description | 938| ------ | ------ | ---- | ------ | 939| year | number | Yes | Year to set. | 940| month | number | Yes | Month to set. | 941| date | number | Yes | Day to set. | 942| hour | number | No | Hour to set. The default value is the system hour.| 943| minute | number | No | Minute to set. The default value is the system minute.| 944| second | number | No | Second to set. The default value is the system second.| 945 946**Example** 947 ```ts 948 let calendar: I18n.Calendar = I18n.getCalendar("zh-Hans"); 949 calendar.set(2021, 10, 1, 8, 0, 0); // set time to 2021.10.1 08:00:00 950 ``` 951 952 953### setTimeZone<sup>8+</sup> 954 955setTimeZone(timezone: string): void 956 957Sets the time zone of this **Calendar** object. 958 959**System capability**: SystemCapability.Global.I18n 960 961**Parameters** 962 963| Name | Type | Mandatory | Description | 964| -------- | ------ | ---- | ------------------------- | 965| timezone | string | Yes | Time zone, for example, **Asia/Shanghai**.| 966 967**Example** 968 ```ts 969 let calendar: I18n.Calendar = I18n.getCalendar("zh-Hans"); 970 calendar.setTimeZone("Asia/Shanghai"); 971 ``` 972 973 974### getTimeZone<sup>8+</sup> 975 976getTimeZone(): string 977 978Obtains the time zone of this **Calendar** object. 979 980**System capability**: SystemCapability.Global.I18n 981 982**Return value** 983 984| Type | Description | 985| ------ | ---------- | 986| string | Time zone of the **Calendar** object.| 987 988**Example** 989 ```ts 990 let calendar: I18n.Calendar = I18n.getCalendar("zh-Hans"); 991 calendar.setTimeZone("Asia/Shanghai"); 992 let timezone: string = calendar.getTimeZone(); // timezone = "Asia/Shanghai" 993 ``` 994 995 996### getFirstDayOfWeek<sup>8+</sup> 997 998getFirstDayOfWeek(): number 999 1000Obtains the start day of a week for this **Calendar** object. 1001 1002**System capability**: SystemCapability.Global.I18n 1003 1004**Return value** 1005 1006| Type | Description | 1007| ------ | --------------------- | 1008| number | Start day of a week. The value **1** indicates Sunday, and the value **7** indicates Saturday.| 1009 1010**Example** 1011 ```ts 1012 let calendar: I18n.Calendar = I18n.getCalendar("en-US", "gregory"); 1013 let firstDayOfWeek: number = calendar.getFirstDayOfWeek(); // firstDayOfWeek = 1 1014 ``` 1015 1016 1017### setFirstDayOfWeek<sup>8+</sup> 1018 1019setFirstDayOfWeek(value: number): void 1020 1021Sets the start day of a week for this **Calendar** object. 1022 1023**System capability**: SystemCapability.Global.I18n 1024 1025**Parameters** 1026 1027| Name | Type | Mandatory | Description | 1028| ----- | ------ | ---- | --------------------- | 1029| value | number | Yes | Start day of a week. The value **1** indicates Sunday, and the value **7** indicates Saturday.| 1030 1031**Example** 1032 ```ts 1033 let calendar: I18n.Calendar = I18n.getCalendar("zh-Hans"); 1034 calendar.setFirstDayOfWeek(3); 1035 let firstDayOfWeek: number = calendar.getFirstDayOfWeek(); // firstDayOfWeek = 3 1036 ``` 1037 1038 1039### getMinimalDaysInFirstWeek<sup>8+</sup> 1040 1041getMinimalDaysInFirstWeek(): number 1042 1043Obtains the minimum number of days in the first week of a year. 1044 1045**System capability**: SystemCapability.Global.I18n 1046 1047**Return value** 1048 1049| Type | Description | 1050| ------ | ------------ | 1051| number | Minimum number of days in the first week of a year.| 1052 1053**Example** 1054 ```ts 1055 let calendar: I18n.Calendar = I18n.getCalendar("zh-Hans"); 1056 let minimalDaysInFirstWeek: number = calendar.getMinimalDaysInFirstWeek(); // minimalDaysInFirstWeek = 1 1057 ``` 1058 1059 1060### setMinimalDaysInFirstWeek<sup>8+</sup> 1061 1062setMinimalDaysInFirstWeek(value: number): void 1063 1064Sets the minimum number of days in the first week of a year. 1065 1066**System capability**: SystemCapability.Global.I18n 1067 1068**Parameters** 1069 1070| Name | Type | Mandatory | Description | 1071| ----- | ------ | ---- | ------------ | 1072| value | number | Yes | Minimum number of days in the first week of a year.| 1073 1074**Example** 1075 ```ts 1076 let calendar: I18n.Calendar = I18n.getCalendar("zh-Hans"); 1077 calendar.setMinimalDaysInFirstWeek(3); 1078 let minimalDaysInFirstWeek: number = calendar.getMinimalDaysInFirstWeek(); // minimalDaysInFirstWeek = 3 1079 ``` 1080 1081 1082### get<sup>8+</sup> 1083 1084get(field: string): number 1085 1086Obtains the value of the specified field in the **Calendar** object. 1087 1088**System capability**: SystemCapability.Global.I18n 1089 1090**Parameters** 1091 1092| Name | Type | Mandatory | Description | 1093| ----- | ------ | ---- | ---------------------------------------- | 1094| 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**.| 1095 1096**Return value** 1097 1098| Type | Description | 1099| ------ | ---------------------------------------- | 1100| 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**.| 1101 1102**Example** 1103 ```ts 1104 let calendar: I18n.Calendar = I18n.getCalendar("zh-Hans"); 1105 calendar.set(2021, 10, 1, 8, 0, 0); // set time to 2021.10.1 08:00:00 1106 let hourOfDay: number = calendar.get("hour_of_day"); // hourOfDay = 8 1107 ``` 1108 1109 1110### getDisplayName<sup>8+</sup> 1111 1112getDisplayName(locale: string): string 1113 1114Obtains the displayed name of the **Calendar** object for the specified locale. 1115 1116**System capability**: SystemCapability.Global.I18n 1117 1118**Parameters** 1119 1120| Name | Type | Mandatory | Description | 1121| ------ | ------ | ---- | ---------------------------------------- | 1122| locale | string | Yes | Locale for the displayed name of the **Calendar** object. For example, displayed name of **buddhist** is **Buddhist Calendar** when the locale is set to **en-US**.| 1123 1124**Return value** 1125 1126| Type | Description | 1127| ------ | ------------------- | 1128| string | Displayed name of the **Calendar** object for the specified locale.| 1129 1130**Example** 1131 ```ts 1132 let calendar: I18n.Calendar = I18n.getCalendar("en-US", "buddhist"); 1133 let calendarName: string = calendar.getDisplayName("zh"); // calendarName = "Buddhist Calendar" 1134 ``` 1135 1136 1137### isWeekend<sup>8+</sup> 1138 1139isWeekend(date?: Date): boolean 1140 1141Checks whether a given date is a weekend in the calendar. 1142 1143**System capability**: SystemCapability.Global.I18n 1144 1145**Parameters** 1146 1147| Name | Type | Mandatory | Description | 1148| ---- | ---- | ---- | ---------------------------------------- | 1149| date | Date | No | Specified date. If this parameter is left empty, the system checks whether the current date is a weekend. The default value is the system date.| 1150 1151**Return value** 1152 1153| Type | Description | 1154| ------- | ----------------------------------- | 1155| boolean | The value **true** indicates that the specified date is a weekend, and the value **false** indicates the opposite.| 1156 1157**Example** 1158 ```ts 1159 let calendar: I18n.Calendar = I18n.getCalendar("zh-Hans"); 1160 calendar.set(2021, 11, 11, 8, 0, 0); // set time to 2021.11.11 08:00:00 1161 calendar.isWeekend(); // false 1162 let date: Date = new Date(2011, 11, 6, 9, 0, 0); 1163 calendar.isWeekend(date); // true 1164 ``` 1165 1166 1167### add<sup>11+</sup> 1168 1169add(field: string, amount: number): void 1170 1171Performs addition and subtraction operations on the specified field of the **Calendar** object. 1172 1173**System capability**: SystemCapability.Global.I18n 1174 1175**Parameters** 1176 1177| Name | Type | Mandatory | Description | 1178| ---- | ---- | ---- | ---------------------------------------- | 1179| field | string | Yes | Specified field of the **Calendar** object. The supported value 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.| 1180| amount | number | Yes | Addition or subtraction amount.| 1181 1182**Error codes** 1183 1184For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md). 1185 1186| ID | Error Message | 1187| ------ | ---------------------- | 1188| 890001 | param value not valid | 1189 1190**Example** 1191 ```ts 1192 import { BusinessError } from '@ohos.base'; 1193 1194 try { 1195 let calendar: I18n.Calendar = I18n.getCalendar("zh-Hans"); 1196 calendar.set(2021, 11, 11, 8, 0, 0); // set time to 2021.11.11 08:00:00 1197 calendar.add("year", 8); // 2021 + 8 1198 let year: number = calendar.get("year"); // year = 2029 1199 } catch(error) { 1200 let err: BusinessError = error as BusinessError; 1201 console.error(`call Calendar.add failed, error code: ${err.code}, message: ${err.message}.`); 1202 } 1203 ``` 1204 1205 1206### getTimeInMillis<sup>11+</sup> 1207 1208getTimeInMillis(): number 1209 1210Obtains number of milliseconds that have elapsed since the Unix epoch in the current **Calendar** object. 1211 1212**System capability**: SystemCapability.Global.I18n 1213 1214**Return value** 1215 1216| Type | Description | 1217| ------- | ----------------------------------- | 1218| number | Number of milliseconds that have elapsed since the Unix epoch.| 1219 1220**Example** 1221 ```ts 1222 let calendar: I18n.Calendar = I18n.getCalendar("zh-Hans"); 1223 calendar.setTime(5000); 1224 let millisecond: number = calendar.getTimeInMillis(); // millisecond = 5000 1225 ``` 1226 1227 1228### compareDays<sup>11+</sup> 1229 1230compareDays(date: Date): number 1231 1232Compares the number of days between the calendar date and the specified date. The value is accurate to milliseconds. If the value is less than one day, it is treated as one day. 1233 1234**System capability**: SystemCapability.Global.I18n 1235 1236**Parameters** 1237 1238| Name | Type | Mandatory | Description | 1239| ---- | ---- | ---- | ---------------------------------------- | 1240| date | Date | Yes | Specified date.| 1241 1242**Return value** 1243 1244| Type | Description | 1245| ------- | ----------------------------------- | 1246| number | Number of days between the calendar date and the specified date. A positive number indicates that the calendar date is earlier, and a negative number indicates the opposite.| 1247 1248**Example** 1249 ```ts 1250 import { BusinessError } from '@ohos.base'; 1251 1252 try { 1253 let calendar: I18n.Calendar = I18n.getCalendar("zh-Hans"); 1254 calendar.setTime(5000); 1255 let date: Date = new Date(6000); 1256 let diff: number = calendar.compareDays(date); // diff = 1 1257 } catch(error) { 1258 let err: BusinessError = error as BusinessError; 1259 console.error(`call Calendar.compareDays failed, error code: ${err.code}, message: ${err.message}.`); 1260 } 1261 ``` 1262 1263 1264## PhoneNumberFormat<sup>8+</sup> 1265 1266 1267### constructor<sup>8+</sup> 1268 1269constructor(country: string, options?: PhoneNumberFormatOptions) 1270 1271Creates a **PhoneNumberFormat** object. 1272 1273**System capability**: SystemCapability.Global.I18n 1274 1275**Parameters** 1276 1277| Name | Type | Mandatory | Description | 1278| ------- | ---------------------------------------- | ---- | ---------------- | 1279| country | string | Yes | Country or region to which the phone number to be formatted belongs.| 1280| options | [PhoneNumberFormatOptions](#phonenumberformatoptions8) | No | Options of the **PhoneNumberFormat** object. The default value is **NATIONAL**. | 1281 1282**Example** 1283 ```ts 1284 let option: I18n.PhoneNumberFormatOptions = {type: "E164"}; 1285 let phoneNumberFormat: I18n.PhoneNumberFormat = new I18n.PhoneNumberFormat("CN", option); 1286 ``` 1287 1288 1289### isValidNumber<sup>8+</sup> 1290 1291isValidNumber(number: string): boolean 1292 1293Checks whether the format of the specified phone number is valid. 1294 1295**System capability**: SystemCapability.Global.I18n 1296 1297**Parameters** 1298 1299| Name | Type | Mandatory | Description | 1300| ------ | ------ | ---- | --------- | 1301| number | string | Yes | Phone number to be checked.| 1302 1303**Return value** 1304 1305| Type | Description | 1306| ------- | ------------------------------------- | 1307| boolean | The value **true** indicates that the phone number format is valid, and the value **false** indicates the opposite.| 1308 1309**Example** 1310 ```ts 1311 let phonenumberfmt: I18n.PhoneNumberFormat = new I18n.PhoneNumberFormat("CN"); 1312 let isValidNumber: boolean = phonenumberfmt.isValidNumber("158****2312"); // isValidNumber = true 1313 ``` 1314 1315 1316### format<sup>8+</sup> 1317 1318format(number: string): string 1319 1320Formats a phone number. 1321 1322**System capability**: SystemCapability.Global.I18n 1323 1324**Parameters** 1325 1326| Name | Type | Mandatory | Description | 1327| ------ | ------ | ---- | ---------- | 1328| number | string | Yes | Phone number to be formatted.| 1329 1330**Return value** 1331 1332| Type | Description | 1333| ------ | ---------- | 1334| string | Formatted phone number.| 1335 1336**Example** 1337 ```ts 1338 let phonenumberfmt: I18n.PhoneNumberFormat = new I18n.PhoneNumberFormat("CN"); 1339 let formattedPhoneNumber: string = phonenumberfmt.format("158****2312"); // formattedPhoneNumber = "158 **** 2312" 1340 ``` 1341 1342 1343### getLocationName<sup>9+</sup> 1344 1345getLocationName(number: string, locale: string): string 1346 1347Obtains the home location of a phone number. 1348 1349**System capability**: SystemCapability.Global.I18n 1350 1351**Parameters** 1352 1353| Name | Type | Mandatory | Description | 1354| ------ | ------ | ---- | ---- | 1355| number | string | Yes | Phone number.| 1356| locale | string | Yes | Locale ID.| 1357 1358**Return value** 1359 1360| Type | Description | 1361| ------ | -------- | 1362| string | Home location of the phone number.| 1363 1364**Example** 1365 ```ts 1366 let phonenumberfmt: I18n.PhoneNumberFormat = new I18n.PhoneNumberFormat("CN"); 1367 let locationName: string = phonenumberfmt.getLocationName("158****2345", "zh-CN"); // locationName = "Zhanjiang, Guangdong Province" 1368 ``` 1369 1370 1371## PhoneNumberFormatOptions<sup>8+</sup> 1372 1373Defines the options for this PhoneNumberFormat object. 1374 1375**System capability**: SystemCapability.Global.I18n 1376 1377| Name | Type | Readable | Writable | Description | 1378| ---- | ------ | ---- | ---- | ---------------------------------------- | 1379| type | string | Yes | Yes | Format type of a phone number. The value can be **E164**, **INTERNATIONAL**, **NATIONAL**, or **RFC3966**.<br>- In API version 8, **type** is mandatory.<br>- In API version 9 or later, **type** is optional.| 1380 1381 1382## UnitInfo<sup>8+</sup> 1383 1384Defines the measurement unit information. 1385 1386**System capability**: SystemCapability.Global.I18n 1387 1388| Name | Type | Readable | Writable | Description | 1389| ------------- | ------ | ---- | ---- | ---------------------------------------- | 1390| unit | string | Yes | Yes | Name of the measurement unit, for example, **meter**, **inch**, or **cup**.| 1391| measureSystem | string | Yes | Yes | Measurement system. The value can be **SI**, **US**, or **UK**.| 1392 1393 1394## getInstance<sup>8+</sup> 1395 1396getInstance(locale?:string): IndexUtil 1397 1398Creates an **IndexUtil** object. 1399 1400**System capability**: SystemCapability.Global.I18n 1401 1402**Parameters** 1403 1404| Name | Type | Mandatory | Description | 1405| ------ | ------ | ---- | ---------------------------- | 1406| locale | string | No | A string containing locale information, including the language, optional script, and region. The default value is the system locale.| 1407 1408**Return value** 1409 1410| Type | Description | 1411| ------------------------ | --------------------- | 1412| [IndexUtil](#indexutil8) | **IndexUtil** object mapping to the **locale** object.| 1413 1414**Example** 1415 ```ts 1416 let indexUtil: I18n.IndexUtil = I18n.getInstance("zh-CN"); 1417 ``` 1418 1419 1420## IndexUtil<sup>8+</sup> 1421 1422 1423### getIndexList<sup>8+</sup> 1424 1425getIndexList(): Array<string> 1426 1427Obtains the index list for this **locale** object. 1428 1429**System capability**: SystemCapability.Global.I18n 1430 1431**Return value** 1432 1433| Type | Description | 1434| ------------------- | ------------------ | 1435| Array<string> | Index list for the **locale** object.| 1436 1437**Example** 1438 ```ts 1439 let indexUtil: I18n.IndexUtil = I18n.getInstance("zh-CN"); 1440 // indexList = [ "...", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", 1441 // "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "..." ] 1442 let indexList: Array<string> = indexUtil.getIndexList(); 1443 ``` 1444 1445 1446### addLocale<sup>8+</sup> 1447 1448addLocale(locale: string): void 1449 1450Adds a **locale** object to the current index list. 1451 1452**System capability**: SystemCapability.Global.I18n 1453 1454**Parameters** 1455 1456| Name | Type | Mandatory | Description | 1457| ------ | ------ | ---- | ---------------------------- | 1458| locale | string | Yes | A string containing locale information, including the language, optional script, and region.| 1459 1460**Example** 1461 ```ts 1462 let indexUtil: I18n.IndexUtil = I18n.getInstance("zh-CN"); 1463 indexUtil.addLocale("en-US"); 1464 ``` 1465 1466 1467### getIndex<sup>8+</sup> 1468 1469getIndex(text: string): string 1470 1471Obtains the index of a **text** object. 1472 1473**System capability**: SystemCapability.Global.I18n 1474 1475**Parameters** 1476 1477| Name | Type | Mandatory | Description | 1478| ---- | ------ | ---- | ------------ | 1479| text | string | Yes | **text** object whose index is to be obtained.| 1480 1481**Return value** 1482 1483| Type | Description | 1484| ------ | ----------- | 1485| string | Index of the **text** object.| 1486 1487**Example** 1488 ```ts 1489 let indexUtil: I18n.IndexUtil = I18n.getInstance("zh-CN"); 1490 let index: string = indexUtil.getIndex("hi"); // index = "H" 1491 ``` 1492 1493 1494## I18n.getLineInstance<sup>8+</sup> 1495 1496getLineInstance(locale: string): BreakIterator 1497 1498Obtains a [BreakIterator](#breakiterator8) object for text segmentation. 1499 1500**System capability**: SystemCapability.Global.I18n 1501 1502**Parameters** 1503 1504| Name | Type | Mandatory | Description | 1505| ------ | ------ | ---- | ---------------------------------------- | 1506| 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.| 1507 1508**Return value** 1509 1510| Type | Description | 1511| -------------------------------- | ----------- | 1512| [BreakIterator](#breakiterator8) | [BreakIterator](#breakiterator8) object used for text segmentation.| 1513 1514**Example** 1515 ```ts 1516 let iterator: I18n.BreakIterator = I18n.getLineInstance("en"); 1517 ``` 1518 1519 1520## BreakIterator<sup>8+</sup> 1521 1522 1523### setLineBreakText<sup>8+</sup> 1524 1525setLineBreakText(text: string): void 1526 1527Sets the text to be processed by the **BreakIterator** object. 1528 1529**System capability**: SystemCapability.Global.I18n 1530 1531**Parameters** 1532 1533| Name | Type | Mandatory | Description | 1534| ---- | ------ | ---- | ----------------------- | 1535| text | string | Yes | Text to be processed by the **BreakIterator** object.| 1536 1537**Example** 1538 ```ts 1539 let iterator: I18n.BreakIterator = I18n.getLineInstance("en"); 1540 iterator.setLineBreakText("Apple is my favorite fruit ."); // Set a short sentence as the text to be processed by the BreakIterator object. 1541 ``` 1542 1543 1544### getLineBreakText<sup>8+</sup> 1545 1546getLineBreakText(): string 1547 1548Obtains the text being processed by the **BreakIterator** object. 1549 1550**System capability**: SystemCapability.Global.I18n 1551 1552**Return value** 1553 1554| Type | Description | 1555| ------ | ---------------------- | 1556| string | Text being processed by the **BreakIterator** object.| 1557 1558**Example** 1559 ```ts 1560 let iterator: I18n.BreakIterator = I18n.getLineInstance("en"); 1561 iterator.setLineBreakText("Apple is my favorite fruit."); 1562 let breakText: string = iterator.getLineBreakText(); // breakText = "Apple is my favorite fruit." 1563 ``` 1564 1565 1566### current<sup>8+</sup> 1567 1568current(): number 1569 1570Obtains the position of the **BreakIterator** object in the text being processed. 1571 1572**System capability**: SystemCapability.Global.I18n 1573 1574**Return value** 1575 1576| Type | Description | 1577| ------ | --------------------------- | 1578| number | Position of the **BreakIterator** object in the text being processed.| 1579 1580**Example** 1581 ```ts 1582 let iterator: I18n.BreakIterator = I18n.getLineInstance("en"); 1583 iterator.setLineBreakText("Apple is my favorite fruit."); 1584 let currentPos: number = iterator.current(); // currentPos = 0 1585 ``` 1586 1587 1588### first<sup>8+</sup> 1589 1590first(): number 1591 1592Puts the **BreakIterator** object to the first break point, which is always at the beginning of the processed text. 1593 1594**System capability**: SystemCapability.Global.I18n 1595 1596**Return value** 1597 1598| Type | Description | 1599| ------ | ----------------- | 1600| number | Offset to the first break point of the processed text.| 1601 1602**Example** 1603 ```ts 1604 let iterator: I18n.BreakIterator = I18n.getLineInstance("en"); 1605 iterator.setLineBreakText("Apple is my favorite fruit."); 1606 let firstPos: number = iterator.first(); // firstPos = 0 1607 ``` 1608 1609 1610### last<sup>8+</sup> 1611 1612last(): number 1613 1614Puts the **BreakIterator** object to the last break point, which is always the next position after the end of the processed text. 1615 1616**System capability**: SystemCapability.Global.I18n 1617 1618**Return value** 1619 1620| Type | Description | 1621| ------ | ------------------ | 1622| number | Offset to the last break point of the processed text.| 1623 1624**Example** 1625 ```ts 1626 let iterator: I18n.BreakIterator = I18n.getLineInstance("en"); 1627 iterator.setLineBreakText("Apple is my favorite fruit."); 1628 let lastPos: number = iterator.last(); // lastPos = 27 1629 ``` 1630 1631 1632### next<sup>8+</sup> 1633 1634next(index?: number): number 1635 1636Moves the **BreakIterator** object backward by the corresponding number of break points. 1637 1638**System capability**: SystemCapability.Global.I18n 1639 1640**Parameters** 1641 1642| Name | Type | Mandatory | Description | 1643| ----- | ------ | ---- | ---------------------------------------- | 1644| index | number | No | Number of break points to be moved by the **BreakIterator** object. A positive value indicates that the break point is moved backward by the specified number of break points, and a negative value indicates the opposite. The default value is **1**.| 1645 1646**Return value** 1647 1648| Type | Description | 1649| ------ | ---------------------------------------- | 1650| number | Position of the **BreakIterator** object in the text after it is moved by the specified number of break points. 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 break points.| 1651 1652**Example** 1653 ```ts 1654 let iterator: I18n.BreakIterator = I18n.getLineInstance("en"); 1655 iterator.setLineBreakText("Apple is my favorite fruit."); 1656 let pos: number = iterator.first(); // pos = 0 1657 pos = iterator.next(); // pos = 6 1658 pos = iterator.next(10); // pos = -1 1659 ``` 1660 1661 1662### previous<sup>8+</sup> 1663 1664previous(): number 1665 1666Moves the **BreakIterator** object forward by one break point. 1667 1668**System capability**: SystemCapability.Global.I18n 1669 1670**Return value** 1671 1672| Type | Description | 1673| ------ | ---------------------------------------- | 1674| number | Position of the **BreakIterator** object in the text after it is moved to the previous break point. 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 break points.| 1675 1676**Example** 1677 ```ts 1678 let iterator: I18n.BreakIterator = I18n.getLineInstance("en"); 1679 iterator.setLineBreakText("Apple is my favorite fruit."); 1680 let pos: number = iterator.first(); // pos = 0 1681 pos = iterator.next(3); // pos = 12 1682 pos = iterator.previous(); // pos = 9 1683 ``` 1684 1685 1686### following<sup>8+</sup> 1687 1688following(offset: number): number 1689 1690Moves the **BreakIterator** to the break point following the specified position. 1691 1692**System capability**: SystemCapability.Global.I18n 1693 1694**Parameters** 1695 1696| Name | Type | Mandatory | Description | 1697| ------ | ------ | ---- | ---------------------------------------- | 1698| offset | number | Yes | Moves the **BreakIterator** to the break point following the specified position.| 1699 1700**Return value** 1701 1702| Type | Description | 1703| ------ | ---------------------------------------- | 1704| number | The value **-1** is returned if the break point to which the **BreakIterator** object is moved is outside of the processed text.| 1705 1706**Example** 1707 ```ts 1708 let iterator: I18n.BreakIterator = I18n.getLineInstance("en"); 1709 iterator.setLineBreakText("Apple is my favorite fruit."); 1710 let pos: number = iterator.following(0); // pos = 6 1711 pos = iterator.following(100); // pos = -1 1712 pos = iterator.current(); // pos = 27 1713 ``` 1714 1715 1716### isBoundary<sup>8+</sup> 1717 1718isBoundary(offset: number): boolean 1719 1720Checks whether the specified position of the text is a break point. 1721 1722**System capability**: SystemCapability.Global.I18n 1723 1724**Parameters** 1725 1726| Name | Type | Mandatory | Description | 1727| ------ | ------ | ---- | ----------- | 1728| offset | number | Yes | Offset to the specified position of the text. The value **true** is returned if the position specified by **offset** is a break point, and the value **false** is returned otherwise. If **true** is returned, the **BreakIterator** object is moved to the position specified by **offset**. Otherwise, **following** is called.| 1729 1730**Return value** 1731 1732| Type | Description | 1733| ------- | ------------------------------- | 1734| boolean | The value **true** indicates that the position specified by the offset is a break point, and the value **false** indicates the opposite.| 1735 1736**Example** 1737 ```ts 1738 let iterator: I18n.BreakIterator = I18n.getLineInstance("en"); 1739 iterator.setLineBreakText("Apple is my favorite fruit."); 1740 let isBoundary: boolean = iterator.isBoundary(0); // isBoundary = true; 1741 isBoundary = iterator.isBoundary(5); // isBoundary = false; 1742 ``` 1743 1744 1745## I18n.getTimeZone 1746 1747getTimeZone(zoneID?: string): TimeZone 1748 1749Obtains the **TimeZone** object corresponding to the specified time zone ID. 1750 1751**System capability**: SystemCapability.Global.I18n 1752 1753**Parameters** 1754 1755| Name | Type | Mandatory | Description | 1756| ------ | ------ | ---- | ----- | 1757| zondID | string | No | Time zone ID. The default value is the system time zone.| 1758 1759**Return value** 1760 1761| Type | Description | 1762| -------- | ------------ | 1763| [TimeZone](#timezone) | **TimeZone** object corresponding to the time zone ID.| 1764 1765**Example** 1766 ```ts 1767 let timezone: I18n.TimeZone = I18n.getTimeZone(); 1768 ``` 1769 1770 1771## TimeZone 1772 1773 1774### getID 1775 1776getID(): string 1777 1778Obtains the ID of the specified **TimeZone** object. 1779 1780**System capability**: SystemCapability.Global.I18n 1781 1782**Return value** 1783 1784| Type | Description | 1785| ------ | ------------ | 1786| string | Time zone ID corresponding to the **TimeZone** object.| 1787 1788**Example** 1789 ```ts 1790 let timezone: I18n.TimeZone = I18n.getTimeZone(); 1791 let timezoneID: string = timezone.getID(); // timezoneID = "Asia/Shanghai" 1792 ``` 1793 1794 1795### getDisplayName 1796 1797getDisplayName(locale?: string, isDST?: boolean): string 1798 1799Obtains the localized representation of a **TimeZone** object. 1800 1801**System capability**: SystemCapability.Global.I18n 1802 1803**Parameters** 1804 1805| Name | Type | Mandatory | Description | 1806| ------ | ------- | ---- | -------------------- | 1807| locale | string | No | Locale ID. The default value is the system locale. | 1808| isDST | boolean | No | Whether DST is considered in the localized representation of the **TimeZone** object. The default value is **false**.| 1809 1810**Return value** 1811 1812| Type | Description | 1813| ------ | ------------- | 1814| string | Representation of the **TimeZone** object in the specified locale.| 1815 1816**Example** 1817 ```ts 1818 let timezone: I18n.TimeZone = I18n.getTimeZone(); 1819 let timezoneName: string = timezone.getDisplayName("zh-CN", false); // timezoneName = "China Standard Time" 1820 ``` 1821 1822 1823### getRawOffset 1824 1825getRawOffset(): number 1826 1827Obtains the offset between the time zone represented by a **TimeZone** object and the UTC time zone. 1828 1829**System capability**: SystemCapability.Global.I18n 1830 1831**Return value** 1832 1833| Type | Description | 1834| ------ | ------------------- | 1835| number | Offset between the time zone represented by a **TimeZone** object and the UTC time zone, in milliseconds.| 1836 1837**Example** 1838 ```ts 1839 let timezone: I18n.TimeZone = I18n.getTimeZone(); 1840 let offset: number = timezone.getRawOffset(); // offset = 28800000 1841 ``` 1842 1843 1844### getOffset 1845 1846getOffset(date?: number): number 1847 1848Obtains the offset between the time zone represented by a **TimeZone** object and the UTC time zone at a certain time. 1849 1850**System capability**: SystemCapability.Global.I18n 1851 1852**Parameters** 1853 1854| Name | Type | Mandatory | Description | 1855| ------ | ------ | ---- | ------ | 1856| date | number | No | Time for calculating the offset, in milliseconds. The default value is the system time.| 1857 1858**Return value** 1859 1860| Type | Description | 1861| ------ | ----------------------- | 1862| number | Offset between the time zone represented by the **TimeZone** object and the UTC time zone at a certain time. The default value is the system time.| 1863 1864**Example** 1865 ```ts 1866 let timezone: I18n.TimeZone = I18n.getTimeZone(); 1867 let offset: number = timezone.getOffset(1234567890); // offset = 28800000 1868 ``` 1869 1870 1871### getAvailableIDs<sup>9+</sup> 1872 1873static getAvailableIDs(): Array<string> 1874 1875Obtains the list of time zone IDs supported by the system. 1876 1877**System capability**: SystemCapability.Global.I18n 1878 1879**Return value** 1880 1881| Type | Description | 1882| ------------------- | ----------- | 1883| Array<string> | List of time zone IDs supported by the system.| 1884 1885**Example** 1886 ```ts 1887 // ids = ["America/Adak", "America/Anchorage", "America/Bogota", "America/Denver", "America/Los_Angeles", "America/Montevideo", "America/Santiago", "America/Sao_Paulo", "Asia/Ashgabat", "Asia/Hovd", "Asia/Jerusalem", "Asia/Magadan", "Asia/Omsk", "Asia/Shanghai", "Asia/Tokyo", "Asia/Yerevan", "Atlantic/Cape_Verde", "Australia/Lord_Howe", "Europe/Dublin", "Europe/London", "Europe/Moscow", "Pacific/Auckland", "Pacific/Easter", "Pacific/Pago-Pago"], 24 time zones supported in total 1888 let ids: Array<string> = I18n.TimeZone.getAvailableIDs(); 1889 ``` 1890 1891 1892### getAvailableZoneCityIDs<sup>9+</sup> 1893 1894static getAvailableZoneCityIDs(): Array<string> 1895 1896Obtains the list of time zone city IDs supported by the system. 1897 1898**System capability**: SystemCapability.Global.I18n 1899 1900**Return value** 1901 1902| Type | Description | 1903| ------------------- | ------------- | 1904| Array<string> | List of time zone city IDs supported by the system.| 1905 1906**Example** 1907 ```ts 1908 // cityIDs = ["Auckland", "Magadan", "Lord Howe Island", "Tokyo", "Shanghai", "Hovd", "Omsk", "Ashgabat", "Yerevan", "Moscow", "Tel Aviv", "Dublin", "London", "Praia", "Montevideo", "Brasília", "Santiago", "Bogotá", "Easter Island", "Salt Lake City", "Los Angeles", "Anchorage", "Adak", "Pago Pago"], 24 time zone cities supported in total 1909 let cityIDs: Array<string> = I18n.TimeZone.getAvailableZoneCityIDs(); 1910 ``` 1911 1912 1913### getCityDisplayName<sup>9+</sup> 1914 1915static getCityDisplayName(cityID: string, locale: string): string 1916 1917Obtains the localized representation of a time zone city in the specified locale. 1918 1919**System capability**: SystemCapability.Global.I18n 1920 1921**Parameters** 1922 1923| Name | Type | Mandatory | Description | 1924| ------ | ------ | ---- | ------ | 1925| cityID | string | Yes | Time zone city ID.| 1926| locale | string | Yes | Locale ID. | 1927 1928**Return value** 1929 1930| Type | Description | 1931| ------ | ------------------ | 1932| string | Localized representation of the time zone city in the specified locale.| 1933 1934**Example** 1935 ```ts 1936 let displayName: string = I18n.TimeZone.getCityDisplayName("Shanghai", "zh-CN"); // displayName = "Shanghai (China)" 1937 ``` 1938 1939 1940### getTimezoneFromCity<sup>9+</sup> 1941 1942static getTimezoneFromCity(cityID: string): TimeZone 1943 1944Obtains the **TimeZone** object corresponding to the specified time zone city ID. 1945 1946**System capability**: SystemCapability.Global.I18n 1947 1948**Parameters** 1949 1950| Name | Type | Mandatory | Description | 1951| ------ | ------ | ---- | ------ | 1952| cityID | string | Yes | Time zone city ID.| 1953 1954**Return value** 1955 1956| Type | Description | 1957| -------- | ----------- | 1958| TimeZone | **TimeZone** object corresponding to the specified time zone city ID.| 1959 1960**Example** 1961 ```ts 1962 let timezone: I18n.TimeZone = I18n.TimeZone.getTimezoneFromCity("Shanghai"); 1963 ``` 1964 1965### getTimezonesByLocation<sup>10+</sup> 1966 1967static getTimezonesByLocation(longitude: number, latitude: number): Array<TimeZone> 1968 1969Creates an array of **TimeZone** objects corresponding to the specified longitude and latitude. 1970 1971**System capability**: SystemCapability.Global.I18n 1972 1973**Parameters** 1974 1975| Name | Type | Mandatory | Description | 1976| --------- | ------ | ---- | ------ | 1977| longitude | number | Yes | Longitude. The value ranges from **-180** to **179.9**. A positive value is used for east longitude and a negative value is used for west longitude.| 1978| latitude | number | Yes | Latitude. The value ranges from **-90** to **89.9**. A positive value is used for north latitude and a negative value is used for south latitude.| 1979 1980**Return value** 1981 1982| Type | Description | 1983| -------- | ----------- | 1984| Array<[TimeZone](#timezone)> | Array of **TimeZone** objects.| 1985 1986**Error codes** 1987 1988For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md). 1989 1990| ID | Error Message | 1991| ------ | ---------------------- | 1992| 890001 | param value not valid | 1993 1994**Example** 1995 ```ts 1996 let timezoneArray: Array<I18n.TimeZone> = I18n.TimeZone.getTimezonesByLocation(-118.1, 34.0); 1997 for (let i = 0; i < timezoneArray.length; i++) { 1998 let tzId: string = timezoneArray[i].getID(); 1999 } 2000 ``` 2001 2002 2003## Transliterator<sup>9+</sup> 2004 2005 2006### getAvailableIDs<sup>9+</sup> 2007 2008static getAvailableIDs(): string[] 2009 2010Obtains a list of IDs supported by the **Transliterator** object. 2011 2012**System capability**: SystemCapability.Global.I18n 2013 2014**Return value** 2015 2016| Type | Description | 2017| -------- | ---------- | 2018| string[] | List of IDs supported by the **Transliterator** object.| 2019 2020**Example** 2021 ```ts 2022 // A total of 671 IDs are supported. One ID is comprised of two parts separated by a hyphen (-) in the format of source-destination. For example, in **ids = ["Han-Latin","Latin-ASCII", "Amharic-Latin/BGN","Accents-Any", ...]**, **Han-Latin** indicates conversion from Chinese to Latin, and **Amharic-Latin** indicates conversion from Amharic to Latin. 2023 // For more information, see ISO-15924. 2024 let ids: string[] = I18n.Transliterator.getAvailableIDs(); 2025 ``` 2026 2027 2028### getInstance<sup>9+</sup> 2029 2030static getInstance(id: string): Transliterator 2031 2032Creates a **Transliterator** object. 2033 2034**System capability**: SystemCapability.Global.I18n 2035 2036**Parameters** 2037 2038| Name | Type | Mandatory | Description | 2039| ---- | ------ | ---- | -------- | 2040| id | string | Yes | ID supported by the **Transliterator** object.| 2041 2042**Return value** 2043 2044| Type | Description | 2045| ---------------------------------- | ----- | 2046| [Transliterator](#transliterator9) | **Transliterator** object.| 2047 2048**Example** 2049 ```ts 2050 let transliterator: I18n.Transliterator = I18n.Transliterator.getInstance("Any-Latn"); 2051 ``` 2052 2053 2054### transform<sup>9+</sup> 2055 2056transform(text: string): string 2057 2058Converts the input string from the source format to the target format. 2059 2060**System capability**: SystemCapability.Global.I18n 2061 2062**Parameters** 2063 2064| Name | Type | Mandatory | Description | 2065| ---- | ------ | ---- | ------ | 2066| text | string | Yes | Input string.| 2067 2068**Return value** 2069 2070| Type | Description | 2071| ------ | -------- | 2072| string | Target string.| 2073 2074**Example** 2075 ```ts 2076 let transliterator: I18n.Transliterator = I18n.Transliterator.getInstance("Any-Latn"); 2077 let res: string = transliterator.transform("China"); // res = "zhōng guó" 2078 ``` 2079 2080 2081## Unicode<sup>9+</sup> 2082 2083 2084### isDigit<sup>9+</sup> 2085 2086static isDigit(char: string): boolean 2087 2088Checks whether the input string is composed of digits. 2089 2090**System capability**: SystemCapability.Global.I18n 2091 2092**Parameters** 2093 2094| Name | Type | Mandatory | Description | 2095| ---- | ------ | ---- | ----- | 2096| char | string | Yes | Input character.| 2097 2098**Return value** 2099 2100| Type | Description | 2101| ------- | ------------------------------------ | 2102| boolean | The value **true** indicates that the input character is a digit, and the value **false** indicates the opposite.| 2103 2104**Example** 2105 ```ts 2106 let isdigit: boolean = I18n.Unicode.isDigit("1"); // isdigit = true 2107 ``` 2108 2109 2110### isSpaceChar<sup>9+</sup> 2111 2112static isSpaceChar(char: string): boolean 2113 2114Checks whether the input character is a space. 2115 2116**System capability**: SystemCapability.Global.I18n 2117 2118**Parameters** 2119 2120| Name | Type | Mandatory | Description | 2121| ---- | ------ | ---- | ----- | 2122| char | string | Yes | Input character.| 2123 2124**Return value** 2125 2126| Type | Description | 2127| ------- | -------------------------------------- | 2128| boolean | The value **true** indicates that the input character is a space, and the value **false** indicates the opposite.| 2129 2130**Example** 2131 ```ts 2132 let isspacechar: boolean = I18n.Unicode.isSpaceChar("a"); // isspacechar = false 2133 ``` 2134 2135 2136### isWhitespace<sup>9+</sup> 2137 2138static isWhitespace(char: string): boolean 2139 2140Checks whether the input character is a white space. 2141 2142**System capability**: SystemCapability.Global.I18n 2143 2144**Parameters** 2145 2146| Name | Type | Mandatory | Description | 2147| ---- | ------ | ---- | ----- | 2148| char | string | Yes | Input character.| 2149 2150**Return value** 2151 2152| Type | Description | 2153| ------- | -------------------------------------- | 2154| boolean | The value **true** indicates that the input character is a white space, and the value **false** indicates the opposite.| 2155 2156**Example** 2157 ```ts 2158 let iswhitespace: boolean = I18n.Unicode.isWhitespace("a"); // iswhitespace = false 2159 ``` 2160 2161 2162### isRTL<sup>9+</sup> 2163 2164static isRTL(char: string): boolean 2165 2166Checks whether the input character is of the right to left (RTL) language. 2167 2168**System capability**: SystemCapability.Global.I18n 2169 2170**Parameters** 2171 2172| Name | Type | Mandatory | Description | 2173| ---- | ------ | ---- | ----- | 2174| char | string | Yes | Input character.| 2175 2176**Return value** 2177 2178| Type | Description | 2179| ------- | ---------------------------------------- | 2180| boolean | The value **true** indicates that the input character is of the RTL language, and the value **false** indicates the opposite.| 2181 2182**Example** 2183 ```ts 2184 let isrtl: boolean = I18n.Unicode.isRTL("a"); // isrtl = false 2185 ``` 2186 2187 2188### isIdeograph<sup>9+</sup> 2189 2190static isIdeograph(char: string): boolean 2191 2192Checks whether the input character is an ideographic character. 2193 2194**System capability**: SystemCapability.Global.I18n 2195 2196**Parameters** 2197 2198| Name | Type | Mandatory | Description | 2199| ---- | ------ | ---- | ----- | 2200| char | string | Yes | Input character.| 2201 2202**Return value** 2203 2204| Type | Description | 2205| ------- | ---------------------------------------- | 2206| boolean | The value **true** indicates that the input character is an ideographic character, and the value **false** indicates the opposite.| 2207 2208**Example** 2209 ```ts 2210 let isideograph: boolean = I18n.Unicode.isIdeograph("a"); // isideograph = false 2211 ``` 2212 2213 2214### isLetter<sup>9+</sup> 2215 2216static isLetter(char: string): boolean 2217 2218Checks whether the input character is a letter. 2219 2220**System capability**: SystemCapability.Global.I18n 2221 2222**Parameters** 2223 2224| Name | Type | Mandatory | Description | 2225| ---- | ------ | ---- | ----- | 2226| char | string | Yes | Input character.| 2227 2228**Return value** 2229 2230| Type | Description | 2231| ------- | ------------------------------------ | 2232| boolean | The value **true** indicates that the input character is a letter, and the value **false** indicates the opposite.| 2233 2234**Example** 2235 ```ts 2236 let isletter: boolean = I18n.Unicode.isLetter("a"); // isletter = true 2237 ``` 2238 2239 2240### isLowerCase<sup>9+</sup> 2241 2242static isLowerCase(char: string): boolean 2243 2244Checks whether the input character is a lowercase letter. 2245 2246**System capability**: SystemCapability.Global.I18n 2247 2248**Parameters** 2249 2250| Name | Type | Mandatory | Description | 2251| ---- | ------ | ---- | ----- | 2252| char | string | Yes | Input character.| 2253 2254**Return value** 2255 2256| Type | Description | 2257| ------- | ---------------------------------------- | 2258| boolean | The value **true** indicates that the input character is a lowercase letter, and the value **false** indicates the opposite.| 2259 2260**Example** 2261 ```ts 2262 let islowercase: boolean = I18n.Unicode.isLowerCase("a"); // islowercase = true 2263 ``` 2264 2265 2266### isUpperCase<sup>9+</sup> 2267 2268static isUpperCase(char: string): boolean 2269 2270Checks whether the input character is an uppercase letter. 2271 2272**System capability**: SystemCapability.Global.I18n 2273 2274**Parameters** 2275 2276| Name | Type | Mandatory | Description | 2277| ---- | ------ | ---- | ----- | 2278| char | string | Yes | Input character.| 2279 2280**Return value** 2281 2282| Type | Description | 2283| ------- | ---------------------------------------- | 2284| boolean | The value **true** indicates that the input character is an uppercase letter, and the value **false** indicates the opposite.| 2285 2286**Example** 2287 ```ts 2288 let isuppercase: boolean = I18n.Unicode.isUpperCase("a"); // isuppercase = false 2289 ``` 2290 2291 2292### getType<sup>9+</sup> 2293 2294static getType(char: string): string 2295 2296Obtains the type of the input string. 2297 2298**System capability**: SystemCapability.Global.I18n 2299 2300**Parameters** 2301 2302| Name | Type | Mandatory | Description | 2303| ---- | ------ | ---- | ----- | 2304| char | string | Yes | Input character.| 2305 2306**Return value** 2307 2308| Type | Description | 2309| ------ | ----------- | 2310| string | Type of the input character.| 2311 2312The following table lists only the common types. For more details, see the Unicode Standard. 2313 2314| Name| Value| Description| 2315| ---- | -------- | ---------- | 2316| U_UNASSIGNED | U_UNASSIGNED | Non-category for unassigned and non-character code points.| 2317| U_GENERAL_OTHER_TYPES | U_GENERAL_OTHER_TYPES | Same as **U_UNASSIGNED**.| 2318| U_UPPERCASE_LETTER | U_UPPERCASE_LETTER | Uppercase letter.| 2319| U_LOWERCASE_LETTER | U_LOWERCASE_LETTER | Lowercase letter. | 2320| U_TITLECASE_LETTER | U_TITLECASE_LETTER | Title case letter.| 2321| U_MODIFIER_LETTER | U_MODIFIER_LETTER | Modifier letter.| 2322| U_OTHER_LETTER | U_OTHER_LETTER | Letters other than the uppercase letter, lowercase letter, title case letter, and modifier letter.| 2323| U_NON_SPACING_MARK | U_NON_SPACING_MARK | Non-spacing mark, such as the accent symbol **'** and the variable symbol **#**.| 2324| U_ENCLOSING_MARK | U_ENCLOSING_MARK | Enclosing mark, for example, a circle or a box.| 2325| U_COMBINING_SPACING_MARK | U_COMBINING_SPACING_MARK | Spacing mark, for example, the vowel symbol **[]**.| 2326| U_DECIMAL_DIGIT_NUMBER | U_DECIMAL_DIGIT_NUMBER | Decimal number.| 2327| U_LETTER_NUMBER | U_LETTER_NUMBER | Letter and number (including Roman numeral).| 2328| U_OTHER_NUMBER | U_OTHER_NUMBER | Other numbers, which are used as encryption symbols, marker symbols, or non-Arabic numerals, such as **@**, **#**, **(1)**, and **①**.| 2329| U_SPACE_SEPARATOR | U_SPACE_SEPARATOR | Space separator, for example, a space character, uninterrupted space character, or space character with a fixed width.| 2330| U_LINE_SEPARATOR | U_LINE_SEPARATOR | Line separator.| 2331| U_PARAGRAPH_SEPARATOR | U_PARAGRAPH_SEPARATOR | Paragraph separator.| 2332| U_CONTROL_CHAR | U_CONTROL_CHAR | Control character.| 2333| U_FORMAT_CHAR | U_FORMAT_CHAR | Format character.| 2334| U_PRIVATE_USE_CHAR | U_PRIVATE_USE_CHAR | Privately used character, for example, a company logo.| 2335| U_SURROGATE | U_SURROGATE | Surrogate, which is used to represent supplementary characters in UTF-16.| 2336| U_DASH_PUNCTUATION | U_DASH_PUNCTUATION | Dash punctuation.| 2337| U_START_PUNCTUATION | U_START_PUNCTUATION | Start punctuation, for example, the left parenthesis.| 2338| U_END_PUNCTUATION | U_END_PUNCTUATION | End punctuation, for example, the right parenthesis.| 2339| U_INITIAL_PUNCTUATION | U_INITIAL_PUNCTUATION | Initial punctuation, for example, the left double quotation mark or left single quotation mark.| 2340| U_FINAL_PUNCTUATION | U_FINAL_PUNCTUATION | Final punctuation, for example, the right double quotation mark or right single quotation mark.| 2341| U_CONNECTOR_PUNCTUATION | U_CONNECTOR_PUNCTUATION | Connector punctuation.| 2342| U_OTHER_PUNCTUATION | U_OTHER_PUNCTUATION | Other punctuations.| 2343| U_MATH_SYMBOL | U_MATH_SYMBOL | Mathematical symbol.| 2344| U_CURRENCY_SYMBOL | U_CURRENCY_SYMBOL | Currency symbol.| 2345| U_MODIFIER_SYMBOL | U_MODIFIER_SYMBOL | Modifier symbol.| 2346| U_OTHER_SYMBOL | U_OTHER_SYMBOL | Other symbols.| 2347 2348**Example** 2349 ```ts 2350 let type: string = I18n.Unicode.getType("a"); // type = "U_LOWERCASE_LETTER" 2351 ``` 2352 2353## I18NUtil<sup>9+</sup> 2354 2355 2356### unitConvert<sup>9+</sup> 2357 2358static unitConvert(fromUnit: UnitInfo, toUnit: UnitInfo, value: number, locale: string, style?: string): string 2359 2360Converts one measurement unit into another and formats the unit based on the specified locale and style. 2361 2362**System capability**: SystemCapability.Global.I18n 2363 2364**Parameters** 2365 2366| Name | Type | Mandatory | Description | 2367| -------- | ---------------------- | ---- | ---------------------------------------- | 2368| fromUnit | [UnitInfo](#unitinfo8) | Yes | Measurement unit to be converted. | 2369| toUnit | [UnitInfo](#unitinfo8) | Yes | Measurement unit to be converted to. | 2370| value | number | Yes | Value of the measurement unit to be converted. | 2371| locale | string | Yes | Locale used for formatting, for example, **zh-Hans-CN**. | 2372| style | string | No | Style used for formatting. The value can be **long**, **short**, or **narrow**. The default value is **short**.| 2373 2374**Return value** 2375 2376| Type | Description | 2377| ------ | ----------------------- | 2378| string | String obtained after formatting based on the measurement unit specified by **toUnit**.| 2379 2380**Example** 2381 ```ts 2382 let fromUnit: I18n.UnitInfo = {unit: "cup", measureSystem: "US"}; 2383 let toUnit: I18n.UnitInfo = {unit: "liter", measureSystem: "SI"}; 2384 let res: string = I18n.I18NUtil.unitConvert(fromUnit, toUnit, 1000, "en-US", "long"); // res = 236.588 liters 2385 ``` 2386 2387 2388### getDateOrder<sup>9+</sup> 2389 2390static getDateOrder(locale: string): string 2391 2392Obtains the sequence of the year, month, and day in the specified locale. 2393 2394**System capability**: SystemCapability.Global.I18n 2395 2396**Parameters** 2397 2398| Name | Type | Mandatory | Description | 2399| ------ | ------ | ---- | ------------------------- | 2400| locale | string | Yes | Locale used for formatting, for example, **zh-Hans-CN**.| 2401 2402**Return value** 2403 2404| Type | Description | 2405| ------ | ------------------- | 2406| string | Sequence of the year, month, and day in the locale.| 2407 2408**Example** 2409 ```ts 2410 let order: string = I18n.I18NUtil.getDateOrder("zh-CN"); // order = "y-L-d" 2411 ``` 2412 2413 2414### getTimePeriodName<sup>11+</sup> 2415 2416static getTimePeriodName(hour:number, locale?: string): string 2417 2418Obtains the localized expression for the specified time of the specified locale. 2419 2420**System capability**: SystemCapability.Global.I18n 2421 2422**Parameters** 2423 2424| Name | Type | Mandatory | Description | 2425| ------ | ------ | ---- | ------------------------- | 2426| hour | number | Yes | Specified time, for example, **16**.| 2427| locale | string | No | Specified locale. By default, the locale of the application is used, for example, **zh-Hans-CN**.| 2428 2429**Return value** 2430 2431| Type | Description | 2432| ------ | ------------------- | 2433| string | Localized expression for the specified time of the specified locale.| 2434 2435**Error codes** 2436 2437For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md). 2438 2439| ID | Error Message | 2440| ------ | ---------------------- | 2441| 890001 | param value not valid | 2442 2443**Example** 2444 ```ts 2445 import { BusinessError } from '@ohos.base'; 2446 2447 try { 2448 let name: string = I18n.I18NUtil.getTimePeriodName(2, "zh-CN"); // name = "a.m." 2449 } catch(error) { 2450 let err: BusinessError = error as BusinessError; 2451 console.error(`call I18NUtil.getTimePeriodName failed, error code: ${err.code}, message: ${err.message}.`); 2452 } 2453 ``` 2454 2455 2456## Normalizer<sup>10+</sup> 2457 2458### getInstance<sup>10+</sup> 2459 2460static getInstance(mode: NormalizerMode): Normalizer 2461 2462Obtains a **Normalizer** object for text normalization. 2463 2464**System capability**: SystemCapability.Global.I18n 2465 2466**Parameters** 2467 2468| Name | Type | Mandatory | Description | 2469| ------ | ------ | ---- | ------------------------- | 2470| mode | [NormalizerMode](#normalizermode10) | Yes | Text normalization mode.| 2471 2472**Return value** 2473 2474| Type | Description | 2475| ------ | ------------------- | 2476| [Normalizer](#normalizer10) | **Normalizer** object for text normalization.| 2477 2478**Example** 2479 ```ts 2480 let normalizer: I18n.Normalizer = I18n.Normalizer.getInstance(I18n.NormalizerMode.NFC); 2481 ``` 2482 2483 2484### normalize<sup>10+</sup> 2485 2486normalize(text: string): string 2487 2488Normalizes text strings. 2489 2490**System capability**: SystemCapability.Global.I18n 2491 2492**Parameters** 2493 2494| Name | Type | Mandatory | Description | 2495| ------ | ------ | ---- | ------------------------- | 2496| text | string | Yes | Text strings to be normalized.| 2497 2498**Return value** 2499 2500| Type | Description | 2501| ------ | ------------------- | 2502| string | Normalized text strings.| 2503 2504**Example** 2505 ```ts 2506 let normalizer: I18n.Normalizer = I18n.Normalizer.getInstance(I18n.NormalizerMode.NFC); 2507 let normalizedText: string = normalizer.normalize('\u1E9B\u0323'); // normalizedText = \u1E9B\u0323 2508 ``` 2509 2510 2511## NormalizerMode<sup>10+</sup> 2512 2513Enumerates text normalization modes. 2514 2515**System capability**: SystemCapability.Global.I18n 2516 2517| Name| Value| Description| 2518| -------- | -------- | -------- | 2519| NFC | 1 | NFC.| 2520| NFD | 2 | NFD.| 2521| NFKC | 3 | NFKC.| 2522| NFKD | 4 | NFKD.| 2523 2524 2525## SystemLocaleManager<sup>10+</sup> 2526 2527 2528### constructor<sup>10+</sup> 2529 2530constructor() 2531 2532Creates a **SystemLocaleManager** object. 2533 2534**System API**: This is a system API. 2535 2536**System capability**: SystemCapability.Global.I18n 2537 2538**Example** 2539 ```ts 2540 let systemLocaleManager: I18n.SystemLocaleManager = new I18n.SystemLocaleManager(); 2541 ``` 2542 2543 2544### getLanguageInfoArray<sup>10+</sup> 2545 2546getLanguageInfoArray(languages: Array<string>, options?: SortOptions): Array<LocaleItem> 2547 2548Obtains the language sorting array. 2549 2550**System API**: This is a system API. 2551 2552**System capability**: SystemCapability.Global.I18n 2553 2554**Parameters** 2555 2556| Name | Type | Mandatory| Description | 2557| --------- | ------------- | ---- | ------------- | 2558| languages | Array<string> | Yes | List of languages to be sorted.| 2559| options | [SortOptions](#sortoptions10) | No | Language sorting option.| 2560 2561**Return value** 2562 2563| Type | Description | 2564| ----------------- | -------------------- | 2565| Array<[LocaleItem](#localeitem10)> | Language list after sorting.| 2566 2567**Error codes** 2568 2569For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md). 2570 2571| ID | Error Message | 2572| ------ | ---------------------- | 2573| 890001 | param value not valid | 2574 2575**Example** 2576 ```ts 2577 import { BusinessError } from '@ohos.base'; 2578 2579 // Assume that the system language is zh-Hans, the system region is CN, and the system locale is zh-Hans-CN. 2580 let systemLocaleManager: I18n.SystemLocaleManager = new I18n.SystemLocaleManager(); 2581 let languages: string[] = ["zh-Hans", "en-US", "pt", "ar"]; 2582 let sortOptions: I18n.SortOptions = {locale: "zh-Hans-CN", isUseLocalName: true, isSuggestedFirst: true}; 2583 try { 2584 // The language list after sorting is [zh-Hans, en-US, pt, ar]. 2585 let sortedLanguages: Array<I18n.LocaleItem> = systemLocaleManager.getLanguageInfoArray(languages, sortOptions); 2586 } catch(error) { 2587 let err: BusinessError = error as BusinessError; 2588 console.error(`call systemLocaleManager.getLanguageInfoArray failed, error code: ${err.code}, message: ${err.message}.`); 2589 } 2590 ``` 2591 2592 2593### getRegionInfoArray<sup>10+</sup> 2594 2595getRegionInfoArray(regions: Array<string>, options?: SortOptions): Array<LocaleItem> 2596 2597Obtains the country/region sorting array. 2598 2599**System API**: This is a system API. 2600 2601**System capability**: SystemCapability.Global.I18n 2602 2603**Parameters** 2604 2605| Name | Type | Mandatory| Description | 2606| --------- | ------------- | ---- | ------------- | 2607| regions | Array<string> | Yes | List of countries/regions to be sorted.| 2608| options | [SortOptions](#sortoptions10) | No | Country/region sorting option. The default value of **locale** is the system locale, the default value of **isUseLocalName** is **false**, and the default value of **isSuggestedFirst** is **true**.| 2609 2610**Return value** 2611 2612| Type | Description | 2613| ----------------- | -------------------- | 2614| Array<[LocaleItem](#localeitem10)> | Country/region list after sorting.| 2615 2616**Error codes** 2617 2618For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md). 2619 2620| ID | Error Message | 2621| ------ | ---------------------- | 2622| 890001 | param value not valid | 2623 2624**Example** 2625 ```ts 2626 import { BusinessError } from '@ohos.base'; 2627 2628 // Assume that the system language is zh-Hans, the system region is CN, and the system locale is zh-Hans-CN. 2629 let systemLocaleManager: I18n.SystemLocaleManager = new I18n.SystemLocaleManager(); 2630 let regions: string[] = ["CN", "US", "PT", "EG"]; 2631 let sortOptions: I18n.SortOptions = {locale: "zh-Hans-CN", isUseLocalName: false, isSuggestedFirst: true}; 2632 try { 2633 // The country/region list after sorting is [CN, EG, US, PT]. 2634 let sortedRegions: Array<I18n.LocaleItem> = systemLocaleManager.getRegionInfoArray(regions, sortOptions); 2635 } catch(error) { 2636 let err: BusinessError = error as BusinessError; 2637 console.error(`call systemLocaleManager.getRegionInfoArray failed, error code: ${err.code}, message: ${err.message}.`); 2638 } 2639 ``` 2640 2641### getTimeZoneCityItemArray<sup>10+</sup> 2642 2643static getTimeZoneCityItemArray(): Array<TimeZoneCityItem> 2644 2645Obtains the array of time zone city items after sorting. 2646 2647**System API**: This is a system API. 2648 2649**System capability**: SystemCapability.Global.I18n 2650 2651**Return value** 2652 2653| Type | Description | 2654| ----------------- | -------------------- | 2655| Array<[TimeZoneCityItem](#timezonecityitem10)> | Array of time zone city items.| 2656 2657**Example** 2658 ```ts 2659 import { BusinessError } from '@ohos.base'; 2660 2661 try { 2662 let timeZoneCityItemArray: Array<I18n.TimeZoneCityItem> = I18n.SystemLocaleManager.getTimeZoneCityItemArray(); 2663 for (let i = 0; i < timeZoneCityItemArray.length; i++) { 2664 console.log(timeZoneCityItemArray[i].zoneId + ", " + timeZoneCityItemArray[i].cityId + ", " + timeZoneCityItemArray[i].cityDisplayName + 2665 ", " + timeZoneCityItemArray[i].offset + "\r\n"); 2666 } 2667 } catch(error) { 2668 let err: BusinessError = error as BusinessError; 2669 console.error(`call SystemLocaleManager.getTimeZoneCityItemArray failed, error code: ${err.code}, message: ${err.message}.`); 2670 } 2671 ``` 2672 2673## LocaleItem<sup>10+</sup> 2674 2675Represents the list of languages or countries/regions sorted by **SystemLocaleManager**. 2676 2677**System API**: This is a system API. 2678 2679**System capability**: SystemCapability.Global.I18n 2680 2681| Name | Type | Mandatory | Description | 2682| --------------- | --------------- | ------ | --------------------------------------- | 2683| id | string | Yes | Language code or country/region code, for example, **zh** or **CN**. | 2684| suggestionType | [SuggestionType](#suggestiontype10) | Yes | Language or country/region suggestion type. | 2685| displayName | string | Yes | Displayed name of ID in the locale of **SystemLocaleManager**.| 2686| localName | string | No | Local name of the ID. | 2687 2688## TimeZoneCityItem<sup>10+</sup> 2689 2690Represents the time zone and city combination information. 2691 2692**System API**: This is a system API. 2693 2694**System capability**: SystemCapability.Global.I18n 2695 2696| Name | Type | Mandatory | Description | 2697| --------------- | --------------- | ------ | --------------------------------------- | 2698| zoneId | string | Yes | Time zone ID, for example, **Asia/Shanghai**. | 2699| cityId | string | Yes | City ID, for example, **Shanghai**. | 2700| cityDisplayName | string | Yes | Displayed name of the city ID in the system locale. | 2701| offset | int | Yes | Offset of the time zone ID. | 2702| zoneDisplayName | string | Yes | Displayed name of the time zone ID in the system locale. | 2703| rawOffset | int | No | Fixed offset of the time zone ID. | 2704 2705 2706## SuggestionType<sup>10+</sup> 2707 2708Represents the language or country/region suggestion type. 2709 2710**System API**: This is a system API. 2711 2712**System capability**: SystemCapability.Global.I18n 2713 2714| Name | Value | Description | 2715| ---------------------- | ---- | ---- | 2716| SUGGESTION_TYPE_NONE | 0x00 | Not a recommended language or country/region.| 2717| SUGGESTION_TYPE_RELATED| 0x01 | Country/region recommended by the system language or language recommended by the system country/region.| 2718| SUGGESTION_TYPE_SIM | 0x02 | Language recommended by the country/region of the SIM card.| 2719 2720 2721## SortOptions<sup>10+<sup> 2722 2723Represents the language or country/region sorting option. 2724 2725**System API**: This is a system API. 2726 2727**System capability**: SystemCapability.Global.I18n 2728 2729| Name | Type | Mandatory| Description | 2730| --------------- | --------------- | ---- | --------------------------------------- | 2731| locale | string | No | System locale, for example, **zh-Hans-CN**. The default value of **locale** is the system locale. | 2732| isUseLocalName | boolean | No | Whether to use the local name for sorting. If **getLanguageInfoArray** is called, the default value of **isUseLocalName** is **true**. If **getRegionInfoArray** is called, the default value of **isUseLocalName** is **false**. | 2733| isSuggestedFirst | boolean | No | Whether to move the recommended language or country/region to the top in the sorting result. The default value of **isSuggestedFirst** is **true**. | 2734 2735 2736## HolidayManager<sup>11+</sup> 2737 2738### constructor<sup>11+</sup> 2739 2740constructor(icsPath: String) 2741 2742Creates a **HolidayManager** object. 2743 2744**System capability**: SystemCapability.Global.I18n 2745 2746**Parameters** 2747 2748| Name | Type | Mandatory| Description | 2749| --------- | ------------- | ---- | ------------- | 2750| icsPath | String | Yes | Path of the **.ics** file with the read permission granted for applications. | 2751 2752**Error codes** 2753 2754For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md). 2755 2756| ID | Error Message | 2757| ------ | ---------------------- | 2758| 890001 | param value not valid | 2759 2760**Example** 2761 ```ts 2762 let holidayManager= new I18n.HolidayManager("/system/lib/US.ics"); 2763 ``` 2764 2765### isHoliday<sup>11+</sup> 2766 2767isHoliday(date?: Date): boolean 2768 2769Determines whether the specified date is a holiday. 2770 2771**System capability**: SystemCapability.Global.I18n 2772 2773**Parameters** 2774 2775| Name | Type | Mandatory| Description | 2776| --------- | ---------------| ---- | ------------- | 2777| date | Date | No | **Date** object.<br>If no date is specified, the current date is used by default.| 2778 2779**Return value** 2780 2781| Type | Description | 2782| ----------------- | ----------------------| 2783| boolean | The value **true** indicates that the specified date is a holiday, and the value **false** indicates the opposite.| 2784 2785**Example** 2786 ```ts 2787 import { BusinessError } from '@ohos.base'; 2788 2789 try { 2790 let holidayManager= new I18n.HolidayManager("/system/lib/US.ics"); 2791 let isHoliday = holidayManager.isHoliday(); 2792 console.log(isHoliday.toString()); 2793 let isHoliday2 = holidayManager.isHoliday(new Date(2023,5,25)); 2794 console.log(isHoliday2.toString()); 2795 } catch(error) { 2796 let err: BusinessError = error as BusinessError; 2797 console.error(`call holidayManager.isHoliday failed, error code: ${err.code}, message: ${err.message}.`); 2798 } 2799 ``` 2800 2801 2802### getHolidayInfoItemArray<sup>11+</sup> 2803 2804getHolidayInfoItemArray(year?: number): Array<[HolidayInfoItem](#holidayinfoitem11)> 2805 2806Obtains the holiday information list of the specified year. 2807 2808**System capability**: SystemCapability.Global.I18n 2809 2810**Parameters** 2811 2812| Name | Type | Mandatory| Description | 2813| --------- | ------------- | ---- | ------------- | 2814| year | number | No | Specified year, for example, 2023.<br>If no year is specified, the current year is used by default.| 2815 2816**Return value** 2817 2818| Type | Description | 2819| ----------------- | -------------------- | 2820| Array<[HolidayInfoItem](#holidayinfoitem11)> | Holiday information list.| 2821 2822**Error codes** 2823 2824For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md). 2825 2826| ID | Error Message | 2827| ------ | ---------------------- | 2828| 890001 | param value not valid | 2829 2830**Example** 2831 ```ts 2832 import { BusinessError } from '@ohos.base'; 2833 2834 try { 2835 let holidayManager= new I18n.HolidayManager("/system/lib/US.ics"); 2836 let holidayInfoItemArray = holidayManager.getHolidayInfoItemArray(2023); 2837 for (let i =0 ;i < holidayInfoItemArray.length; i++) { 2838 console.log(JSON.stringify(holidayInfoItemArray[i])); 2839 } 2840 } catch(error) { 2841 let err: BusinessError = error as BusinessError; 2842 console.error(`call holidayManager.getHolidayInfoItemArray failed, error code: ${err.code}, message: ${err.message}.`); 2843 } 2844 ``` 2845 2846## HolidayInfoItem<sup>11+</sup> 2847 2848Represents the holiday information. 2849 2850**System capability**: SystemCapability.Global.I18n 2851 2852| Name | Type | Mandatory | Description | 2853| --------------- | --------------- | ------ | --------------------------------------- | 2854| baseName | string | Yes | Holiday name. | 2855| year | number | Yes | Year of the holiday. | 2856| month | number | Yes | Month of the holiday. | 2857| day | number | Yes | Day of the holiday. | 2858| localNames | Array<[HolidayLocalName](#holidaylocalname11)> | No | Local names of the holiday. | 2859 2860## HolidayLocalName<sup>11+</sup> 2861 2862Defines the local names of a holiday. 2863 2864**System capability**: SystemCapability.Global.I18n 2865 2866| Name | Type | Mandatory | Description | 2867| --------------- | -----------------| ------ | --------------------------------------- | 2868| language | string | Yes | Local language of a holiday, for example, **ar**, **en**, or **tr**. | 2869| name | string | Yes | Local name of a holiday. For example, the Turkish name of Sacrifice Feast is Kurban Bayrami. | 2870 2871 2872## I18n.getDisplayCountry<sup>(deprecated)</sup> 2873 2874getDisplayCountry(country: string, locale: string, sentenceCase?: boolean): string 2875 2876Obtains the localized script for the specified country. 2877 2878This API is deprecated since API version 9. You are advised to use [System.getDisplayCountry](#getdisplaycountry9). 2879 2880**System capability**: SystemCapability.Global.I18n 2881 2882**Parameters** 2883 2884| Name | Type | Mandatory | Description | 2885| ------------ | ------- | ---- | ---------------- | 2886| country | string | Yes | Specified country. | 2887| locale | string | Yes | Locale ID. | 2888| sentenceCase | boolean | No | Whether to use sentence case for the localized script. The default value is **true**.| 2889 2890**Return value** 2891 2892| Type | Description | 2893| ------ | ------------- | 2894| string | Localized script for the specified country.| 2895 2896**Example** 2897 ```ts 2898 let countryName: string = I18n.getDisplayCountry("zh-CN", "en-GB", true); // countryName = true 2899 countryName = I18n.getDisplayCountry("zh-CN", "en-GB"); // countryName = true 2900 ``` 2901 2902 2903## I18n.getDisplayLanguage<sup>(deprecated)</sup> 2904 2905getDisplayLanguage(language: string, locale: string, sentenceCase?: boolean): string 2906 2907Obtains the localized script for the specified language. 2908 2909This API is deprecated since API version 9. You are advised to use [System.getDisplayLanguage](#getdisplaylanguage9). 2910 2911**System capability**: SystemCapability.Global.I18n 2912 2913**Parameters** 2914 2915| Name | Type | Mandatory | Description | 2916| ------------ | ------- | ---- | ---------------- | 2917| language | string | Yes | Specified language. | 2918| locale | string | Yes | Locale ID. | 2919| sentenceCase | boolean | No | Whether to use sentence case for the localized script. The default value is **true**.| 2920 2921**Return value** 2922 2923| Type | Description | 2924| ------ | ------------- | 2925| string | Localized script for the specified language.| 2926 2927**Example** 2928 ```ts 2929 let languageName: string = I18n.getDisplayLanguage("zh", "en-GB", true); // languageName = "Chinese" 2930 languageName = I18n.getDisplayLanguage("zh", "en-GB"); // languageName = "Chinese" 2931 ``` 2932 2933 2934## I18n.getSystemLanguage<sup>(deprecated)</sup> 2935 2936getSystemLanguage(): string 2937 2938Obtains the system language. 2939 2940This API is deprecated since API version 9. You are advised to use [System.getSystemLanguage](#getsystemlanguage9). 2941 2942**System capability**: SystemCapability.Global.I18n 2943 2944**Return value** 2945 2946| Type | Description | 2947| ------ | ------- | 2948| string | System language ID.| 2949 2950**Example** 2951 ```ts 2952 let systemLanguage: string = I18n.getSystemLanguage(); // Obtain the current system language. 2953 ``` 2954 2955 2956## I18n.getSystemRegion<sup>(deprecated)</sup> 2957 2958getSystemRegion(): string 2959 2960Obtains the system region. 2961 2962This API is deprecated since API version 9. You are advised to use [System.getSystemRegion](#getsystemregion9). 2963 2964**System capability**: SystemCapability.Global.I18n 2965 2966**Return value** 2967 2968| Type | Description | 2969| ------ | ------- | 2970| string | System region ID.| 2971 2972**Example** 2973 ```ts 2974 let region: string = I18n.getSystemRegion(); // Obtain the current system region. 2975 ``` 2976 2977 2978## I18n.getSystemLocale<sup>(deprecated)</sup> 2979 2980getSystemLocale(): string 2981 2982Obtains the system locale. 2983 2984This API is deprecated since API version 9. You are advised to use [System.getSystemLocale](#getsystemlocale9). 2985 2986**System capability**: SystemCapability.Global.I18n 2987 2988**Return value** 2989 2990| Type | Description | 2991| ------ | ------- | 2992| string | System locale ID.| 2993 2994**Example** 2995 ```ts 2996 let locale: string = I18n.getSystemLocale (); // Obtain the system locale. 2997 ``` 2998 2999 3000## I18n.is24HourClock<sup>(deprecated)</sup> 3001 3002is24HourClock(): boolean 3003 3004Checks whether the 24-hour clock is used. 3005 3006This API is deprecated since API version 9. You are advised to use [System.is24HourClock](#is24hourclock9). 3007 3008**System capability**: SystemCapability.Global.I18n 3009 3010**Return value** 3011 3012| Type | Description | 3013| ------- | ---------------------------------------- | 3014| boolean | The value **true** indicates that the 24-hour clock is used, and the value **false** indicates the opposite.| 3015 3016**Example** 3017 ```ts 3018 let is24HourClock: boolean = I18n.is24HourClock(); 3019 ``` 3020 3021 3022## I18n.set24HourClock<sup>(deprecated)</sup> 3023 3024set24HourClock(option: boolean): boolean 3025 3026Sets the 24-hour clock. 3027 3028This API is deprecated since API version 9. You are advised to use [System.set24HourClock](#set24hourclock9). 3029 3030**Permission required**: ohos.permission.UPDATE_CONFIGURATION 3031 3032**System capability**: SystemCapability.Global.I18n 3033 3034**Parameters** 3035 3036| Name | Type | Mandatory | Description | 3037| ------ | ------- | ---- | ---------------------------------------- | 3038| 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.| 3039 3040**Return value** 3041 3042| Type | Description | 3043| ------- | ----------------------------- | 3044| boolean | The value **true** indicates that the 24-hour clock is enabled, and the value **false** indicates the opposite.| 3045 3046**Example** 3047 ```ts 3048 // Set the system time to the 24-hour clock. 3049 let success: boolean = I18n.set24HourClock(true); 3050 ``` 3051 3052 3053## I18n.addPreferredLanguage<sup>(deprecated)</sup> 3054 3055addPreferredLanguage(language: string, index?: number): boolean 3056 3057Adds a preferred language to the specified position on the preferred language list. 3058 3059This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [System.addPreferredLanguage](#addpreferredlanguage9). 3060 3061**Permission required**: ohos.permission.UPDATE_CONFIGURATION 3062 3063**System capability**: SystemCapability.Global.I18n 3064 3065**Parameters** 3066 3067| Name | Type | Mandatory | Description | 3068| -------- | ------ | ---- | ---------- | 3069| language | string | Yes | Preferred language to add. | 3070| index | number | No | Position to which the preferred language is added. The default value is the length of the preferred language list.| 3071 3072**Return value** 3073 3074| Type | Description | 3075| ------- | ----------------------------- | 3076| boolean | The value **true** indicates that the preferred language is successfully added, and the value **false** indicates the opposite.| 3077 3078**Example** 3079 ```ts 3080 // Add zh-CN to the preferred language list. 3081 let language: string = 'zh-CN'; 3082 let index: number = 0; 3083 let success: boolean = I18n.addPreferredLanguage(language, index); 3084 ``` 3085 3086 3087## I18n.removePreferredLanguage<sup>(deprecated)</sup> 3088 3089removePreferredLanguage(index: number): boolean 3090 3091Deletes a preferred language from the specified position on the preferred language list. 3092 3093This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [System.removePreferredLanguage](#removepreferredlanguage9). 3094 3095**Permission required**: ohos.permission.UPDATE_CONFIGURATION 3096 3097**System capability**: SystemCapability.Global.I18n 3098 3099**Parameters** 3100 3101| Name | Type | Mandatory | Description | 3102| ----- | ------ | ---- | --------------------- | 3103| index | number | Yes | Position of the preferred language to delete.| 3104 3105**Return value** 3106 3107| Type | Description | 3108| ------- | ----------------------------- | 3109| boolean | The value **true** indicates that the preferred language is deleted, and the value **false** indicates the opposite.| 3110 3111**Example** 3112 ```ts 3113 // Delete the first preferred language from the preferred language list. 3114 let index: number = 0; 3115 let success: boolean = I18n.removePreferredLanguage(index); 3116 ``` 3117 3118 3119## I18n.getPreferredLanguageList<sup>(deprecated)</sup> 3120 3121getPreferredLanguageList(): Array<string> 3122 3123Obtains the list of preferred languages. 3124 3125This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [System.getPreferredLanguageList](#getpreferredlanguagelist9). 3126 3127**System capability**: SystemCapability.Global.I18n 3128 3129**Return value** 3130 3131| Type | Description | 3132| ------------------- | --------- | 3133| Array<string> | List of preferred languages.| 3134 3135**Example** 3136 ```ts 3137 let preferredLanguageList: Array<string> = I18n.getPreferredLanguageList(); // Obtain the preferred language list. 3138 ``` 3139 3140 3141## I18n.getFirstPreferredLanguage<sup>(deprecated)</sup> 3142 3143getFirstPreferredLanguage(): string 3144 3145Obtains the first language in the preferred language list. 3146 3147This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [System.getFirstPreferredLanguage](#getfirstpreferredlanguage9). 3148 3149**System capability**: SystemCapability.Global.I18n 3150 3151**Return value** 3152 3153| Type | Description | 3154| ------ | -------------- | 3155| string | First language in the preferred language list.| 3156 3157**Example** 3158 ```ts 3159 let firstPreferredLanguage: string = I18n.getFirstPreferredLanguage(); 3160 ``` 3161 3162 3163## Util<sup>(deprecated)</sup> 3164 3165 3166### unitConvert<sup>(deprecated)</sup> 3167 3168unitConvert(fromUnit: UnitInfo, toUnit: UnitInfo, value: number, locale: string, style?: string): string 3169 3170Converts one measurement unit into another and formats the unit based on the specified locale and style. 3171 3172This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [unitConvert](#unitconvert9). 3173 3174**System capability**: SystemCapability.Global.I18n 3175 3176**Parameters** 3177 3178| Name | Type | Mandatory | Description | 3179| -------- | ---------------------- | ---- | ---------------------------------------- | 3180| fromUnit | [UnitInfo](#unitinfo8) | Yes | Measurement unit to be converted. | 3181| toUnit | [UnitInfo](#unitinfo8) | Yes | Measurement unit to be converted to. | 3182| value | number | Yes | Value of the measurement unit to be converted. | 3183| locale | string | Yes | Locale used for formatting, for example, **zh-Hans-CN**. | 3184| style | string | No | Style used for formatting. The value can be **long**, **short**, or **narrow**. The default value is **short**.| 3185 3186**Return value** 3187 3188| Type | Description | 3189| ------ | ----------------------- | 3190| string | String obtained after formatting based on the measurement unit specified by **toUnit**.| 3191 3192 3193## Character<sup>(deprecated)</sup> 3194 3195 3196### isDigit<sup>(deprecated)</sup> 3197 3198isDigit(char: string): boolean 3199 3200Checks whether the input string is composed of digits. 3201 3202This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [isDigit](#isdigit9). 3203 3204**System capability**: SystemCapability.Global.I18n 3205 3206**Parameters** 3207 3208| Name | Type | Mandatory | Description | 3209| ---- | ------ | ---- | ----- | 3210| char | string | Yes | Input character.| 3211 3212**Return value** 3213 3214| Type | Description | 3215| ------- | ------------------------------------ | 3216| boolean | The value **true** indicates that the input character is a digit, and the value **false** indicates the opposite.| 3217 3218 3219### isSpaceChar<sup>(deprecated)</sup> 3220 3221isSpaceChar(char: string): boolean 3222 3223Checks whether the input character is a space. 3224 3225This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [isSpaceChar](#isspacechar9). 3226 3227**System capability**: SystemCapability.Global.I18n 3228 3229**Parameters** 3230 3231| Name | Type | Mandatory | Description | 3232| ---- | ------ | ---- | ----- | 3233| char | string | Yes | Input character.| 3234 3235**Return value** 3236 3237| Type | Description | 3238| ------- | -------------------------------------- | 3239| boolean | The value **true** indicates that the input character is a space, and the value **false** indicates the opposite.| 3240 3241 3242### isWhitespace<sup>(deprecated)</sup> 3243 3244isWhitespace(char: string): boolean 3245 3246Checks whether the input character is a white space. 3247 3248This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [isWhitespace](#iswhitespace9). 3249 3250**System capability**: SystemCapability.Global.I18n 3251 3252**Parameters** 3253 3254| Name | Type | Mandatory | Description | 3255| ---- | ------ | ---- | ----- | 3256| char | string | Yes | Input character.| 3257 3258**Return value** 3259 3260| Type | Description | 3261| ------- | -------------------------------------- | 3262| boolean | The value **true** indicates that the input character is a white space, and the value **false** indicates the opposite.| 3263 3264 3265### isRTL<sup>(deprecated)</sup> 3266 3267isRTL(char: string): boolean 3268 3269Checks whether the input character is of the right to left (RTL) language. 3270 3271This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [isRTL](#isrtl9). 3272 3273**System capability**: SystemCapability.Global.I18n 3274 3275**Parameters** 3276 3277| Name | Type | Mandatory | Description | 3278| ---- | ------ | ---- | ----- | 3279| char | string | Yes | Input character.| 3280 3281**Return value** 3282 3283| Type | Description | 3284| ------- | ---------------------------------------- | 3285| boolean | The value **true** indicates that the input character is of the RTL language, and the value **false** indicates the opposite.| 3286 3287 3288### isIdeograph<sup>(deprecated)</sup> 3289 3290isIdeograph(char: string): boolean 3291 3292Checks whether the input character is an ideographic character. 3293 3294This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [isIdeograph](#isideograph9). 3295 3296**System capability**: SystemCapability.Global.I18n 3297 3298**Parameters** 3299 3300| Name | Type | Mandatory | Description | 3301| ---- | ------ | ---- | ----- | 3302| char | string | Yes | Input character.| 3303 3304**Return value** 3305 3306| Type | Description | 3307| ------- | ---------------------------------------- | 3308| boolean | The value **true** indicates that the input character is an ideographic character, and the value **false** indicates the opposite.| 3309 3310 3311### isLetter<sup>(deprecated)</sup> 3312 3313isLetter(char: string): boolean 3314 3315Checks whether the input character is a letter. 3316 3317This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [isLetter](#isletter9). 3318 3319**System capability**: SystemCapability.Global.I18n 3320 3321**Parameters** 3322 3323| Name | Type | Mandatory | Description | 3324| ---- | ------ | ---- | ----- | 3325| char | string | Yes | Input character.| 3326 3327**Return value** 3328 3329| Type | Description | 3330| ------- | ------------------------------------ | 3331| boolean | The value **true** indicates that the input character is a letter, and the value **false** indicates the opposite.| 3332 3333 3334### isLowerCase<sup>(deprecated)</sup> 3335 3336isLowerCase(char: string): boolean 3337 3338Checks whether the input character is a lowercase letter. 3339 3340This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [isLowerCase](#islowercase9). 3341 3342**System capability**: SystemCapability.Global.I18n 3343 3344**Parameters** 3345 3346| Name | Type | Mandatory | Description | 3347| ---- | ------ | ---- | ----- | 3348| char | string | Yes | Input character.| 3349 3350**Return value** 3351 3352| Type | Description | 3353| ------- | ---------------------------------------- | 3354| boolean | The value **true** indicates that the input character is a lowercase letter, and the value **false** indicates the opposite.| 3355 3356 3357### isUpperCase<sup>(deprecated)</sup> 3358 3359isUpperCase(char: string): boolean 3360 3361Checks whether the input character is an uppercase letter. 3362 3363This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [isUpperCase](#isuppercase9). 3364 3365**System capability**: SystemCapability.Global.I18n 3366 3367**Parameters** 3368 3369| Name | Type | Mandatory | Description | 3370| ---- | ------ | ---- | ----- | 3371| char | string | Yes | Input character.| 3372 3373**Return value** 3374 3375| Type | Description | 3376| ------- | ---------------------------------------- | 3377| boolean | The value **true** indicates that the input character is an uppercase letter, and the value **false** indicates the opposite.| 3378 3379 3380### getType<sup>(deprecated)</sup> 3381 3382getType(char: string): string 3383 3384Obtains the type of the input string. 3385 3386This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [getType](#gettype9). 3387 3388**System capability**: SystemCapability.Global.I18n 3389 3390**Parameters** 3391 3392| Name | Type | Mandatory | Description | 3393| ---- | ------ | ---- | ----- | 3394| char | string | Yes | Input character.| 3395 3396**Return value** 3397 3398| Type | Description | 3399| ------ | ----------- | 3400| string | Type of the input character.| 3401