js-apis-i18n.md 77.5 KB
Newer Older
S
shawn_he 已提交
1
# @ohos.i18n (Internationalization)
Z
zengyawen 已提交
2

S
shawn_he 已提交
3
 The **i18n** 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.
S
shawn_he 已提交
4
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.
S
shawn_he 已提交
5

S
shawn_he 已提交
6
>  **NOTE**
S
shawn_he 已提交
7 8 9 10
>  - The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
>  - This module provides system-related or enhanced i18n capabilities, such as locale management, phone number formatting, and calendar, through supplementary i18n APIs that are not defined in ECMA 402. For details about the basic i18n capabilities, see [intl](js-apis-intl.md).

S
shawn_he 已提交
11 12

## Modules to Import
Z
zengyawen 已提交
13

S
shawn_he 已提交
14
```js
S
shawn_he 已提交
15
import I18n from '@ohos.i18n';
Z
zengyawen 已提交
16 17 18
```


S
shawn_he 已提交
19
## System<sup>9+</sup>
Z
zengyawen 已提交
20

S
shawn_he 已提交
21
### getDisplayCountry<sup>9+</sup>
Z
zengyawen 已提交
22

S
shawn_he 已提交
23 24 25
static getDisplayCountry(country: string, locale: string, sentenceCase?: boolean): string

Obtains the localized script for the specified country.
Z
zengyawen 已提交
26

S
shawn_he 已提交
27 28
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
29
**Parameters**
S
shawn_he 已提交
30

S
shawn_he 已提交
31 32
| Name         | Type     | Mandatory  | Description              |
| ------------ | ------- | ---- | ---------------- |
S
shawn_he 已提交
33
| country      | string  | Yes   | Specified country.           |
S
shawn_he 已提交
34 35
| locale       | string  | Yes   | Locale ID.    |
| sentenceCase | boolean | No   | Whether to use sentence case for the localized script.|
S
shawn_he 已提交
36

S
shawn_he 已提交
37
**Return value**
S
shawn_he 已提交
38

S
shawn_he 已提交
39 40
| Type    | Description           |
| ------ | ------------- |
S
shawn_he 已提交
41 42 43 44
| string | Localized script for the specified country.|

**Error codes**

S
shawn_he 已提交
45
For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
S
shawn_he 已提交
46

S
shawn_he 已提交
47 48 49
| ID | Error Message                  |
| ------ | ---------------------- |
| 890001 | Unspported para value. |
S
shawn_he 已提交
50

S
shawn_he 已提交
51
**Example**
S
shawn_he 已提交
52
  ```js
S
shawn_he 已提交
53
  try {
S
shawn_he 已提交
54
    let displayCountry = I18n.System.getDisplayCountry("zh-CN", "en-GB"); // displayCountry = "China"
S
shawn_he 已提交
55
  } catch(error) {
S
shawn_he 已提交
56
    console.error(`call System.getDisplayCountry failed, error code: ${error.code}, message: ${error.message}.`);
S
shawn_he 已提交
57
  }
S
shawn_he 已提交
58 59
  ```

S
shawn_he 已提交
60
### getDisplayLanguage<sup>9+</sup>
S
shawn_he 已提交
61

S
shawn_he 已提交
62
static getDisplayLanguage(language: string, locale: string, sentenceCase?: boolean): string
Z
zengyawen 已提交
63

S
shawn_he 已提交
64
Obtains the localized script for the specified language.
Z
zengyawen 已提交
65

S
shawn_he 已提交
66 67
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
68
**Parameters**
S
shawn_he 已提交
69

S
shawn_he 已提交
70 71
| Name         | Type     | Mandatory  | Description              |
| ------------ | ------- | ---- | ---------------- |
S
shawn_he 已提交
72
| language     | string  | Yes   | Specified language.           |
S
shawn_he 已提交
73 74
| locale       | string  | Yes   | Locale ID.    |
| sentenceCase | boolean | No   | Whether to use sentence case for the localized script.|
S
shawn_he 已提交
75

S
shawn_he 已提交
76
**Return value**
S
shawn_he 已提交
77

S
shawn_he 已提交
78 79
| Type    | Description           |
| ------ | ------------- |
S
shawn_he 已提交
80 81 82 83
| string | Localized script for the specified language.|

**Error codes**

S
shawn_he 已提交
84
For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
S
shawn_he 已提交
85

S
shawn_he 已提交
86 87 88
| ID | Error Message                  |
| ------ | ---------------------- |
| 890001 | Unspported para value. |
S
shawn_he 已提交
89

S
shawn_he 已提交
90
**Example**
S
shawn_he 已提交
91
  ```js
S
shawn_he 已提交
92
  try {
S
shawn_he 已提交
93
    let displayLanguage = I18n.System.getDisplayLanguage("zh", "en-GB"); // displayLanguage = Chinese
S
shawn_he 已提交
94
  } catch(error) {
S
shawn_he 已提交
95
    console.error(`call System.getDisplayLanguage failed, error code: ${error.code}, message: ${error.message}.`);
S
shawn_he 已提交
96
  }
S
shawn_he 已提交
97 98
  ```

S
shawn_he 已提交
99
### getSystemLanguages<sup>9+</sup>
S
shawn_he 已提交
100

S
shawn_he 已提交
101
static getSystemLanguages(): Array&lt;string&gt;
Z
zengyawen 已提交
102

S
shawn_he 已提交
103
Obtains the list of system languages. For details about languages, see [Instantiating the Locale Object](../../internationalization/intl-guidelines.md#how-to-develop).
Z
zengyawen 已提交
104

S
shawn_he 已提交
105
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
106

S
shawn_he 已提交
107
**Return value**
S
shawn_he 已提交
108

S
shawn_he 已提交
109 110 111
| Type                 | Description          |
| ------------------- | ------------ |
| Array&lt;string&gt; | List of the IDs of system languages.|
Z
zengyawen 已提交
112

S
shawn_he 已提交
113
**Error codes**
S
shawn_he 已提交
114

S
shawn_he 已提交
115
For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
S
shawn_he 已提交
116

S
shawn_he 已提交
117 118 119
| ID | Error Message                  |
| ------ | ---------------------- |
| 890001 | Unspported para value. |
Z
zengyawen 已提交
120

S
shawn_he 已提交
121
**Example**
S
shawn_he 已提交
122
  ```js
S
shawn_he 已提交
123
  try {
S
shawn_he 已提交
124
    let systemLanguages = I18n.System.getSystemLanguages(); // [ "en-Latn-US", "zh-Hans" ]
S
shawn_he 已提交
125
  } catch(error) {
S
shawn_he 已提交
126
    console.error(`call System.getSystemLanguages failed, error code: ${error.code}, message: ${error.message}.`);
S
shawn_he 已提交
127
  }
S
shawn_he 已提交
128
  ```
Z
zengyawen 已提交
129

S
shawn_he 已提交
130
### getSystemCountries<sup>9+</sup>
Z
zengyawen 已提交
131

S
shawn_he 已提交
132
static getSystemCountries(language: string): Array&lt;string&gt;
Z
zengyawen 已提交
133

S
shawn_he 已提交
134
Obtains the list of countries and regions supported for the specified language. For details about countries or regions, see [Instantiating the Locale Object](../../internationalization/intl-guidelines.md#how-to-develop).
Z
zengyawen 已提交
135

S
shawn_he 已提交
136 137
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
138 139
**Parameters**

S
shawn_he 已提交
140 141 142
| Name     | Type    | Mandatory  | Description   |
| -------- | ------ | ---- | ----- |
| language | string | Yes   | Language ID.|
S
shawn_he 已提交
143

S
shawn_he 已提交
144
**Return value**
S
shawn_he 已提交
145

S
shawn_he 已提交
146 147 148
| Type                 | Description          |
| ------------------- | ------------ |
| Array&lt;string&gt; | List of the IDs of the countries and regions supported for the specified language.|
S
shawn_he 已提交
149

S
shawn_he 已提交
150
**Error codes**
Z
zengyawen 已提交
151

S
shawn_he 已提交
152
For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
Z
zengyawen 已提交
153

S
shawn_he 已提交
154 155 156
| ID | Error Message                  |
| ------ | ---------------------- |
| 890001 | Unspported para value. |
S
shawn_he 已提交
157

S
shawn_he 已提交
158 159 160
**Example**
  ```js
  try {
S
shawn_he 已提交
161
    let systemCountries = I18n.System.getSystemCountries('zh'); // systemCountries = [ "ZW", "YT", "YE", ..., "ER", "CN", "DE" ], 240 countries or regions in total
S
shawn_he 已提交
162
  } catch(error) {
S
shawn_he 已提交
163
    console.error(`call System.getSystemCountries failed, error code: ${error.code}, message: ${error.message}.`);
S
shawn_he 已提交
164 165
  }
  ```
S
shawn_he 已提交
166

S
shawn_he 已提交
167
### isSuggested<sup>9+</sup>
S
shawn_he 已提交
168

S
shawn_he 已提交
169
static isSuggested(language: string, region?: string): boolean
S
shawn_he 已提交
170

S
shawn_he 已提交
171
Checks whether the system language matches the specified region.
S
shawn_he 已提交
172

S
shawn_he 已提交
173 174
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
175
**Parameters**
S
shawn_he 已提交
176

S
shawn_he 已提交
177 178 179 180
| Name     | Type    | Mandatory  | Description           |
| -------- | ------ | ---- | ------------- |
| language | string | Yes   | Valid language ID, for example, **zh**.|
| region   | string | No   | Valid region ID, for example, **CN**. |
S
shawn_he 已提交
181

S
shawn_he 已提交
182
**Return value**
S
shawn_he 已提交
183

S
shawn_he 已提交
184 185 186 187 188 189
| Type     | Description                                      |
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the system language matches the specified region; returns **false** otherwise.|

**Error codes**

S
shawn_he 已提交
190
For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
S
shawn_he 已提交
191

S
shawn_he 已提交
192 193 194
| ID | Error Message                  |
| ------ | ---------------------- |
| 890001 | Unspported para value. |
S
shawn_he 已提交
195

S
shawn_he 已提交
196
**Example**
S
shawn_he 已提交
197
  ```js
S
shawn_he 已提交
198
  try {
S
shawn_he 已提交
199
    let res = I18n.System.isSuggested('zh', 'CN');  // res = true
S
shawn_he 已提交
200
  } catch(error) {
S
shawn_he 已提交
201
    console.error(`call System.isSuggested failed, error code: ${error.code}, message: ${error.message}.`);
S
shawn_he 已提交
202
  }
S
shawn_he 已提交
203 204
  ```

S
shawn_he 已提交
205
### getSystemLanguage<sup>9+</sup>
S
shawn_he 已提交
206

S
shawn_he 已提交
207
static getSystemLanguage(): string
S
shawn_he 已提交
208

S
shawn_he 已提交
209
Obtains the system language. For details about languages, see [Instantiating the Locale Object](../../internationalization/intl-guidelines.md#how-to-develop).
S
shawn_he 已提交
210 211 212

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

S
shawn_he 已提交
213
**Return value**
S
shawn_he 已提交
214

S
shawn_he 已提交
215 216 217 218 219 220
| Type    | Description     |
| ------ | ------- |
| string | System language ID.|

**Error codes**

S
shawn_he 已提交
221
For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
S
shawn_he 已提交
222

S
shawn_he 已提交
223 224 225
| ID | Error Message                  |
| ------ | ---------------------- |
| 890001 | Unspported para value. |
S
shawn_he 已提交
226

S
shawn_he 已提交
227
**Example**
S
shawn_he 已提交
228
  ```js
S
shawn_he 已提交
229
  try {
S
shawn_he 已提交
230
    let systemLanguage = I18n.System.getSystemLanguage(); // systemLanguage indicates the current system language.
S
shawn_he 已提交
231
  } catch(error) {
S
shawn_he 已提交
232
    console.error(`call System.getSystemLanguage failed, error code: ${error.code}, message: ${error.message}.`);
S
shawn_he 已提交
233
  }
S
shawn_he 已提交
234 235
  ```

S
shawn_he 已提交
236
### setSystemLanguage<sup>9+</sup>
S
shawn_he 已提交
237

S
shawn_he 已提交
238
static setSystemLanguage(language: string): void
S
shawn_he 已提交
239

S
shawn_he 已提交
240
Sets the system language. Currently, this API does not support real-time updating of the system language.
S
shawn_he 已提交
241

S
shawn_he 已提交
242
**System API**: This is a system API.
S
shawn_he 已提交
243

S
shawn_he 已提交
244
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
S
shawn_he 已提交
245

S
shawn_he 已提交
246
**System capability**: SystemCapability.Global.I18n
S
shawn_he 已提交
247

S
shawn_he 已提交
248
**Parameters**
S
shawn_he 已提交
249

S
shawn_he 已提交
250 251 252
| Name     | Type    | Mandatory  | Description   |
| -------- | ------ | ---- | ----- |
| language | string | Yes   | Language ID.|
S
shawn_he 已提交
253

S
shawn_he 已提交
254
**Error codes**
S
shawn_he 已提交
255

S
shawn_he 已提交
256
For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
S
shawn_he 已提交
257

S
shawn_he 已提交
258 259 260
| ID | Error Message                  |
| ------ | ---------------------- |
| 890001 | Unspported para value. |
S
shawn_he 已提交
261

S
shawn_he 已提交
262
**Example**
S
shawn_he 已提交
263
  ```js
S
shawn_he 已提交
264
  try {
S
shawn_he 已提交
265
    I18n.System.setSystemLanguage('zh'); // Set the current system language to zh.
S
shawn_he 已提交
266
  } catch(error) {
S
shawn_he 已提交
267
    console.error(`call System.setSystemLanguage failed, error code: ${error.code}, message: ${error.message}.`);
S
shawn_he 已提交
268
  }
S
shawn_he 已提交
269 270
  ```

S
shawn_he 已提交
271
### getSystemRegion<sup>9+</sup>
S
shawn_he 已提交
272

S
shawn_he 已提交
273
static getSystemRegion(): string
Z
zengyawen 已提交
274

S
shawn_he 已提交
275
Obtains the system region. For details about system regions, see [Instantiating the Locale Object](../../internationalization/intl-guidelines.md#how-to-develop).
S
shawn_he 已提交
276 277 278

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

S
shawn_he 已提交
279
**Return value**
S
shawn_he 已提交
280

S
shawn_he 已提交
281 282 283
| Type    | Description     |
| ------ | ------- |
| string | System region ID.|
Z
zengyawen 已提交
284

S
shawn_he 已提交
285 286
**Error codes**

S
shawn_he 已提交
287
For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
S
shawn_he 已提交
288

S
shawn_he 已提交
289 290 291
| ID | Error Message                  |
| ------ | ---------------------- |
| 890001 | Unspported para value. |
S
shawn_he 已提交
292

S
shawn_he 已提交
293
**Example**
S
shawn_he 已提交
294
  ```js
S
shawn_he 已提交
295
  try {
S
shawn_he 已提交
296
    let systemRegion = I18n.System.getSystemRegion(); // Obtain the current system region.
S
shawn_he 已提交
297
  } catch(error) {
S
shawn_he 已提交
298
    console.error(`call System.getSystemRegion failed, error code: ${error.code}, message: ${error.message}.`);
S
shawn_he 已提交
299
  }
S
shawn_he 已提交
300
  ```
Z
zengyawen 已提交
301

S
shawn_he 已提交
302
### setSystemRegion<sup>9+</sup>
Z
zengyawen 已提交
303

S
shawn_he 已提交
304
static setSystemRegion(region: string): void
S
shawn_he 已提交
305 306 307

Sets the system region.

S
shawn_he 已提交
308
**System API**: This is a system API.
S
shawn_he 已提交
309

S
shawn_he 已提交
310
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
S
shawn_he 已提交
311

S
shawn_he 已提交
312 313
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
314
**Parameters**
S
shawn_he 已提交
315

S
shawn_he 已提交
316 317 318
| Name   | Type    | Mandatory  | Description   |
| ------ | ------ | ---- | ----- |
| region | string | Yes   | Region ID.|
S
shawn_he 已提交
319

S
shawn_he 已提交
320
**Error codes**
S
shawn_he 已提交
321

S
shawn_he 已提交
322
For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
S
shawn_he 已提交
323

S
shawn_he 已提交
324 325 326
| ID | Error Message                  |
| ------ | ---------------------- |
| 890001 | Unspported para value. |
S
shawn_he 已提交
327

S
shawn_he 已提交
328
**Example**
S
shawn_he 已提交
329
  ```js
S
shawn_he 已提交
330
  try {
S
shawn_he 已提交
331
    I18n.System.setSystemRegion('CN'); // Set the current system region to CN.
S
shawn_he 已提交
332
  } catch(error) {
S
shawn_he 已提交
333
    console.error(`call System.setSystemRegion failed, error code: ${error.code}, message: ${error.message}.`);
S
shawn_he 已提交
334
  }
S
shawn_he 已提交
335 336
  ```

S
shawn_he 已提交
337
### getSystemLocale<sup>9+</sup>
S
shawn_he 已提交
338

S
shawn_he 已提交
339
static getSystemLocale(): string
Z
zengyawen 已提交
340

S
shawn_he 已提交
341
Obtains the system locale. For details about system locales, see [Instantiating the Locale Object](../../internationalization/intl-guidelines.md#how-to-develop).
Z
zengyawen 已提交
342

S
shawn_he 已提交
343
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
344

S
shawn_he 已提交
345
**Return value**
S
shawn_he 已提交
346

S
shawn_he 已提交
347 348 349
| Type    | Description     |
| ------ | ------- |
| string | System locale ID.|
Z
zengyawen 已提交
350

S
shawn_he 已提交
351 352
**Error codes**

S
shawn_he 已提交
353
For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
S
shawn_he 已提交
354

S
shawn_he 已提交
355 356 357
| ID | Error Message                  |
| ------ | ---------------------- |
| 890001 | Unspported para value. |
S
shawn_he 已提交
358

S
shawn_he 已提交
359
**Example**
S
shawn_he 已提交
360
  ```js
S
shawn_he 已提交
361
  try {
S
shawn_he 已提交
362
    let systemLocale = I18n.System.getSystemLocale(); // Obtain the current system locale.
S
shawn_he 已提交
363
  } catch(error) {
S
shawn_he 已提交
364
    console.error(`call System.getSystemLocale failed, error code: ${error.code}, message: ${error.message}.`);
S
shawn_he 已提交
365
  }
S
shawn_he 已提交
366
  ```
Z
zengyawen 已提交
367

S
shawn_he 已提交
368
### setSystemLocale<sup>9+</sup>
Z
zengyawen 已提交
369

S
shawn_he 已提交
370
static setSystemLocale(locale: string): void
S
shawn_he 已提交
371 372 373

Sets the system locale.

S
shawn_he 已提交
374
**System API**: This is a system API.
S
shawn_he 已提交
375

S
shawn_he 已提交
376
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
S
shawn_he 已提交
377

S
shawn_he 已提交
378 379
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
380
**Parameters**
S
shawn_he 已提交
381

S
shawn_he 已提交
382 383 384
| Name   | Type    | Mandatory  | Description             |
| ------ | ------ | ---- | --------------- |
| locale | string | Yes   | System locale ID, for example, **zh-CN**.|
S
shawn_he 已提交
385

S
shawn_he 已提交
386
**Error codes**
S
shawn_he 已提交
387

S
shawn_he 已提交
388
For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
S
shawn_he 已提交
389

S
shawn_he 已提交
390 391 392
| ID | Error Message                  |
| ------ | ---------------------- |
| 890001 | Unspported para value. |
S
shawn_he 已提交
393

S
shawn_he 已提交
394
**Example**
S
shawn_he 已提交
395
  ```js
S
shawn_he 已提交
396
  try {
S
shawn_he 已提交
397
    I18n.System.setSystemLocale('zh-CN'); // Set the current system locale to zh-CN.
S
shawn_he 已提交
398
  } catch(error) {
S
shawn_he 已提交
399
    console.error(`call System.setSystemLocale failed, error code: ${error.code}, message: ${error.message}.`);
S
shawn_he 已提交
400
  }
S
shawn_he 已提交
401 402
  ```

S
shawn_he 已提交
403
### is24HourClock<sup>9+</sup>
S
shawn_he 已提交
404

S
shawn_he 已提交
405
static is24HourClock(): boolean
S
shawn_he 已提交
406

S
shawn_he 已提交
407
Checks whether the 24-hour clock is used.
S
shawn_he 已提交
408 409 410

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

S
shawn_he 已提交
411
**Return value**
S
shawn_he 已提交
412

S
shawn_he 已提交
413 414
| Type     | Description                                      |
| ------- | ---------------------------------------- |
S
shawn_he 已提交
415 416 417 418
| boolean | Returns **true** if the 24-hour clock is used; returns **false** otherwise.|

**Error codes**

S
shawn_he 已提交
419
For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
S
shawn_he 已提交
420

S
shawn_he 已提交
421 422 423
| ID | Error Message                  |
| ------ | ---------------------- |
| 890001 | Unspported para value. |
S
shawn_he 已提交
424

S
shawn_he 已提交
425
**Example**
S
shawn_he 已提交
426
  ```js
S
shawn_he 已提交
427
  try {
S
shawn_he 已提交
428
    let is24HourClock = I18n.System.is24HourClock(); // Check whether the 24-hour clock is enabled.
S
shawn_he 已提交
429
  } catch(error) {
S
shawn_he 已提交
430
    console.error(`call System.is24HourClock failed, error code: ${error.code}, message: ${error.message}.`);
S
shawn_he 已提交
431
  }
S
shawn_he 已提交
432 433
  ```

S
shawn_he 已提交
434
### set24HourClock<sup>9+</sup>
S
shawn_he 已提交
435

S
shawn_he 已提交
436
static set24HourClock(option: boolean): void
Z
zengyawen 已提交
437

S
shawn_he 已提交
438
Sets the 24-hour clock.
Z
zengyawen 已提交
439

S
shawn_he 已提交
440
**System API**: This is a system API.
S
shawn_he 已提交
441 442

**Permission required**: ohos.permission.UPDATE_CONFIGURATION
Z
zengyawen 已提交
443

S
shawn_he 已提交
444
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
445

S
shawn_he 已提交
446
**Parameters**
S
shawn_he 已提交
447

S
shawn_he 已提交
448 449 450
| Name   | Type     | Mandatory  | Description                                      |
| ------ | ------- | ---- | ---------------------------------------- |
| option | boolean | Yes   | Whether to enable the 24-hour clock. The value **true** means to enable the 24-hour clock, and the value **false** means the opposite.|
S
shawn_he 已提交
451

S
shawn_he 已提交
452
**Error codes**
S
shawn_he 已提交
453

S
shawn_he 已提交
454
For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
S
shawn_he 已提交
455

S
shawn_he 已提交
456 457 458
| ID | Error Message                  |
| ------ | ---------------------- |
| 890001 | Unspported para value. |
S
shawn_he 已提交
459

S
shawn_he 已提交
460
**Example**
S
shawn_he 已提交
461
  ```js
S
shawn_he 已提交
462 463
  // Set the system time to the 24-hour clock.
  try {
S
shawn_he 已提交
464
    I18n.System.set24HourClock(true);
S
shawn_he 已提交
465
  } catch(error) {
S
shawn_he 已提交
466
    console.error(`call System.set24HourClock failed, error code: ${error.code}, message: ${error.message}.`);
S
shawn_he 已提交
467
  }
S
shawn_he 已提交
468 469
  ```

S
shawn_he 已提交
470
### addPreferredLanguage<sup>9+</sup>
S
shawn_he 已提交
471

S
shawn_he 已提交
472
static addPreferredLanguage(language: string, index?: number): void
S
shawn_he 已提交
473

S
shawn_he 已提交
474
Adds a preferred language to the specified position on the preferred language list.
S
shawn_he 已提交
475

S
shawn_he 已提交
476
**System API**: This is a system API.
S
shawn_he 已提交
477

S
shawn_he 已提交
478
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
S
shawn_he 已提交
479 480 481

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

S
shawn_he 已提交
482
**Parameters**
S
shawn_he 已提交
483

S
shawn_he 已提交
484 485 486 487 488 489 490
| Name     | Type    | Mandatory  | Description        |
| -------- | ------ | ---- | ---------- |
| language | string | Yes   | Preferred language to add. |
| index    | number | No   | Position to which the preferred language is added.|

**Error codes**

S
shawn_he 已提交
491
For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
S
shawn_he 已提交
492

S
shawn_he 已提交
493 494 495
| ID | Error Message                  |
| ------ | ---------------------- |
| 890001 | Unspported para value. |
S
shawn_he 已提交
496

S
shawn_he 已提交
497
**Example**
S
shawn_he 已提交
498
  ```js
S
shawn_he 已提交
499
  // Add zh-CN to the preferred language list.
S
shawn_he 已提交
500 501
  let language = 'zh-CN';
  let index = 0;
S
shawn_he 已提交
502
  try {
S
shawn_he 已提交
503
    I18n.System.addPreferredLanguage(language, index); // Add zh-CN to the first place in the preferred language list.
S
shawn_he 已提交
504
  } catch(error) {
S
shawn_he 已提交
505
    console.error(`call System.addPreferredLanguage failed, error code: ${error.code}, message: ${error.message}.`);
S
shawn_he 已提交
506
  }
S
shawn_he 已提交
507 508
  ```

S
shawn_he 已提交
509
### removePreferredLanguage<sup>9+</sup>
S
shawn_he 已提交
510

S
shawn_he 已提交
511
static removePreferredLanguage(index: number): void
S
shawn_he 已提交
512

S
shawn_he 已提交
513
Deletes a preferred language from the specified position on the preferred language list.
S
shawn_he 已提交
514

S
shawn_he 已提交
515
**System API**: This is a system API.
S
shawn_he 已提交
516 517

**Permission required**: ohos.permission.UPDATE_CONFIGURATION
S
shawn_he 已提交
518 519 520

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

S
shawn_he 已提交
521
**Parameters**
S
shawn_he 已提交
522

S
shawn_he 已提交
523 524 525 526 527 528
| Name  | Type    | Mandatory  | Description                   |
| ----- | ------ | ---- | --------------------- |
| index | number | Yes   | Position of the preferred language to delete.|

**Error codes**

S
shawn_he 已提交
529
For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
S
shawn_he 已提交
530

S
shawn_he 已提交
531 532 533
| ID | Error Message                  |
| ------ | ---------------------- |
| 890001 | Unspported para value. |
S
shawn_he 已提交
534

S
shawn_he 已提交
535
**Example**
S
shawn_he 已提交
536
  ```js
S
shawn_he 已提交
537
  // Delete the first preferred language from the preferred language list.
S
shawn_he 已提交
538
  let index = 0;
S
shawn_he 已提交
539
  try {
S
shawn_he 已提交
540
    I18n.System.removePreferredLanguage(index);
S
shawn_he 已提交
541
  } catch(error) {
S
shawn_he 已提交
542
    console.error(`call System.removePreferredLanguage failed, error code: ${error.code}, message: ${error.message}.`);
S
shawn_he 已提交
543
  }
S
shawn_he 已提交
544 545
  ```

S
shawn_he 已提交
546
### getPreferredLanguageList<sup>9+</sup>
S
shawn_he 已提交
547

S
shawn_he 已提交
548
static getPreferredLanguageList(): Array&lt;string&gt;
S
shawn_he 已提交
549

S
shawn_he 已提交
550
Obtains the preferred language list.
S
shawn_he 已提交
551 552 553

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

S
shawn_he 已提交
554
**Return value**
S
shawn_he 已提交
555

S
shawn_he 已提交
556 557
| Type                 | Description       |
| ------------------- | --------- |
S
shawn_he 已提交
558
| Array&lt;string&gt; | Preferred language list.|
S
shawn_he 已提交
559 560 561

**Error codes**

S
shawn_he 已提交
562
For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
S
shawn_he 已提交
563

S
shawn_he 已提交
564 565 566
| ID | Error Message                  |
| ------ | ---------------------- |
| 890001 | Unspported para value. |
S
shawn_he 已提交
567

S
shawn_he 已提交
568
**Example**
S
shawn_he 已提交
569
  ```js
S
shawn_he 已提交
570
  try {
S
shawn_he 已提交
571
    let preferredLanguageList = I18n.System.getPreferredLanguageList(); // Obtain the current preferred language list.
S
shawn_he 已提交
572
  } catch(error) {
S
shawn_he 已提交
573
    console.error(`call System.getPreferredLanguageList failed, error code: ${error.code}, message: ${error.message}.`);
S
shawn_he 已提交
574
  }
S
shawn_he 已提交
575 576
  ```

S
shawn_he 已提交
577
### getFirstPreferredLanguage<sup>9+</sup>
S
shawn_he 已提交
578

S
shawn_he 已提交
579
static getFirstPreferredLanguage(): string
S
shawn_he 已提交
580

S
shawn_he 已提交
581
Obtains the first language in the preferred language list.
S
shawn_he 已提交
582 583 584

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

S
shawn_he 已提交
585
**Return value**
S
shawn_he 已提交
586

S
shawn_he 已提交
587 588 589
| Type    | Description            |
| ------ | -------------- |
| string | First language in the preferred language list.|
S
shawn_he 已提交
590

S
shawn_he 已提交
591 592
**Error codes**

S
shawn_he 已提交
593
For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
S
shawn_he 已提交
594

S
shawn_he 已提交
595 596 597
| ID | Error Message                  |
| ------ | ---------------------- |
| 890001 | Unspported para value. |
S
shawn_he 已提交
598 599 600 601

**Example**
  ```js
  try {
S
shawn_he 已提交
602
    let firstPreferredLanguage = I18n.System.getFirstPreferredLanguage(); // Obtain the first language in the preferred language list.
S
shawn_he 已提交
603
  } catch(error) {
S
shawn_he 已提交
604
    console.error(`call System.getFirstPreferredLanguage failed, error code: ${error.code}, message: ${error.message}.`);
S
shawn_he 已提交
605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623
  }
  ```

### getAppPreferredLanguage<sup>9+</sup>

static getAppPreferredLanguage(): string

Obtains the preferred language of an application.

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

**Return value**

| Type    | Description      |
| ------ | -------- |
| string | Preferred language of the application.|

**Error codes**

S
shawn_he 已提交
624
For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
S
shawn_he 已提交
625

S
shawn_he 已提交
626 627 628
| ID | Error Message                  |
| ------ | ---------------------- |
| 890001 | Unspported para value. |
S
shawn_he 已提交
629 630 631 632

**Example**
  ```js
  try {
S
shawn_he 已提交
633
    let appPreferredLanguage = I18n.System.getAppPreferredLanguage(); // Obtain the preferred language of an application.
S
shawn_he 已提交
634
  } catch(error) {
S
shawn_he 已提交
635
    console.error(`call System.getAppPreferredLanguage failed, error code: ${error.code}, message: ${error.message}.`);
S
shawn_he 已提交
636 637 638 639 640 641 642
  }
  ```

### setUsingLocalDigit<sup>9+</sup>

static setUsingLocalDigit(flag: boolean): void

S
shawn_he 已提交
643
Specifies whether to enable use of local digits.
S
shawn_he 已提交
644

S
shawn_he 已提交
645
**System API**: This is a system API.
S
shawn_he 已提交
646 647 648 649 650 651 652 653 654

**Permission required**: ohos.permission.UPDATE_CONFIGURATION

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

**Parameters**

| Name | Type     | Mandatory  | Description                             |
| ---- | ------- | ---- | ------------------------------- |
S
shawn_he 已提交
655
| flag | boolean | Yes   | Whether to enable the local digit switch. The value **true** means to enable the local digit switch, and the value **false** indicates the opposite.|
S
shawn_he 已提交
656 657 658

**Error codes**

S
shawn_he 已提交
659
For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
S
shawn_he 已提交
660

S
shawn_he 已提交
661 662 663
| ID | Error Message                  |
| ------ | ---------------------- |
| 890001 | Unspported para value. |
S
shawn_he 已提交
664 665 666 667

**Example**
  ```ts
  try {
S
shawn_he 已提交
668
    I18n.System.setUsingLocalDigit(true); // Enable the local digit switch.
S
shawn_he 已提交
669
  } catch(error) {
S
shawn_he 已提交
670
    console.error(`call System.setUsingLocalDigit failed, error code: ${error.code}, message: ${error.message}.`);
S
shawn_he 已提交
671 672 673 674 675 676 677
  }
  ```

### getUsingLocalDigit<sup>9+</sup>

static getUsingLocalDigit(): boolean

S
shawn_he 已提交
678
Checks whether use of local digits is enabled.
S
shawn_he 已提交
679 680 681 682 683 684 685 686 687 688 689

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

**Return value**

| Type     | Description                                      |
| ------- | ---------------------------------------- |
| boolean | Result indicating whether the local digit switch is turned on. The value **true** indicates that the local digit switch is turned on, and the value **false** indicates the opposite.|

**Error codes**

S
shawn_he 已提交
690
For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
S
shawn_he 已提交
691

S
shawn_he 已提交
692 693 694
| ID | Error Message                  |
| ------ | ---------------------- |
| 890001 | Unspported para value. |
S
shawn_he 已提交
695 696 697 698

**Example**
  ```ts
  try {
S
shawn_he 已提交
699
    let status = I18n.System.getUsingLocalDigit(); // Check whether the local digit switch is enabled.
S
shawn_he 已提交
700
  } catch(error) {
S
shawn_he 已提交
701
    console.error(`call System.getUsingLocalDigit failed, error code: ${error.code}, message: ${error.message}.`);
S
shawn_he 已提交
702 703 704 705
  }
  ```


S
shawn_he 已提交
706
## I18n.isRTL<sup>7+</sup>
S
shawn_he 已提交
707 708 709 710 711 712 713 714 715

isRTL(locale: string): boolean

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

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

**Parameters**

S
shawn_he 已提交
716 717 718
| Name   | Type    | Mandatory  | Description     |
| ------ | ------ | ---- | ------- |
| locale | string | Yes   | Locale ID.|
S
shawn_he 已提交
719 720 721 722 723 724 725 726 727 728 729 730 731 732

**Return value**

| Type     | Description                                      |
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the localized script is displayed from right to left; returns **false** otherwise.|

**Example**
  ```js
  i18n.isRTL("zh-CN");// Since Chinese is not written from right to left, false is returned.
  i18n.isRTL("ar-EG");// Since Arabic is written from right to left, true is returned.
  ```


S
shawn_he 已提交
733
## I18n.getCalendar<sup>8+</sup>
S
shawn_he 已提交
734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755

getCalendar(locale: string, type? : string): Calendar

Obtains a **Calendar** object.

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

**Parameters**

| Name   | Type    | Mandatory  | Description                                      |
| ------ | ------ | ---- | ---------------------------------------- |
| locale | string | Yes   | Valid locale value, for example, **zh-Hans-CN**.                |
| type   | string | No   | Valid calendar type. Currently, the valid types are as follows: **buddhist**, **chinese**, **coptic**, **ethiopic**, **hebrew**, **gregory**, **indian**, **islamic\_civil**, **islamic\_tbla**, **islamic\_umalqura**, **japanese**, and **persian**. If this parameter is left unspecified, the default calendar type of the specified locale is used.|

**Return value**

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

**Example**
  ```js
S
shawn_he 已提交
756
  I18n.getCalendar("zh-Hans", "chinese"); // Obtain the Calendar object for the Chinese lunar calendar.
S
shawn_he 已提交
757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778
  ```


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


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

setTime(date: Date): void

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

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

**Parameters**

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

**Example**
  ```js
S
shawn_he 已提交
779 780
  let calendar = I18n.getCalendar("en-US", "gregory");
  let date = new Date(2021, 10, 7, 8, 0, 0, 0);
S
shawn_he 已提交
781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800
  calendar.setTime(date);
  ```


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

setTime(time: number): void

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

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

**Parameters**

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

**Example**
  ```js
S
shawn_he 已提交
801
  let calendar = I18n.getCalendar("en-US", "gregory");
S
shawn_he 已提交
802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826
  calendar.setTime(10540800000);
  ```


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

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

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

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

**Parameters**

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

**Example**
  ```js
S
shawn_he 已提交
827
  let calendar = I18n.getCalendar("zh-Hans");
S
shawn_he 已提交
828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846
  calendar.set(2021, 10, 1, 8, 0, 0); // set time to 2021.10.1 08:00:00
  ```


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

setTimeZone(timezone: string): void

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

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

**Parameters**

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

**Example**
S
shawn_he 已提交
847
  ```js
S
shawn_he 已提交
848
  let calendar = I18n.getCalendar("zh-Hans");
S
shawn_he 已提交
849 850 851 852 853 854 855 856 857 858 859 860
  calendar.setTimeZone("Asia/Shanghai");
  ```


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

getTimeZone(): string

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

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

S
shawn_he 已提交
861
**Return value**
S
shawn_he 已提交
862

S
shawn_he 已提交
863 864 865
| Type    | Description        |
| ------ | ---------- |
| string | Time zone of the **Calendar** object.|
S
shawn_he 已提交
866

S
shawn_he 已提交
867
**Example**
S
shawn_he 已提交
868
  ```js
S
shawn_he 已提交
869
  let calendar = I18n.getCalendar("zh-Hans");
S
shawn_he 已提交
870
  calendar.setTimeZone("Asia/Shanghai");
S
shawn_he 已提交
871
  let timezone = calendar.getTimeZone(); // timezone = "Asia/Shanghai"
S
shawn_he 已提交
872 873 874 875 876 877 878 879 880 881 882
  ```


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

getFirstDayOfWeek(): number

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

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

S
shawn_he 已提交
883
**Return value**
S
shawn_he 已提交
884

S
shawn_he 已提交
885 886 887
| Type    | Description                   |
| ------ | --------------------- |
| number | Start day of a week. The value **1** indicates Sunday, and the value **7** indicates Saturday.|
S
shawn_he 已提交
888

S
shawn_he 已提交
889
**Example**
S
shawn_he 已提交
890
  ```js
S
shawn_he 已提交
891 892
  let calendar = I18n.getCalendar("en-US", "gregory");
  let firstDayOfWeek = calendar.getFirstDayOfWeek(); // firstDayOfWeek = 1
S
shawn_he 已提交
893 894 895 896 897 898 899 900 901 902 903
  ```


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

setFirstDayOfWeek(value: number): void

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

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

S
shawn_he 已提交
904
**Parameters**
S
shawn_he 已提交
905

S
shawn_he 已提交
906 907
| Name  | Type    | Mandatory  | Description                   |
| ----- | ------ | ---- | --------------------- |
S
shawn_he 已提交
908
| value | number | Yes   | Start day of a week. The value **1** indicates Sunday, and the value **7** indicates Saturday.|
Z
zengyawen 已提交
909

S
shawn_he 已提交
910
**Example**
S
shawn_he 已提交
911
  ```js
S
shawn_he 已提交
912 913 914
  let calendar = I18n.getCalendar("zh-Hans");
  calendar.setFirstDayOfWeek(3);
  let firstDayOfWeek = calendar.getFirstDayOfWeek(); // firstDayOfWeek = 3
S
shawn_he 已提交
915
  ```
Z
zengyawen 已提交
916 917


S
shawn_he 已提交
918
### getMinimalDaysInFirstWeek<sup>8+</sup>
Z
zengyawen 已提交
919

S
shawn_he 已提交
920 921 922 923 924 925
getMinimalDaysInFirstWeek(): number

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

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

S
shawn_he 已提交
926
**Return value**
S
shawn_he 已提交
927

S
shawn_he 已提交
928 929 930
| Type    | Description          |
| ------ | ------------ |
| number | Minimum number of days in the first week of a year.|
S
shawn_he 已提交
931

S
shawn_he 已提交
932
**Example**
S
shawn_he 已提交
933
  ```js
S
shawn_he 已提交
934 935
  let calendar = I18n.getCalendar("zh-Hans");
  let minimalDaysInFirstWeek = calendar.getMinimalDaysInFirstWeek(); // minimalDaysInFirstWeek = 1
S
shawn_he 已提交
936
  ```
Z
zengyawen 已提交
937 938


S
shawn_he 已提交
939
### setMinimalDaysInFirstWeek<sup>8+</sup>
Z
zengyawen 已提交
940

S
shawn_he 已提交
941
setMinimalDaysInFirstWeek(value: number): void
Z
zengyawen 已提交
942 943 944

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

S
shawn_he 已提交
945 946
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
947
**Parameters**
S
shawn_he 已提交
948

S
shawn_he 已提交
949 950
| Name  | Type    | Mandatory  | Description          |
| ----- | ------ | ---- | ------------ |
S
shawn_he 已提交
951
| value | number | Yes   | Minimum number of days in the first week of a year.|
S
shawn_he 已提交
952

S
shawn_he 已提交
953
**Example**
S
shawn_he 已提交
954
  ```js
S
shawn_he 已提交
955
  let calendar = I18n.getCalendar("zh-Hans");
S
shawn_he 已提交
956
  calendar.setMinimalDaysInFirstWeek(3);
S
shawn_he 已提交
957
  let minimalDaysInFirstWeek = calendar.getMinimalDaysInFirstWeek(); // minimalDaysInFirstWeek = 3
S
shawn_he 已提交
958 959 960 961 962 963 964 965 966 967 968
  ```


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

get(field: string): number

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

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

S
shawn_he 已提交
969
**Parameters**
S
shawn_he 已提交
970

S
shawn_he 已提交
971 972 973
| Name  | Type    | Mandatory  | Description                                      |
| ----- | ------ | ---- | ---------------------------------------- |
| field | string | Yes   | Value of the specified field in the **Calendar** object. Currently, a valid field can be any of the following: **era**, **year**, **month**, **week\_of\_year**, **week\_of\_month**, **date**, **day\_of\_year**, **day\_of\_week**, **day\_of\_week\_in\_month**, **hour**, **hour\_of\_day**, **minute**, **second**, **millisecond**, **zone\_offset**, **dst\_offset**, **year\_woy**, **dow\_local**, **extended\_year**, **julian\_day**, **milliseconds\_in\_day**, **is\_leap\_month**.|
S
shawn_he 已提交
974

S
shawn_he 已提交
975
**Return value**
S
shawn_he 已提交
976

S
shawn_he 已提交
977 978 979
| Type    | Description                                      |
| ------ | ---------------------------------------- |
| number | Value of the specified field. For example, if the year in the internal date of this **Calendar** object is **1990**, the **get("year")** function will return **1990**.|
S
shawn_he 已提交
980

S
shawn_he 已提交
981
**Example**
S
shawn_he 已提交
982
  ```js
S
shawn_he 已提交
983
  let calendar = I18n.getCalendar("zh-Hans");
S
shawn_he 已提交
984
  calendar.set(2021, 10, 1, 8, 0, 0); // set time to 2021.10.1 08:00:00
S
shawn_he 已提交
985
  let hourOfDay = calendar.get("hour_of_day"); // hourOfDay = 8
S
shawn_he 已提交
986 987 988 989 990 991 992
  ```


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

getDisplayName(locale: string): string

S
shawn_he 已提交
993
Obtains the **Calendar** object name displayed for the specified locale.
S
shawn_he 已提交
994 995 996

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

S
shawn_he 已提交
997
**Parameters**
S
shawn_he 已提交
998

S
shawn_he 已提交
999 1000 1001
| Name   | Type    | Mandatory  | Description                                      |
| ------ | ------ | ---- | ---------------------------------------- |
| locale | string | Yes   | Locale for which the name of the **Calendar** object is displayed. For example, if **locale** is **en-US**, the name of the Buddhist calendar will be **Buddhist Calendar**.|
S
shawn_he 已提交
1002

S
shawn_he 已提交
1003
**Return value**
S
shawn_he 已提交
1004

S
shawn_he 已提交
1005 1006
| Type    | Description                 |
| ------ | ------------------- |
S
shawn_he 已提交
1007
| string | **Calendar** object name displayed for the specified locale.|
S
shawn_he 已提交
1008

S
shawn_he 已提交
1009
**Example**
S
shawn_he 已提交
1010
  ```js
S
shawn_he 已提交
1011 1012
  let calendar = I18n.getCalendar("en-US", "buddhist");
  let calendarName = calendar.getDisplayName("zh"); // calendarName = "Buddhist Calendar"
S
shawn_he 已提交
1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023
  ```


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

isWeekend(date?: Date): boolean

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

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

S
shawn_he 已提交
1024
**Parameters**
S
shawn_he 已提交
1025

S
shawn_he 已提交
1026 1027
| Name | Type  | Mandatory  | Description                                      |
| ---- | ---- | ---- | ---------------------------------------- |
S
shawn_he 已提交
1028
| date | Date | No   | Specified date in this **Calendar** object. If the **date** parameter is not specified, the system checks whether the current date is a weekend.|
S
shawn_he 已提交
1029

S
shawn_he 已提交
1030
**Return value**
S
shawn_he 已提交
1031

S
shawn_he 已提交
1032 1033 1034
| Type     | Description                                 |
| ------- | ----------------------------------- |
| boolean | Returns **true** if the date is a weekend; returns **false** if the date is a weekday.|
S
shawn_he 已提交
1035

S
shawn_he 已提交
1036
**Example**
S
shawn_he 已提交
1037
  ```js
S
shawn_he 已提交
1038
  let calendar = I18n.getCalendar("zh-Hans");
S
shawn_he 已提交
1039
  calendar.set(2021, 11, 11, 8, 0, 0); // set time to 2021.11.11 08:00:00
S
shawn_he 已提交
1040
  calendar.isWeekend(); // false
S
shawn_he 已提交
1041
  let date = new Date(2011, 11, 6, 9, 0, 0);
S
shawn_he 已提交
1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055
  calendar.isWeekend(date); // true
  ```


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


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

constructor(country: string, options?: PhoneNumberFormatOptions)

Creates a **PhoneNumberFormat** object.

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

S
shawn_he 已提交
1057 1058
**Parameters**

S
shawn_he 已提交
1059 1060 1061
| Name    | Type                                      | Mandatory  | Description              |
| ------- | ---------------------------------------- | ---- | ---------------- |
| country | string                                   | Yes   | Country or region to which the phone number to be formatted belongs.|
S
shawn_he 已提交
1062
| options | [PhoneNumberFormatOptions](#phonenumberformatoptions8) | No   | Options of the **PhoneNumberFormat** object. |
Z
zengyawen 已提交
1063

S
shawn_he 已提交
1064
**Example**
S
shawn_he 已提交
1065
  ```js
S
shawn_he 已提交
1066
  let phoneNumberFormat= new I18n.PhoneNumberFormat("CN", {"type": "E164"});
S
shawn_he 已提交
1067 1068 1069 1070 1071 1072
  ```


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

isValidNumber(number: string): boolean
Z
zengyawen 已提交
1073 1074 1075

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

S
shawn_he 已提交
1076 1077
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
1078
**Parameters**
S
shawn_he 已提交
1079

S
shawn_he 已提交
1080 1081 1082
| Name   | Type    | Mandatory  | Description       |
| ------ | ------ | ---- | --------- |
| number | string | Yes   | Phone number to be checked.|
S
shawn_he 已提交
1083

S
shawn_he 已提交
1084
**Return value**
S
shawn_he 已提交
1085

S
shawn_he 已提交
1086 1087 1088
| Type     | Description                                   |
| ------- | ------------------------------------- |
| boolean | Returns **true** if the phone number format is valid; returns **false** otherwise.|
S
shawn_he 已提交
1089

S
shawn_he 已提交
1090
**Example**
S
shawn_he 已提交
1091
  ```js
S
shawn_he 已提交
1092 1093
  let phonenumberfmt = new I18n.PhoneNumberFormat("CN");
  let isValidNumber = phonenumberfmt.isValidNumber("15812312312"); // isValidNumber = true
S
shawn_he 已提交
1094 1095 1096 1097 1098 1099
  ```


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

format(number: string): string
Z
zengyawen 已提交
1100 1101 1102

Formats a phone number.

S
shawn_he 已提交
1103 1104
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
1105
**Parameters**
S
shawn_he 已提交
1106

S
shawn_he 已提交
1107 1108 1109
| Name   | Type    | Mandatory  | Description        |
| ------ | ------ | ---- | ---------- |
| number | string | Yes   | Phone number to be formatted.|
S
shawn_he 已提交
1110

S
shawn_he 已提交
1111
**Return value**
S
shawn_he 已提交
1112

S
shawn_he 已提交
1113 1114 1115
| Type    | Description        |
| ------ | ---------- |
| string | Formatted phone number.|
S
shawn_he 已提交
1116

S
shawn_he 已提交
1117
**Example**
S
shawn_he 已提交
1118
  ```js
S
shawn_he 已提交
1119 1120
  let phonenumberfmt = new I18n.PhoneNumberFormat("CN");
  let formattedPhoneNumber = phonenumberfmt.format("15812312312"); // formattedPhoneNumber = "158 1231 2312"
S
shawn_he 已提交
1121 1122
  ```

S
shawn_he 已提交
1123

S
shawn_he 已提交
1124
### getLocationName<sup>9+</sup>
S
shawn_he 已提交
1125

S
shawn_he 已提交
1126
getLocationName(number: string, locale: string): string
S
shawn_he 已提交
1127 1128 1129 1130 1131 1132

Obtains the home location of a phone number.

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

**Parameters**
S
shawn_he 已提交
1133

S
shawn_he 已提交
1134 1135
| Name   | Type    | Mandatory  | Description  |
| ------ | ------ | ---- | ---- |
S
shawn_he 已提交
1136 1137 1138 1139
| number | string | Yes   | Phone number.|
| locale | string | Yes   | Locale ID.|

**Return value**
S
shawn_he 已提交
1140

S
shawn_he 已提交
1141 1142
| Type    | Description      |
| ------ | -------- |
S
shawn_he 已提交
1143 1144 1145
| string | Home location of the phone number.|

**Example**
S
shawn_he 已提交
1146
  ```js
S
shawn_he 已提交
1147 1148
  let phonenumberfmt = new I18n.PhoneNumberFormat("CN");
  let locationName = phonenumberfmt.getLocationName("15812312345", "zh-CN"); // locationName = "Zhanjiang, Guangdong Province"
S
shawn_he 已提交
1149 1150
  ```

S
shawn_he 已提交
1151

S
shawn_he 已提交
1152
## PhoneNumberFormatOptions<sup>8+</sup>
S
shawn_he 已提交
1153 1154 1155

Defines the options for this PhoneNumberFormat object.

S
shawn_he 已提交
1156
**System capability**: SystemCapability.Global.I18n
S
shawn_he 已提交
1157

S
shawn_he 已提交
1158
| Name  | Type    | Readable  | Writable  | Description                                      |
S
shawn_he 已提交
1159
| ---- | ------ | ---- | ---- | ---------------------------------------- |
S
shawn_he 已提交
1160
| type | string | Yes   | Yes   | Format type of a phone number. The available options are as follows: E164,&nbsp;INTERNATIONAL,&nbsp;NATIONAL, and&nbsp;RFC3966.|
S
shawn_he 已提交
1161 1162 1163


## UnitInfo<sup>8+</sup>
Z
zengyawen 已提交
1164 1165 1166

Defines the measurement unit information.

S
shawn_he 已提交
1167
**System capability**: SystemCapability.Global.I18n
S
shawn_he 已提交
1168

S
shawn_he 已提交
1169
| Name           | Type    | Readable  | Writable  | Description                                      |
S
shawn_he 已提交
1170 1171
| ------------- | ------ | ---- | ---- | ---------------------------------------- |
| unit          | string | Yes   | Yes   | Name of the measurement unit, for example, **meter**, **inch**, or **cup**.|
S
shawn_he 已提交
1172
| measureSystem | string | Yes   | Yes   | Measurement system. The value can be **SI**,&nbsp;**US**, or&nbsp;**UK**.|
S
shawn_he 已提交
1173 1174


S
shawn_he 已提交
1175
## getInstance<sup>8+</sup>
S
shawn_he 已提交
1176

S
shawn_he 已提交
1177
getInstance(locale?:string): IndexUtil
S
shawn_he 已提交
1178 1179 1180 1181 1182

Creates an **IndexUtil** object.

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

S
shawn_he 已提交
1183
**Parameters**
S
shawn_he 已提交
1184

S
shawn_he 已提交
1185 1186 1187
| Name   | Type    | Mandatory  | Description                          |
| ------ | ------ | ---- | ---------------------------- |
| locale | string | No   | A string containing locale information, including the language, optional script, and region.|
S
shawn_he 已提交
1188

S
shawn_he 已提交
1189
**Return value**
S
shawn_he 已提交
1190

S
shawn_he 已提交
1191 1192 1193
| Type                      | Description                   |
| ------------------------ | --------------------- |
| [IndexUtil](#indexutil8) | **IndexUtil** object mapping to the specified locale.|
S
shawn_he 已提交
1194

S
shawn_he 已提交
1195
**Example**
S
shawn_he 已提交
1196
  ```js
S
shawn_he 已提交
1197
  let indexUtil= I18n.getInstance("zh-CN");
S
shawn_he 已提交
1198 1199 1200
  ```


S
shawn_he 已提交
1201 1202 1203
## IndexUtil<sup>8+</sup>


S
shawn_he 已提交
1204 1205 1206 1207 1208 1209 1210 1211
### getIndexList<sup>8+</sup>

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

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

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

S
shawn_he 已提交
1212
**Return value**
S
shawn_he 已提交
1213

S
shawn_he 已提交
1214 1215 1216
| Type                 | Description                |
| ------------------- | ------------------ |
| Array&lt;string&gt; | Index list for this **locale** object.|
S
shawn_he 已提交
1217

S
shawn_he 已提交
1218
**Example**
S
shawn_he 已提交
1219
  ```js
S
shawn_he 已提交
1220 1221 1222 1223
  let indexUtil = I18n.getInstance("zh-CN");
  // indexList = [ "...", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N",
  //              "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "..." ]
  let indexList = indexUtil.getIndexList();
S
shawn_he 已提交
1224 1225 1226 1227 1228
  ```


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

S
shawn_he 已提交
1229
addLocale(locale: string): void
S
shawn_he 已提交
1230 1231 1232 1233 1234

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

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

S
shawn_he 已提交
1235
**Parameters**
S
shawn_he 已提交
1236

S
shawn_he 已提交
1237 1238 1239
| Name   | Type    | Mandatory  | Description                          |
| ------ | ------ | ---- | ---------------------------- |
| locale | string | Yes   | A string containing locale information, including the language, optional script, and region.|
S
shawn_he 已提交
1240

S
shawn_he 已提交
1241
**Example**
S
shawn_he 已提交
1242
  ```js
S
shawn_he 已提交
1243
  let indexUtil = I18n.getInstance("zh-CN");
S
shawn_he 已提交
1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255
  indexUtil.addLocale("en-US");
  ```


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

getIndex(text: string): string

Obtains the index of a text object.

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

S
shawn_he 已提交
1256
**Parameters**
S
shawn_he 已提交
1257

S
shawn_he 已提交
1258 1259 1260
| Name | Type    | Mandatory  | Description          |
| ---- | ------ | ---- | ------------ |
| text | string | Yes   | **text** object whose index is to be obtained.|
S
shawn_he 已提交
1261

S
shawn_he 已提交
1262
**Return value**
S
shawn_he 已提交
1263

S
shawn_he 已提交
1264 1265 1266
| Type    | Description         |
| ------ | ----------- |
| string | Index of the **text** object.|
S
shawn_he 已提交
1267

S
shawn_he 已提交
1268
**Example**
S
shawn_he 已提交
1269
  ```js
S
shawn_he 已提交
1270 1271
  let indexUtil= I18n.getInstance("zh-CN");
  let index = indexUtil.getIndex("hi");  // index = "H"
S
shawn_he 已提交
1272 1273 1274
  ```


S
shawn_he 已提交
1275
## I18n.getLineInstance<sup>8+</sup>
S
shawn_he 已提交
1276

S
shawn_he 已提交
1277
getLineInstance(locale: string): BreakIterator
S
shawn_he 已提交
1278

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

S
shawn_he 已提交
1281
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1282

S
shawn_he 已提交
1283
**Parameters**
S
shawn_he 已提交
1284

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

S
shawn_he 已提交
1289
**Return value**
S
shawn_he 已提交
1290

S
shawn_he 已提交
1291 1292 1293
| Type                              | Description         |
| -------------------------------- | ----------- |
| [BreakIterator](#breakiterator8) | [BreakIterator](#breakiterator8) object used for text segmentation.|
Z
zengyawen 已提交
1294

S
shawn_he 已提交
1295
**Example**
S
shawn_he 已提交
1296
  ```js
S
shawn_he 已提交
1297
  let iterator = I18n.getLineInstance("en");
S
shawn_he 已提交
1298
  ```
Z
zengyawen 已提交
1299 1300


S
shawn_he 已提交
1301
## BreakIterator<sup>8+</sup>
Z
zengyawen 已提交
1302 1303


S
shawn_he 已提交
1304
### setLineBreakText<sup>8+</sup>
Z
zengyawen 已提交
1305

S
shawn_he 已提交
1306
setLineBreakText(text: string): void
Z
zengyawen 已提交
1307

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

S
shawn_he 已提交
1310
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1311

S
shawn_he 已提交
1312
**Parameters**
S
shawn_he 已提交
1313

S
shawn_he 已提交
1314 1315 1316
| Name | Type    | Mandatory  | Description                     |
| ---- | ------ | ---- | ----------------------- |
| text | string | Yes   | Text to be processed by the **BreakIterator** object.|
Z
zengyawen 已提交
1317

S
shawn_he 已提交
1318
**Example**
S
shawn_he 已提交
1319
  ```js
S
shawn_he 已提交
1320 1321
  let iterator = I18n.getLineInstance("en");
  iterator.setLineBreakText("Apple is my favorite fruit ."); // Set a short sentence as the text to be processed by the BreakIterator object.
S
shawn_he 已提交
1322
  ```
Z
zengyawen 已提交
1323 1324


S
shawn_he 已提交
1325
### getLineBreakText<sup>8+</sup>
Z
zengyawen 已提交
1326

S
shawn_he 已提交
1327
getLineBreakText(): string
Z
zengyawen 已提交
1328

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

S
shawn_he 已提交
1331
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1332

S
shawn_he 已提交
1333
**Return value**
S
shawn_he 已提交
1334

S
shawn_he 已提交
1335 1336 1337
| Type    | Description                    |
| ------ | ---------------------- |
| string | Text being processed by the **BreakIterator** object.|
Z
zengyawen 已提交
1338

S
shawn_he 已提交
1339
**Example**
S
shawn_he 已提交
1340
  ```js
S
shawn_he 已提交
1341
  let iterator = I18n.getLineInstance("en");
S
shawn_he 已提交
1342
  iterator.setLineBreakText("Apple is my favorite fruit.");
S
shawn_he 已提交
1343
  let breakText = iterator.getLineBreakText(); // breakText = "Apple is my favorite fruit."
S
shawn_he 已提交
1344
  ```
Z
zengyawen 已提交
1345 1346


S
shawn_he 已提交
1347
### current<sup>8+</sup>
Z
zengyawen 已提交
1348

S
shawn_he 已提交
1349 1350 1351 1352 1353 1354
current(): number

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

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

S
shawn_he 已提交
1355
**Return value**
S
shawn_he 已提交
1356

S
shawn_he 已提交
1357 1358 1359
| Type    | Description                         |
| ------ | --------------------------- |
| number | Position of the **BreakIterator** object in the text being processed.|
S
shawn_he 已提交
1360

S
shawn_he 已提交
1361
**Example**
S
shawn_he 已提交
1362
  ```js
S
shawn_he 已提交
1363
  let iterator = I18n.getLineInstance("en");
S
shawn_he 已提交
1364
  iterator.setLineBreakText("Apple is my favorite fruit.");
S
shawn_he 已提交
1365
  let currentPos = iterator.current(); // currentPos = 0
S
shawn_he 已提交
1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376
  ```


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

first(): number

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

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

S
shawn_he 已提交
1377
**Return value**
S
shawn_he 已提交
1378

S
shawn_he 已提交
1379 1380 1381
| Type    | Description               |
| ------ | ----------------- |
| number | Offset to the first text boundary of the processed text.|
S
shawn_he 已提交
1382

S
shawn_he 已提交
1383
**Example**
S
shawn_he 已提交
1384
  ```js
S
shawn_he 已提交
1385
  let iterator = i18n.getLineInstance("en");
S
shawn_he 已提交
1386
  iterator.setLineBreakText("Apple is my favorite fruit.");
S
shawn_he 已提交
1387
  let firstPos = iterator.first(); // firstPos = 0
S
shawn_he 已提交
1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398
  ```


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

last(): number

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

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

S
shawn_he 已提交
1399
**Return value**
S
shawn_he 已提交
1400

S
shawn_he 已提交
1401 1402
| Type    | Description                |
| ------ | ------------------ |
S
shawn_he 已提交
1403
| number | Offset to the last text boundary of the processed text.|
S
shawn_he 已提交
1404

S
shawn_he 已提交
1405
**Example**
S
shawn_he 已提交
1406
  ```js
S
shawn_he 已提交
1407
  let iterator = I18n.getLineInstance("en");
S
shawn_he 已提交
1408
  iterator.setLineBreakText("Apple is my favorite fruit.");
S
shawn_he 已提交
1409
  let lastPos = iterator.last(); // lastPos = 27
S
shawn_he 已提交
1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420
  ```


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

next(index?: number): number

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

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

S
shawn_he 已提交
1421
**Parameters**
S
shawn_he 已提交
1422

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

S
shawn_he 已提交
1427
**Return value**
S
shawn_he 已提交
1428

S
shawn_he 已提交
1429 1430 1431
| Type    | Description                                      |
| ------ | ---------------------------------------- |
| number | Position of the [BreakIterator](#breakiterator8) object in the text after it is moved by the specified number of text boundaries. The value **-1** is returned if the position of the [BreakIterator](#breakiterator8) object is outside of the processed text after it is moved by the specified number of text boundaries.|
S
shawn_he 已提交
1432

S
shawn_he 已提交
1433
**Example**
S
shawn_he 已提交
1434
  ```js
S
shawn_he 已提交
1435
  let iterator = I18n.getLineInstance("en");
S
shawn_he 已提交
1436
  iterator.setLineBreakText("Apple is my favorite fruit.");
S
shawn_he 已提交
1437 1438 1439
  let pos = iterator.first(); // pos = 0
  pos = iterator.next(); // pos = 6
  pos = iterator.next(10); // pos = -1
S
shawn_he 已提交
1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450
  ```


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

previous(): number

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

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

S
shawn_he 已提交
1451
**Return value**
S
shawn_he 已提交
1452

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

S
shawn_he 已提交
1457
**Example**
S
shawn_he 已提交
1458
  ```js
S
shawn_he 已提交
1459
  let iterator = I18n.getLineInstance("en");
S
shawn_he 已提交
1460
  iterator.setLineBreakText("Apple is my favorite fruit.");
S
shawn_he 已提交
1461 1462 1463
  let pos = iterator.first(); // pos = 0
  pos = iterator.next(3); // pos = 12
  pos = iterator.previous(); // pos = 9
S
shawn_he 已提交
1464
  ```
Z
zengyawen 已提交
1465 1466


S
shawn_he 已提交
1467
### following<sup>8+</sup>
Z
zengyawen 已提交
1468

S
shawn_he 已提交
1469
following(offset: number): number
Z
zengyawen 已提交
1470

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

S
shawn_he 已提交
1473
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1474

S
shawn_he 已提交
1475
**Parameters**
S
shawn_he 已提交
1476

S
shawn_he 已提交
1477 1478 1479
| Name   | Type    | Mandatory  | Description                                      |
| ------ | ------ | ---- | ---------------------------------------- |
| offset | number | Yes   | Offset to the position before the text boundary to which the [BreakIterator](#breakiterator8) object is moved.|
Z
zengyawen 已提交
1480

S
shawn_he 已提交
1481
**Return value**
S
shawn_he 已提交
1482

S
shawn_he 已提交
1483 1484 1485
| Type    | Description                                      |
| ------ | ---------------------------------------- |
| number | The value **-1** is returned if the text boundary to which the [BreakIterator](#breakiterator8) object is moved is outside of the processed text.|
S
shawn_he 已提交
1486

S
shawn_he 已提交
1487
**Example**
S
shawn_he 已提交
1488
  ```js
S
shawn_he 已提交
1489
  let iterator = I18n.getLineInstance("en");
S
shawn_he 已提交
1490
  iterator.setLineBreakText("Apple is my favorite fruit.");
S
shawn_he 已提交
1491 1492 1493
  let pos = iterator.following(0); // pos = 6
  pos = iterator.following(100); // pos = -1
  pos = iterator.current(); // pos = 27
S
shawn_he 已提交
1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504
  ```


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

isBoundary(offset: number): boolean

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

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

S
shawn_he 已提交
1505
**Parameters**
S
shawn_he 已提交
1506

S
shawn_he 已提交
1507 1508 1509
| Name   | Type    | Mandatory  | Description         |
| ------ | ------ | ---- | ----------- |
| offset | number | Yes   | Position to check.|
S
shawn_he 已提交
1510

S
shawn_he 已提交
1511
**Return value**
S
shawn_he 已提交
1512

S
shawn_he 已提交
1513 1514 1515
| Type     | Description                             |
| ------- | ------------------------------- |
| boolean | Returns **true** if the position specified by the offset is a text boundary; returns **false** otherwise.|
S
shawn_he 已提交
1516

S
shawn_he 已提交
1517
**Example**
S
shawn_he 已提交
1518
  ```js
S
shawn_he 已提交
1519
  let iterator = I18n.getLineInstance("en");
S
shawn_he 已提交
1520
  iterator.setLineBreakText("Apple is my favorite fruit.");
S
shawn_he 已提交
1521 1522
  let isBoundary = iterator.isBoundary(0); // isBoundary = true;
  isBoundary = iterator.isBoundary(5); // isBoundary = false;
S
shawn_he 已提交
1523 1524 1525
  ```


S
shawn_he 已提交
1526
## I18n.getTimeZone<sup>7+</sup>
S
shawn_he 已提交
1527

S
shawn_he 已提交
1528
getTimeZone(zoneID?: string): TimeZone
S
shawn_he 已提交
1529

S
shawn_he 已提交
1530
Obtains the **TimeZone** object corresponding to the specified time zone ID.
S
shawn_he 已提交
1531 1532 1533

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

S
shawn_he 已提交
1534 1535 1536 1537 1538 1539
**Parameters**

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

S
shawn_he 已提交
1540
**Return value**
S
shawn_he 已提交
1541

S
shawn_he 已提交
1542 1543 1544
| Type      | Description          |
| -------- | ------------ |
| TimeZone | **TimeZone** object corresponding to the time zone ID.|
S
shawn_he 已提交
1545

S
shawn_he 已提交
1546
**Example**
S
shawn_he 已提交
1547
  ```js
S
shawn_he 已提交
1548
  let timezone = I18n.getTimeZone();
S
shawn_he 已提交
1549 1550 1551
  ```


S
shawn_he 已提交
1552
## TimeZone
Z
zengyawen 已提交
1553 1554


S
shawn_he 已提交
1555
### getID
S
shawn_he 已提交
1556

S
shawn_he 已提交
1557
getID(): string
S
shawn_he 已提交
1558

S
shawn_he 已提交
1559
Obtains the ID of the specified **TimeZone** object.
S
shawn_he 已提交
1560

S
shawn_he 已提交
1561
**System capability**: SystemCapability.Global.I18n
S
shawn_he 已提交
1562

S
shawn_he 已提交
1563
**Return value**
S
shawn_he 已提交
1564

S
shawn_he 已提交
1565 1566 1567
| Type    | Description          |
| ------ | ------------ |
| string | Time zone ID corresponding to the **TimeZone** object.|
S
shawn_he 已提交
1568

S
shawn_he 已提交
1569
**Example**
S
shawn_he 已提交
1570
  ```js
S
shawn_he 已提交
1571 1572
  let timezone = I18n.getTimeZone();
  let timezoneID = timezone.getID(); // timezoneID = "Asia/Shanghai"
S
shawn_he 已提交
1573 1574 1575
  ```


S
shawn_he 已提交
1576
### getDisplayName
S
shawn_he 已提交
1577 1578 1579

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

S
shawn_he 已提交
1580
Obtains the localized representation of the time zone.
S
shawn_he 已提交
1581 1582 1583

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

S
shawn_he 已提交
1584
**Parameters**
S
shawn_he 已提交
1585

S
shawn_he 已提交
1586 1587
| Name   | Type     | Mandatory  | Description                  |
| ------ | ------- | ---- | -------------------- |
S
shawn_he 已提交
1588
| locale | string  | No   | Locale ID.               |
S
shawn_he 已提交
1589
| isDST  | boolean | No   | Whether to consider DST when obtaining the representation of the **TimeZone** object.|
S
shawn_he 已提交
1590

S
shawn_he 已提交
1591
**Return value**
S
shawn_he 已提交
1592

S
shawn_he 已提交
1593 1594 1595
| Type    | Description           |
| ------ | ------------- |
| string | Representation of the **TimeZone** object in the specified locale.|
S
shawn_he 已提交
1596

S
shawn_he 已提交
1597
**Example**
S
shawn_he 已提交
1598
  ```js
S
shawn_he 已提交
1599 1600
  let timezone = I18n.getTimeZone();
  let timezoneName = timezone.getDisplayName("zh-CN", false); // timezoneName = "China Standard Time"
S
shawn_he 已提交
1601 1602 1603
  ```


S
shawn_he 已提交
1604
### getRawOffset
S
shawn_he 已提交
1605 1606 1607 1608 1609 1610 1611

getRawOffset(): number

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

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

S
shawn_he 已提交
1612
**Return value**
S
shawn_he 已提交
1613

S
shawn_he 已提交
1614 1615 1616
| Type    | Description                 |
| ------ | ------------------- |
| number | Offset between the time zone represented by the **TimeZone** object and the UTC time zone.|
S
shawn_he 已提交
1617

S
shawn_he 已提交
1618
**Example**
S
shawn_he 已提交
1619
  ```js
S
shawn_he 已提交
1620 1621
  let timezone = I18n.getTimeZone();
  let offset = timezone.getRawOffset(); // offset = 28800000
S
shawn_he 已提交
1622 1623 1624
  ```


S
shawn_he 已提交
1625
### getOffset
S
shawn_he 已提交
1626 1627 1628 1629 1630 1631 1632

getOffset(date?: number): number

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

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

S
shawn_he 已提交
1633
**Return value**
S
shawn_he 已提交
1634

S
shawn_he 已提交
1635 1636 1637
| Type    | Description                     |
| ------ | ----------------------- |
| number | Offset between the time zone represented by the **TimeZone** object and the UTC time zone at a certain time point.|
S
shawn_he 已提交
1638

S
shawn_he 已提交
1639
**Example**
S
shawn_he 已提交
1640
  ```js
S
shawn_he 已提交
1641 1642
  let timezone = I18n.getTimeZone();
  let offset = timezone.getOffset(1234567890); // offset = 28800000
S
shawn_he 已提交
1643
  ```
S
shawn_he 已提交
1644

S
shawn_he 已提交
1645

S
shawn_he 已提交
1646 1647 1648 1649 1650 1651 1652 1653 1654
### getAvailableIDs<sup>9+</sup>

static getAvailableIDs(): Array&lt;string&gt;

Obtains the list of time zone IDs supported by the system.

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

**Return value**
S
shawn_he 已提交
1655

S
shawn_he 已提交
1656 1657
| Type                 | Description         |
| ------------------- | ----------- |
S
shawn_he 已提交
1658 1659 1660
| Array&lt;string&gt; | List of time zone IDs supported by the system.|

**Example**
S
shawn_he 已提交
1661
  ```ts
S
shawn_he 已提交
1662 1663
  // ids = ["America/Adak", "America/Anchorage", "America/Bogota", "America/Denver", "America/Los_Angeles", "America/Montevideo", "America/Santiago", "America/Sao_Paulo", "Asia/Ashgabat", "Asia/Hovd", "Asia/Jerusalem", "Asia/Magadan", "Asia/Omsk", "Asia/Shanghai", "Asia/Tokyo", "Asia/Yerevan", "Atlantic/Cape_Verde", "Australia/Lord_Howe", "Europe/Dublin", "Europe/London", "Europe/Moscow", "Pacific/Auckland", "Pacific/Easter", "Pacific/Pago-Pago"], 24 time zones supported in total
  let ids = I18n.TimeZone.getAvailableIDs();
S
shawn_he 已提交
1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675
  ```


### getAvailableZoneCityIDs<sup>9+</sup>

static getAvailableZoneCityIDs(): Array&lt;string&gt;

Obtains the list of time zone city IDs supported by the system.

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

**Return value**
S
shawn_he 已提交
1676

S
shawn_he 已提交
1677 1678
| Type                 | Description           |
| ------------------- | ------------- |
S
shawn_he 已提交
1679 1680 1681
| Array&lt;string&gt; | List of time zone city IDs supported by the system.|

**Example**
S
shawn_he 已提交
1682
  ```ts
S
shawn_he 已提交
1683 1684
  // cityIDs = ["Auckland", "Magadan", "Lord Howe Island", "Tokyo", "Shanghai", "Hovd", "Omsk", "Ashgabat", "Yerevan", "Moscow", "Tel Aviv", "Dublin", "London", "Praia", "Montevideo", "Brasília", "Santiago", "Bogotá", "Easter Island", "Salt Lake City", "Los Angeles", "Anchorage", "Adak", "Pago Pago"], 24 time zone cities supported in total
  let cityIDs = I18n.TimeZone.getAvailableZoneCityIDs();
S
shawn_he 已提交
1685 1686 1687 1688 1689 1690 1691
  ```


### getCityDisplayName<sup>9+</sup>

static getCityDisplayName(cityID: string, locale: string): string

S
shawn_he 已提交
1692
Obtains the localized representation of a time zone city in the specified locale.
S
shawn_he 已提交
1693 1694 1695 1696

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

**Parameters**
S
shawn_he 已提交
1697

S
shawn_he 已提交
1698 1699
| Name   | Type    | Mandatory  | Description    |
| ------ | ------ | ---- | ------ |
S
shawn_he 已提交
1700
| cityID | string | Yes   | Time zone city ID.|
S
shawn_he 已提交
1701
| locale | string | Yes   | Locale ID.  |
S
shawn_he 已提交
1702 1703

**Return value**
S
shawn_he 已提交
1704

S
shawn_he 已提交
1705 1706
| Type    | Description                |
| ------ | ------------------ |
S
shawn_he 已提交
1707 1708 1709
| string | Localized display of the time zone city in the specified locale.|

**Example**
S
shawn_he 已提交
1710
  ```ts
S
shawn_he 已提交
1711
  let displayName = I18n.TimeZone.getCityDisplayName("Shanghai", "zh-CN"); // displayName = "Shanghai (China)"
S
shawn_he 已提交
1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723
  ```


### getTimezoneFromCity<sup>9+</sup>

static getTimezoneFromCity(cityID: string): TimeZone

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

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

**Parameters**
S
shawn_he 已提交
1724

S
shawn_he 已提交
1725 1726
| Name   | Type    | Mandatory  | Description    |
| ------ | ------ | ---- | ------ |
S
shawn_he 已提交
1727 1728 1729
| cityID | string | Yes   | Time zone city ID.|

**Return value**
S
shawn_he 已提交
1730

S
shawn_he 已提交
1731 1732
| Type      | Description         |
| -------- | ----------- |
S
shawn_he 已提交
1733 1734 1735
| TimeZone | **TimeZone** object corresponding to the specified time zone city ID.|

**Example**
S
shawn_he 已提交
1736
  ```ts
S
shawn_he 已提交
1737
  let timezone = I18n.TimeZone.getTimezoneFromCity("Shanghai");
S
shawn_he 已提交
1738 1739 1740
  ```


S
shawn_he 已提交
1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752
## Transliterator<sup>9+</sup>


### getAvailableIDs<sup>9+</sup>

static getAvailableIDs(): string[]

Obtains a list of IDs supported by the **Transliterator** object.

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

**Return value**
S
shawn_he 已提交
1753

S
shawn_he 已提交
1754 1755
| Type      | Description        |
| -------- | ---------- |
S
shawn_he 已提交
1756 1757 1758
| string[] | List of IDs supported by the **Transliterator** object.|

**Example**
S
shawn_he 已提交
1759
  ```ts
S
shawn_he 已提交
1760 1761 1762
  // ids = ["ASCII-Latin", "Accents-Any", "Amharic-Latin/BGN", ...], 671 IDs supported in total
  // Each ID consists of two parts separated by a hyphen (-). The format is source-destination.
  let ids = I18n.Transliterator.getAvailableIDs();
S
shawn_he 已提交
1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774
  ```


### getInstance<sup>9+</sup>

static getInstance(id: string): Transliterator

Creates a **Transliterator** object.

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

**Parameters**
S
shawn_he 已提交
1775

S
shawn_he 已提交
1776 1777 1778
| Name | Type    | Mandatory  | Description      |
| ---- | ------ | ---- | -------- |
| id   | string | Yes   | ID supported by the **Transliterator** object.|
S
shawn_he 已提交
1779 1780

**Return value**
S
shawn_he 已提交
1781

S
shawn_he 已提交
1782 1783
| Type                                | Description   |
| ---------------------------------- | ----- |
S
shawn_he 已提交
1784 1785 1786
| [Transliterator](#transliterator9) | **Transliterator** object.|

**Example**
S
shawn_he 已提交
1787
  ```ts
S
shawn_he 已提交
1788
  let transliterator = I18n.Transliterator.getInstance("Any-Latn");
S
shawn_he 已提交
1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800
  ```


### transform<sup>9+</sup>

transform(text: string): string

Converts the input string from the source format to the target format.

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

**Parameters**
S
shawn_he 已提交
1801

S
shawn_he 已提交
1802 1803 1804
| Name | Type    | Mandatory  | Description    |
| ---- | ------ | ---- | ------ |
| text | string | Yes   | Input string.|
S
shawn_he 已提交
1805 1806

**Return value**
S
shawn_he 已提交
1807

S
shawn_he 已提交
1808 1809
| Type    | Description      |
| ------ | -------- |
S
shawn_he 已提交
1810 1811 1812
| string | Target string.|

**Example**
S
shawn_he 已提交
1813
  ```ts
S
shawn_he 已提交
1814 1815
  let transliterator = I18n.Transliterator.getInstance("Any-Latn");
  let res = transliterator.transform("China"); // res = "zhōng guó"
S
shawn_he 已提交
1816
  ```
S
shawn_he 已提交
1817

S
shawn_he 已提交
1818

S
shawn_he 已提交
1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843
## Unicode<sup>9+</sup>


### isDigit<sup>9+</sup>

static isDigit(char: string): boolean

Checks whether the input character string is composed of digits.

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

**Parameters**

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

**Return value**

| Type     | Description                                  |
| ------- | ------------------------------------ |
| boolean | Returns **true** if the input character is a digit; returns **false** otherwise.|

**Example**
  ```js
S
shawn_he 已提交
1844
  let isdigit = I18n.Unicode.isDigit("1");  // isdigit = true
S
shawn_he 已提交
1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869
  ```


### isSpaceChar<sup>9+</sup>

static isSpaceChar(char: string): boolean

Checks whether the input character is a space.

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

**Parameters**

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

**Return value**

| Type     | Description                                    |
| ------- | -------------------------------------- |
| boolean | Returns **true** if the input character is a space; returns **false** otherwise.|

**Example**
  ```js
S
shawn_he 已提交
1870
  let isspacechar = I18n.Unicode.isSpaceChar("a");  // isspacechar = false
S
shawn_he 已提交
1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895
  ```


### isWhitespace<sup>9+</sup>

static isWhitespace(char: string): boolean

Checks whether the input character is a white space.

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

**Parameters**

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

**Return value**

| Type     | Description                                    |
| ------- | -------------------------------------- |
| boolean | Returns **true** if the input character is a white space; returns **false** otherwise.|

**Example**
  ```js
S
shawn_he 已提交
1896
  let iswhitespace = I18n.Unicode.isWhitespace("a");  // iswhitespace = false
S
shawn_he 已提交
1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921
  ```


### isRTL<sup>9+</sup>

static isRTL(char: string): boolean

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

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

**Parameters**

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

**Return value**

| Type     | Description                                      |
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the input character is of the RTL language; returns **false** otherwise.|

**Example**
  ```js
S
shawn_he 已提交
1922
  let isrtl = I18n.Unicode.isRTL("a");  // isrtl = false
S
shawn_he 已提交
1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947
  ```


### isIdeograph<sup>9+</sup>

static isIdeograph(char: string): boolean

Checks whether the input character is an ideographic character.

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

**Parameters**

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

**Return value**

| Type     | Description                                      |
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the input character is an ideographic character; returns **false** otherwise.|

**Example**
  ```js
S
shawn_he 已提交
1948
  let isideograph = I18n.Unicode.isIdeograph("a");  // isideograph = false
S
shawn_he 已提交
1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973
  ```


### isLetter<sup>9+</sup>

static isLetter(char: string): boolean

Checks whether the input character is a letter.

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

**Parameters**

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

**Return value**

| Type     | Description                                  |
| ------- | ------------------------------------ |
| boolean | Returns **true** if the input character is a letter; returns **false** otherwise.|

**Example**
  ```js
S
shawn_he 已提交
1974
  let isletter = I18n.Unicode.isLetter("a");  // isletter = true
S
shawn_he 已提交
1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999
  ```


### isLowerCase<sup>9+</sup>

static isLowerCase(char: string): boolean

Checks whether the input character is a lowercase letter.

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

**Parameters**

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

**Return value**

| Type     | Description                                      |
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the input character is a lowercase letter; returns **false** otherwise.|

**Example**
  ```js
S
shawn_he 已提交
2000
  let islowercase = I18n.Unicode.isLowerCase("a");  // islowercase = true
S
shawn_he 已提交
2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025
  ```


### isUpperCase<sup>9+</sup>

static isUpperCase(char: string): boolean

Checks whether the input character is an uppercase letter.

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

**Parameters**

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

**Return value**

| Type     | Description                                      |
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the input character is an uppercase letter; returns **false** otherwise.|

**Example**
  ```js
S
shawn_he 已提交
2026
  let isuppercase = I18n.Unicode.isUpperCase("a");  // isuppercase = false
S
shawn_he 已提交
2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051
  ```


### getType<sup>9+</sup>

static getType(char: string): string

Obtains the type of the input character string.

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

**Parameters**

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

**Return value**

| Type    | Description         |
| ------ | ----------- |
| string | Type of the input character.|

**Example**
  ```js
S
shawn_he 已提交
2052
  let type = I18n.Unicode.getType("a"); // type = "U_LOWERCASE_LETTER"
S
shawn_he 已提交
2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084
  ```


## I18NUtil<sup>9+</sup>


### unitConvert<sup>9+</sup>

static unitConvert(fromUnit: UnitInfo, toUnit: UnitInfo, value: number, locale: string, style?: string): string

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

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

**Parameters**

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

**Return value**

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

**Example**
  ```js
S
shawn_he 已提交
2085
  let res = I18n.I18NUtil.unitConvert({unit: "cup", measureSystem: "US"}, {unit: "liter", measureSystem: "SI"}, 1000, "en-US", "long"); // res = 236.588 liters
S
shawn_he 已提交
2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110
  ```


### getDateOrder<sup>9+</sup>

static getDateOrder(locale: string): string

Obtains the sequence of the year, month, and day in the specified locale.

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

**Parameters**

| Name   | Type    | Mandatory  | Description                       |
| ------ | ------ | ---- | ------------------------- |
| locale | string | Yes   | Locale used for formatting, for example, **zh-Hans-CN**.|

**Return value**

| Type    | Description                 |
| ------ | ------------------- |
| string | Sequence of the year, month, and day.|

**Example**
  ```js
S
shawn_he 已提交
2111
  let order = I18n.I18NUtil.getDateOrder("zh-CN");  // order = "y-L-d"
S
shawn_he 已提交
2112
  ```
S
shawn_he 已提交
2113 2114


S
shawn_he 已提交
2115
## I18n.getDisplayCountry<sup>(deprecated)</sup>
S
shawn_he 已提交
2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140

getDisplayCountry(country: string, locale: string, sentenceCase?: boolean): string

Obtains the localized script for the specified country.

This API is deprecated since API version 9. You are advised to use [System.getDisplayCountry](#getdisplaycountry9) instead.

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

**Parameters**

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

**Return value**

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

**Example**
  ```js
S
shawn_he 已提交
2141 2142
  let countryName = I18n.getDisplayCountry("zh-CN", "en-GB", true); // countryName = true
  countryName = I18n.getDisplayCountry("zh-CN", "en-GB"); // countryName = true
S
shawn_he 已提交
2143 2144 2145
  ```


S
shawn_he 已提交
2146
## I18n.getDisplayLanguage<sup>(deprecated)</sup>
S
shawn_he 已提交
2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171

getDisplayLanguage(language: string, locale: string, sentenceCase?: boolean): string

Obtains the localized script for the specified language.

This API is deprecated since API version 9. You are advised to use [System.getDisplayLanguage](#getdisplaylanguage9) instead.

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

**Parameters**

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

**Return value**

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

**Example**
  ```js
S
shawn_he 已提交
2172 2173
  let languageName = I18n.getDisplayLanguage("zh", "en-GB", true); // languageName = "Chinese"
  languageName = I18n.getDisplayLanguage("zh", "en-GB"); // languageName = "Chinese"
S
shawn_he 已提交
2174 2175 2176
  ```


S
shawn_he 已提交
2177
## I18n.getSystemLanguage<sup>(deprecated)</sup>
S
shawn_he 已提交
2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194

getSystemLanguage(): string

Obtains the system language.

This API is deprecated since API version 9. You are advised to use [System.getSystemLanguage](#getsystemlanguage9) instead.

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

**Return value**

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

**Example**
  ```js
S
shawn_he 已提交
2195
  let systemLanguage = I18n.getSystemLanguage(); // Obtain the current system language.
S
shawn_he 已提交
2196 2197 2198
  ```


S
shawn_he 已提交
2199
## I18n.getSystemRegion<sup>(deprecated)</sup>
S
shawn_he 已提交
2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216

getSystemRegion(): string

Obtains the system region.

This API is deprecated since API version 9. You are advised to use [System.getSystemRegion](#getsystemregion9) instead.

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

**Return value**

| Type    | Description     |
| ------ | ------- |
| string | System region ID.|

**Example**
  ```js
S
shawn_he 已提交
2217
  let region = I18n.getSystemRegion(); // Obtain the current system region.
S
shawn_he 已提交
2218 2219 2220
  ```


S
shawn_he 已提交
2221
## I18n.getSystemLocale<sup>(deprecated)</sup>
S
shawn_he 已提交
2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238

getSystemLocale(): string

Obtains the system locale.

This API is deprecated since API version 9. You are advised to use [System.getSystemLocale](#getsystemlocale9) instead.

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

**Return value**

| Type    | Description     |
| ------ | ------- |
| string | System locale ID.|

**Example**
  ```js
S
shawn_he 已提交
2239
  let locale = I18n.getSystemLocale (); // Obtain the system locale.
S
shawn_he 已提交
2240 2241 2242
  ```


S
shawn_he 已提交
2243
## I18n.is24HourClock<sup>(deprecated)</sup>
S
shawn_he 已提交
2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260

is24HourClock(): boolean

Checks whether the 24-hour clock is used.

This API is deprecated since API version 9. You are advised to use [System.is24HourClock](#is24hourclock9) instead.

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

**Return value**

| Type     | Description                                      |
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the 24-hour clock is used; returns **false** otherwise.|

**Example**
  ```js
S
shawn_he 已提交
2261
  let is24HourClock = I18n.is24HourClock();
S
shawn_he 已提交
2262 2263 2264
  ```


S
shawn_he 已提交
2265
## I18n.set24HourClock<sup>(deprecated)</sup>
S
shawn_he 已提交
2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291

set24HourClock(option: boolean): boolean

Sets the 24-hour clock.

This API is deprecated since API version 9. You are advised to use [System.set24HourClock](#set24hourclock9) instead.

**Permission required**: ohos.permission.UPDATE_CONFIGURATION

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

**Parameters**

| Name   | Type     | Mandatory  | Description                                      |
| ------ | ------- | ---- | ---------------------------------------- |
| 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.|

**Return value**

| Type     | Description                           |
| ------- | ----------------------------- |
| boolean | Returns **true** if the 24-hour clock is enabled; returns **false** otherwise.|

**Example**
  ```js
  // Set the system time to the 24-hour clock.
S
shawn_he 已提交
2292
  let success = I18n.set24HourClock(true);
S
shawn_he 已提交
2293 2294 2295
  ```


S
shawn_he 已提交
2296
## I18n.addPreferredLanguage<sup>(deprecated)</sup>
S
shawn_he 已提交
2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323

addPreferredLanguage(language: string, index?: number): boolean

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

This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [System.addPreferredLanguage](#addpreferredlanguage9) instead.

**Permission required**: ohos.permission.UPDATE_CONFIGURATION

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

**Parameters**

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

**Return value**

| Type     | Description                           |
| ------- | ----------------------------- |
| boolean | Returns **true** if the preferred language is successfully added; returns **false** otherwise.|

**Example**
  ```js
  // Add zh-CN to the preferred language list.
S
shawn_he 已提交
2324 2325 2326
  let language = 'zh-CN';
  let index = 0;
  let success = I18n.addPreferredLanguage(language, index);
S
shawn_he 已提交
2327 2328 2329
  ```


S
shawn_he 已提交
2330
## I18n.removePreferredLanguage<sup>(deprecated)</sup>
S
shawn_he 已提交
2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356

removePreferredLanguage(index: number): boolean

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

This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [System.removePreferredLanguage](#removepreferredlanguage9) instead.

**Permission required**: ohos.permission.UPDATE_CONFIGURATION

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

**Parameters**

| Name  | Type    | Mandatory  | Description                   |
| ----- | ------ | ---- | --------------------- |
| index | number | Yes   | Position of the preferred language to delete.|

**Return value**

| Type     | Description                           |
| ------- | ----------------------------- |
| boolean | Returns **true** if the preferred language is deleted; returns **false** otherwise.|

**Example**
  ```js
  // Delete the first preferred language from the preferred language list.
S
shawn_he 已提交
2357 2358
  let index = 0;
  let success = I18n.removePreferredLanguage(index);
S
shawn_he 已提交
2359 2360 2361
  ```


S
shawn_he 已提交
2362
## I18n.getPreferredLanguageList<sup>(deprecated)</sup>
S
shawn_he 已提交
2363 2364 2365

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

S
shawn_he 已提交
2366
Obtains the preferred language list.
S
shawn_he 已提交
2367 2368 2369 2370 2371 2372 2373 2374 2375

This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [System.getPreferredLanguageList](#getpreferredlanguagelist9) instead.

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

**Return value**

| Type                 | Description       |
| ------------------- | --------- |
S
shawn_he 已提交
2376
| Array&lt;string&gt; | Preferred language list.|
S
shawn_he 已提交
2377 2378 2379

**Example**
  ```js
S
shawn_he 已提交
2380
  let preferredLanguageList = I18n.getPreferredLanguageList(); // Obtain the preferred language list.
S
shawn_he 已提交
2381 2382 2383
  ```


S
shawn_he 已提交
2384
## I18n.getFirstPreferredLanguage<sup>(deprecated)</sup>
S
shawn_he 已提交
2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401

getFirstPreferredLanguage(): string

Obtains the first language in the preferred language list.

This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [System.getFirstPreferredLanguage](#getfirstpreferredlanguage9) instead.

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

**Return value**

| Type    | Description            |
| ------ | -------------- |
| string | First language in the preferred language list.|

**Example**
  ```js
S
shawn_he 已提交
2402
  let firstPreferredLanguage = I18n.getFirstPreferredLanguage();
S
shawn_he 已提交
2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643
  ```


## Util<sup>(deprecated)</sup>


### unitConvert<sup>(deprecated)</sup>

static unitConvert(fromUnit: UnitInfo, toUnit: UnitInfo, value: number, locale: string, style?: string): string

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

This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [unitConvert](#unitconvert9) instead.

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

**Parameters**

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

**Return value**

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


## Character<sup>(deprecated)</sup>


### isDigit<sup>(deprecated)</sup>

static isDigit(char: string): boolean

Checks whether the input character string is composed of digits.

This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [isDigit](#isdigit9) instead.

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

**Parameters**

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

**Return value**

| Type     | Description                                  |
| ------- | ------------------------------------ |
| boolean | Returns **true** if the input character is a digit; returns **false** otherwise.|


### isSpaceChar<sup>(deprecated)</sup>

static isSpaceChar(char: string): boolean

Checks whether the input character is a space.

This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [isSpaceChar](#isspacechar9) instead.

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

**Parameters**

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

**Return value**

| Type     | Description                                    |
| ------- | -------------------------------------- |
| boolean | Returns **true** if the input character is a space; returns **false** otherwise.|


### isWhitespace<sup>(deprecated)</sup>

static isWhitespace(char: string): boolean

Checks whether the input character is a white space.

This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [isWhitespace](#iswhitespace9) instead.

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

**Parameters**

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

**Return value**

| Type     | Description                                    |
| ------- | -------------------------------------- |
| boolean | Returns **true** if the input character is a white space; returns **false** otherwise.|


### isRTL<sup>(deprecated)</sup>

static isRTL(char: string): boolean

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

This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [isRTL](#isrtl9) instead.

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

**Parameters**

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

**Return value**

| Type     | Description                                      |
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the input character is of the RTL language; returns **false** otherwise.|


### isIdeograph<sup>(deprecated)</sup>

static isIdeograph(char: string): boolean

Checks whether the input character is an ideographic character.

This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [isIdeograph](#isideograph9) instead.

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

**Parameters**

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

**Return value**

| Type     | Description                                      |
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the input character is an ideographic character; returns **false** otherwise.|


### isLetter<sup>(deprecated)</sup>

static isLetter(char: string): boolean

Checks whether the input character is a letter.

This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [isLetter](#isletter9) instead.

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

**Parameters**

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

**Return value**

| Type     | Description                                  |
| ------- | ------------------------------------ |
| boolean | Returns **true** if the input character is a letter; returns **false** otherwise.|


### isLowerCase<sup>(deprecated)</sup>

static isLowerCase(char: string): boolean

Checks whether the input character is a lowercase letter.

This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [isLowerCase](#islowercase9) instead.

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

**Parameters**

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

**Return value**

| Type     | Description                                      |
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the input character is a lowercase letter; returns **false** otherwise.|


### isUpperCase<sup>(deprecated)</sup>

static isUpperCase(char: string): boolean

Checks whether the input character is an uppercase letter.

This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [isUpperCase](#isuppercase9) instead.

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

**Parameters**

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

**Return value**

| Type     | Description                                      |
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the input character is an uppercase letter; returns **false** otherwise.|


### getType<sup>(deprecated)</sup>

static getType(char: string): string

Obtains the type of the input character string.

This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [getType](#gettype9) instead.

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

**Parameters**

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

**Return value**

| Type    | Description         |
| ------ | ----------- |
| string | Type of the input character.|