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