js-apis-i18n.md 73.1 KB
Newer Older
S
shawn_he 已提交
1
# Internationalization – I18N
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 5
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 已提交
6
>  **NOTE**
S
shawn_he 已提交
7
>  The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
S
shawn_he 已提交
8 9

## Modules to Import
Z
zengyawen 已提交
10

S
shawn_he 已提交
11
```js
Z
zengyawen 已提交
12 13 14 15
import i18n from '@ohos.i18n';
```


S
shawn_he 已提交
16
## System<sup>9+</sup>
Z
zengyawen 已提交
17

S
shawn_he 已提交
18
### getDisplayCountry<sup>9+</sup>
Z
zengyawen 已提交
19

S
shawn_he 已提交
20 21 22
static getDisplayCountry(country: string, locale: string, sentenceCase?: boolean): string

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

S
shawn_he 已提交
24 25
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
26
**Parameters**
S
shawn_he 已提交
27

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

S
shawn_he 已提交
34
**Return value**
S
shawn_he 已提交
35

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

**Error codes**

For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).

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

S
shawn_he 已提交
48
**Example**
S
shawn_he 已提交
49
  ```js
S
shawn_he 已提交
50 51 52 53 54
  try {
    var displayCountry = i18n.System.getDisplayCountry("zh-CN", "en-GB");
  } catch(error) {
    console.error(`call System.getDisplayCountry failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
55 56
  ```

S
shawn_he 已提交
57
### getDisplayLanguage<sup>9+</sup>
S
shawn_he 已提交
58

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

S
shawn_he 已提交
61
Obtains the localized script for the specified language.
Z
zengyawen 已提交
62

S
shawn_he 已提交
63 64
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
65
**Parameters**
S
shawn_he 已提交
66

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

S
shawn_he 已提交
73
**Return value**
S
shawn_he 已提交
74

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

**Error codes**

For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).

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

S
shawn_he 已提交
87
**Example**
S
shawn_he 已提交
88
  ```js
S
shawn_he 已提交
89 90 91 92 93
  try {
    var displayLanguage = i18n.System.getDisplayLanguage("zh", "en-GB");
  } catch(error) {
    console.error(`call System.getDisplayLanguage failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
94 95
  ```

S
shawn_he 已提交
96
### getSystemLanguages<sup>9+</sup>
S
shawn_he 已提交
97

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

S
shawn_he 已提交
100
Obtains the list of system languages.
Z
zengyawen 已提交
101

S
shawn_he 已提交
102
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
103

S
shawn_he 已提交
104
**Return value**
S
shawn_he 已提交
105

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

S
shawn_he 已提交
110
**Error codes**
S
shawn_he 已提交
111

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

| ID| Error Message|
| -------- | ---------------------------------------- |
| 890001  | Unspported para value.                |
Z
zengyawen 已提交
117

S
shawn_he 已提交
118
**Example**
S
shawn_he 已提交
119
  ```js
S
shawn_he 已提交
120 121 122 123 124
  try {
    var systemLanguages = i18n.System.getSystemLanguages();
  } catch(error) {
    console.error(`call System.getSystemLanguages failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
125
  ```
Z
zengyawen 已提交
126

S
shawn_he 已提交
127
### getSystemCountries<sup>9+</sup>
Z
zengyawen 已提交
128

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

S
shawn_he 已提交
131
Obtains the list of countries and regions supported for the specified language.
Z
zengyawen 已提交
132

S
shawn_he 已提交
133 134
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
135 136 137 138 139 140
**Parameters**

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

S
shawn_he 已提交
141
**Return value**
S
shawn_he 已提交
142

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

S
shawn_he 已提交
147
**Error codes**
Z
zengyawen 已提交
148

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

S
shawn_he 已提交
151 152 153
| ID| Error Message|
| -------- | ---------------------------------------- |
| 890001  | Unspported para value.                |
S
shawn_he 已提交
154

S
shawn_he 已提交
155 156 157 158 159 160 161 162
**Example**
  ```js
  try {
    var systemCountries = i18n.System.getSystemCountries('zh');
  } catch(error) {
    console.error(`call System.getSystemCountries failed, error code: ${error.code}, message: ${error.message}.`)
  }
  ```
S
shawn_he 已提交
163

S
shawn_he 已提交
164
### isSuggested<sup>9+</sup>
S
shawn_he 已提交
165

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

S
shawn_he 已提交
168
Checks whether the system language matches the specified region.
S
shawn_he 已提交
169

S
shawn_he 已提交
170 171
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
172
**Parameters**
S
shawn_he 已提交
173

S
shawn_he 已提交
174 175 176 177
| 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 已提交
178

S
shawn_he 已提交
179
**Return value**
S
shawn_he 已提交
180

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

**Error codes**

For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).

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

S
shawn_he 已提交
193
**Example**
S
shawn_he 已提交
194
  ```js
S
shawn_he 已提交
195 196 197 198 199
  try {
    var res = i18n.System.isSuggested('zh', 'CN');
  } catch(error) {
    console.error(`call System.isSuggested failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
200 201
  ```

S
shawn_he 已提交
202
### getSystemLanguage<sup>9+</sup>
S
shawn_he 已提交
203

S
shawn_he 已提交
204
static getSystemLanguage(): string
S
shawn_he 已提交
205

S
shawn_he 已提交
206
Obtains the system language.
S
shawn_he 已提交
207 208 209

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

S
shawn_he 已提交
210
**Return value**
S
shawn_he 已提交
211

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

**Error codes**

For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).

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

S
shawn_he 已提交
224
**Example**
S
shawn_he 已提交
225
  ```js
S
shawn_he 已提交
226 227 228 229 230
  try {
    var systemLanguage = i18n.System.getSystemLanguage();
  } catch(error) {
    console.error(`call System.getSystemLanguage failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
231 232
  ```

S
shawn_he 已提交
233
### setSystemLanguage<sup>9+</sup>
S
shawn_he 已提交
234

S
shawn_he 已提交
235
static setSystemLanguage(language: string): void
S
shawn_he 已提交
236

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

S
shawn_he 已提交
239
This is a system API.
S
shawn_he 已提交
240

S
shawn_he 已提交
241
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
S
shawn_he 已提交
242

S
shawn_he 已提交
243
**System capability**: SystemCapability.Global.I18n
S
shawn_he 已提交
244

S
shawn_he 已提交
245
**Parameters**
S
shawn_he 已提交
246

S
shawn_he 已提交
247 248 249
| Name     | Type    | Mandatory | Description   |
| -------- | ------ | ----- | ----- |
| language | string | Yes | Language ID.|
S
shawn_he 已提交
250

S
shawn_he 已提交
251
**Error codes**
S
shawn_he 已提交
252

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

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

S
shawn_he 已提交
259
**Example**
S
shawn_he 已提交
260
  ```js
S
shawn_he 已提交
261 262 263 264 265
  try {
    i18n.System.setSystemLanguage('zh');
  } catch(error) {
    console.error(`call System.setSystemLanguage failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
266 267
  ```

S
shawn_he 已提交
268
### getSystemRegion<sup>9+</sup>
S
shawn_he 已提交
269

S
shawn_he 已提交
270
static getSystemRegion(): string
Z
zengyawen 已提交
271

S
shawn_he 已提交
272 273 274 275
Obtains the system region.

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

S
shawn_he 已提交
276
**Return value**
S
shawn_he 已提交
277

S
shawn_he 已提交
278 279 280
| Type    | Description     |
| ------ | ------- |
| string | System region ID.|
Z
zengyawen 已提交
281

S
shawn_he 已提交
282 283 284 285 286 287 288 289
**Error codes**

For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 890001  | Unspported para value.                |

S
shawn_he 已提交
290
**Example**
S
shawn_he 已提交
291
  ```js
S
shawn_he 已提交
292 293 294 295 296
  try {
    var systemRegion = i18n.System.getSystemRegion();
  } catch(error) {
    console.error(`call System.getSystemRegion failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
297
  ```
Z
zengyawen 已提交
298

S
shawn_he 已提交
299
### setSystemRegion<sup>9+</sup>
Z
zengyawen 已提交
300

S
shawn_he 已提交
301
static setSystemRegion(region: string): void
S
shawn_he 已提交
302 303 304

Sets the system region.

S
shawn_he 已提交
305 306
This is a system API.

S
shawn_he 已提交
307
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
S
shawn_he 已提交
308

S
shawn_he 已提交
309 310
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
311
**Parameters**
S
shawn_he 已提交
312

S
shawn_he 已提交
313 314 315
| Name     | Type    | Mandatory | Description   |
| -------- | ------ | ----- | ----- |
| region | string | Yes | Region ID.|
S
shawn_he 已提交
316

S
shawn_he 已提交
317
**Error codes**
S
shawn_he 已提交
318

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

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

S
shawn_he 已提交
325
**Example**
S
shawn_he 已提交
326
  ```js
S
shawn_he 已提交
327 328 329 330 331
  try {
    i18n.System.setSystemRegion('CN');
  } catch(error) {
    console.error(`call System.setSystemRegion failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
332 333
  ```

S
shawn_he 已提交
334
### getSystemLocale<sup>9+</sup>
S
shawn_he 已提交
335

S
shawn_he 已提交
336
static getSystemLocale(): string
Z
zengyawen 已提交
337 338 339

Obtains the system locale.

S
shawn_he 已提交
340
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
341

S
shawn_he 已提交
342
**Return value**
S
shawn_he 已提交
343

S
shawn_he 已提交
344 345 346
| Type    | Description     |
| ------ | ------- |
| string | System locale ID.|
Z
zengyawen 已提交
347

S
shawn_he 已提交
348 349 350 351 352 353 354 355
**Error codes**

For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 890001  | Unspported para value.                |

S
shawn_he 已提交
356
**Example**
S
shawn_he 已提交
357
  ```js
S
shawn_he 已提交
358 359 360 361 362
  try {
    var systemLocale = i18n.System.getSystemLocale();
  } catch(error) {
    console.error(`call System.getSystemLocale failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
363
  ```
Z
zengyawen 已提交
364

S
shawn_he 已提交
365
### setSystemLocale<sup>9+</sup>
Z
zengyawen 已提交
366

S
shawn_he 已提交
367
static setSystemLocale(locale: string): void
S
shawn_he 已提交
368 369 370

Sets the system locale.

S
shawn_he 已提交
371 372
This is a system API.

S
shawn_he 已提交
373
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
S
shawn_he 已提交
374

S
shawn_he 已提交
375 376
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
377
**Parameters**
S
shawn_he 已提交
378

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

S
shawn_he 已提交
383
**Error codes**
S
shawn_he 已提交
384

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

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

S
shawn_he 已提交
391
**Example**
S
shawn_he 已提交
392
  ```js
S
shawn_he 已提交
393 394 395 396 397
  try {
    i18n.System.setSystemLocale('zh-CN');
  } catch(error) {
    console.error(`call System.setSystemLocale failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
398 399
  ```

S
shawn_he 已提交
400
### is24HourClock<sup>9+</sup>
S
shawn_he 已提交
401

S
shawn_he 已提交
402
static is24HourClock(): boolean
S
shawn_he 已提交
403

S
shawn_he 已提交
404
Checks whether the 24-hour clock is used.
S
shawn_he 已提交
405 406 407

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

S
shawn_he 已提交
408
**Return value**
S
shawn_he 已提交
409

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

**Error codes**

For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).

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

S
shawn_he 已提交
422
**Example**
S
shawn_he 已提交
423
  ```js
S
shawn_he 已提交
424 425 426 427 428
  try {
    var is24HourClock = i18n.System.is24HourClock();
  } catch(error) {
    console.error(`call System.is24HourClock failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
429 430
  ```

S
shawn_he 已提交
431
### set24HourClock<sup>9+</sup>
S
shawn_he 已提交
432

S
shawn_he 已提交
433
static set24HourClock(option: boolean): void
Z
zengyawen 已提交
434

S
shawn_he 已提交
435
Sets the 24-hour clock.
Z
zengyawen 已提交
436

S
shawn_he 已提交
437 438 439
This is a system API.

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

S
shawn_he 已提交
441
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
442

S
shawn_he 已提交
443
**Parameters**
S
shawn_he 已提交
444

S
shawn_he 已提交
445 446 447
| 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 已提交
448

S
shawn_he 已提交
449
**Error codes**
S
shawn_he 已提交
450

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

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

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

S
shawn_he 已提交
467
### addPreferredLanguage<sup>9+</sup>
S
shawn_he 已提交
468

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

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

S
shawn_he 已提交
473
This is a system API.
S
shawn_he 已提交
474

S
shawn_he 已提交
475
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
S
shawn_he 已提交
476 477 478

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

S
shawn_he 已提交
479
**Parameters**
S
shawn_he 已提交
480

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

**Error codes**

For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).

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

S
shawn_he 已提交
494
**Example**
S
shawn_he 已提交
495
  ```js
S
shawn_he 已提交
496 497 498 499 500 501 502 503
  // Add zh-CN to the preferred language list.
  var language = 'zh-CN';
  var index = 0;
  try {
    i18n.System.addPreferredLanguage(language, index);
  } catch(error) {
    console.error(`call System.addPreferredLanguage failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
504 505
  ```

S
shawn_he 已提交
506
### removePreferredLanguage<sup>9+</sup>
S
shawn_he 已提交
507

S
shawn_he 已提交
508
static removePreferredLanguage(index: number): void
S
shawn_he 已提交
509

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

S
shawn_he 已提交
512 513 514
This is a system API.

**Permission required**: ohos.permission.UPDATE_CONFIGURATION
S
shawn_he 已提交
515 516 517

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

S
shawn_he 已提交
518
**Parameters**
S
shawn_he 已提交
519

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

**Error codes**

For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).

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

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

S
shawn_he 已提交
543
### getPreferredLanguageList<sup>9+</sup>
S
shawn_he 已提交
544

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

S
shawn_he 已提交
547
Obtains the list of preferred languages.
S
shawn_he 已提交
548 549 550

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

S
shawn_he 已提交
551
**Return value**
S
shawn_he 已提交
552

S
shawn_he 已提交
553 554 555 556 557 558 559 560 561 562 563
| Type                 | Description       |
| ------------------- | --------- |
| Array&lt;string&gt; | List of preferred languages.|

**Error codes**

For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).

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

S
shawn_he 已提交
565
**Example**
S
shawn_he 已提交
566
  ```js
S
shawn_he 已提交
567 568 569 570 571
  try {
    var preferredLanguageList = i18n.System.getPreferredLanguageList();
  } catch(error) {
    console.error(`call System.getPreferredLanguageList failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
572 573
  ```

S
shawn_he 已提交
574
### getFirstPreferredLanguage<sup>9+</sup>
S
shawn_he 已提交
575

S
shawn_he 已提交
576
static getFirstPreferredLanguage(): string
S
shawn_he 已提交
577

S
shawn_he 已提交
578
Obtains the first language in the preferred language list.
S
shawn_he 已提交
579 580 581

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

S
shawn_he 已提交
582
**Return value**
S
shawn_he 已提交
583

S
shawn_he 已提交
584 585 586
| Type    | Description            |
| ------ | -------------- |
| string | First language in the preferred language list.|
S
shawn_he 已提交
587

S
shawn_he 已提交
588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712
**Error codes**

For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 890001  | Unspported para value.                |

**Example**
  ```js
  try {
    var firstPreferredLanguage = i18n.System.getFirstPreferredLanguage();
  } catch(error) {
    console.error(`call System.getFirstPreferredLanguage failed, error code: ${error.code}, message: ${error.message}.`)
  }
  ```

### 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**

For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 890001  | Unspported para value.                |

**Example**
  ```js
  try {
    var appPreferredLanguage = i18n.System.getAppPreferredLanguage();
  } catch(error) {
    console.error(`call System.getAppPreferredLanguage failed, error code: ${error.code}, message: ${error.message}.`)
  }
  ```

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

static setUsingLocalDigit(flag: boolean): void

Sets whether to turn on the local digit switch.

This is a system API.

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

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

**Parameters**

| Name | Type     | Mandatory  | Description                             |
| ---- | ------- | ---- | ------------------------------- |
| flag | boolean | Yes   | Whether to turn on the local digit switch. The value **true** means to turn on the local digit switch, and the value **false** indicates the opposite.|

**Error codes**

For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 890001  | Unspported para value.                |

**Example**
  ```ts
  try {
    i18n.System.setUsingLocalDigit(true);
  } catch(error) {
    console.error(`call System.setUsingLocalDigit failed, error code: ${error.code}, message: ${error.message}.`)
  }
  ```

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

static getUsingLocalDigit(): boolean

Checks whether the local digit switch is turned on.

**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**

For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).

| ID| Error Message|
| -------- | ---------------------------------------- |
| 890001  | Unspported para value.                |

**Example**
  ```ts
  try {
    var status = i18n.System.getUsingLocalDigit();
  } catch(error) {
    console.error(`call System.getUsingLocalDigit failed, error code: ${error.code}, message: ${error.message}.`)
  }
  ```


## i18n.isRTL<sup>7+</sup>

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 已提交
713 714 715
| Name     | Type    | Mandatory | Description   |
| -------- | ------ | ----- | ----- |
| locale | string | Yes | Locale ID.|
S
shawn_he 已提交
716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843

**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.
  ```


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

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
  i18n.getCalendar("zh-Hans", "gregory");
  ```


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


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

setTime(date: Date): void

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

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

**Parameters**

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

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


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

setTime(time: number): void

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

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

**Parameters**

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

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


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

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

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

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

**Parameters**

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

**Example**
  ```js
  var calendar = i18n.getCalendar("zh-Hans");
  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 已提交
844
  ```js
S
shawn_he 已提交
845 846 847 848 849 850 851 852 853 854 855 856 857
  var calendar = i18n.getCalendar("zh-Hans");
  calendar.setTimeZone("Asia/Shanghai");
  ```


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

getTimeZone(): string

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

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

S
shawn_he 已提交
858
**Return value**
S
shawn_he 已提交
859

S
shawn_he 已提交
860 861 862
| Type    | Description        |
| ------ | ---------- |
| string | Time zone of the **Calendar** object.|
S
shawn_he 已提交
863

S
shawn_he 已提交
864
**Example**
S
shawn_he 已提交
865
  ```js
S
shawn_he 已提交
866 867 868 869 870 871 872 873 874 875 876 877 878 879
  var calendar = i18n.getCalendar("zh-Hans");
  calendar.setTimeZone("Asia/Shanghai");
  calendar.getTimeZone(); // Asia/Shanghai"
  ```


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

getFirstDayOfWeek(): number

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

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

S
shawn_he 已提交
880
**Return value**
S
shawn_he 已提交
881

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

S
shawn_he 已提交
886
**Example**
S
shawn_he 已提交
887
  ```js
S
shawn_he 已提交
888
  var calendar = i18n.getCalendar("en-US", "gregory");
S
shawn_he 已提交
889 890 891 892 893 894 895 896 897 898 899 900
  calendar.getFirstDayOfWeek();
  ```


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

setFirstDayOfWeek(value: number): void

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

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

S
shawn_he 已提交
901
**Parameters**
S
shawn_he 已提交
902

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

S
shawn_he 已提交
907
**Example**
S
shawn_he 已提交
908
  ```js
S
shawn_he 已提交
909 910 911
  var calendar = i18n.getCalendar("zh-Hans");
  calendar.setFirstDayOfWeek(0);
  ```
Z
zengyawen 已提交
912 913


S
shawn_he 已提交
914
### getMinimalDaysInFirstWeek<sup>8+</sup>
Z
zengyawen 已提交
915

S
shawn_he 已提交
916 917 918 919 920 921
getMinimalDaysInFirstWeek(): number

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

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

S
shawn_he 已提交
922
**Return value**
S
shawn_he 已提交
923

S
shawn_he 已提交
924 925 926
| Type    | Description          |
| ------ | ------------ |
| number | Minimum number of days in the first week of a year.|
S
shawn_he 已提交
927

S
shawn_he 已提交
928
**Example**
S
shawn_he 已提交
929
  ```js
S
shawn_he 已提交
930 931 932
  var calendar = i18n.getCalendar("zh-Hans");
  calendar.getMinimalDaysInFirstWeek();
  ```
Z
zengyawen 已提交
933 934


S
shawn_he 已提交
935
### setMinimalDaysInFirstWeek<sup>8+</sup>
Z
zengyawen 已提交
936

S
shawn_he 已提交
937
setMinimalDaysInFirstWeek(value: number): void
Z
zengyawen 已提交
938 939 940

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

S
shawn_he 已提交
941 942
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
943
**Parameters**
S
shawn_he 已提交
944

S
shawn_he 已提交
945 946
| Name  | Type    | Mandatory  | Description          |
| ----- | ------ | ---- | ------------ |
S
shawn_he 已提交
947
| value | number | Yes   | Minimum number of days in the first week of a year.|
S
shawn_he 已提交
948

S
shawn_he 已提交
949
**Example**
S
shawn_he 已提交
950
  ```js
S
shawn_he 已提交
951 952 953 954 955 956 957 958 959 960 961 962 963
  var calendar = i18n.getCalendar("zh-Hans");
  calendar.setMinimalDaysInFirstWeek(3);
  ```


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

get(field: string): number

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

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

S
shawn_he 已提交
964
**Parameters**
S
shawn_he 已提交
965

S
shawn_he 已提交
966 967 968
| 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 已提交
969

S
shawn_he 已提交
970
**Return value**
S
shawn_he 已提交
971

S
shawn_he 已提交
972 973 974
| 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 已提交
975

S
shawn_he 已提交
976
**Example**
S
shawn_he 已提交
977
  ```js
S
shawn_he 已提交
978
  var calendar = i18n.getCalendar("zh-Hans");
S
shawn_he 已提交
979
  calendar.set(2021, 10, 1, 8, 0, 0); // set time to 2021.10.1 08:00:00
S
shawn_he 已提交
980 981 982 983 984 985 986 987
  calendar.get("hour_of_day"); // 8
  ```


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

getDisplayName(locale: string): string

S
shawn_he 已提交
988
Obtains the **Calendar** object name displayed for the specified locale.
S
shawn_he 已提交
989 990 991

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

S
shawn_he 已提交
992
**Parameters**
S
shawn_he 已提交
993

S
shawn_he 已提交
994 995 996
| 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 已提交
997

S
shawn_he 已提交
998
**Return value**
S
shawn_he 已提交
999

S
shawn_he 已提交
1000 1001
| Type    | Description                 |
| ------ | ------------------- |
S
shawn_he 已提交
1002
| string | **Calendar** object name displayed for the specified locale.|
S
shawn_he 已提交
1003

S
shawn_he 已提交
1004
**Example**
S
shawn_he 已提交
1005
  ```js
S
shawn_he 已提交
1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018
  var calendar = i18n.getCalendar("en-US", "buddhist");
  calendar.getDisplayName("zh"); // Obtain the name of the Buddhist calendar in zh.
  ```


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

isWeekend(date?: Date): boolean

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

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

S
shawn_he 已提交
1019
**Parameters**
S
shawn_he 已提交
1020

S
shawn_he 已提交
1021 1022 1023
| Name | Type  | Mandatory  | Description                                      |
| ---- | ---- | ---- | ---------------------------------------- |
| date | Date | No   | Specified date in this **Calendar** object. If this parameter is left unspecified, the system checks whether the current date in the **Calendar** object is a weekend.|
S
shawn_he 已提交
1024

S
shawn_he 已提交
1025
**Return value**
S
shawn_he 已提交
1026

S
shawn_he 已提交
1027 1028 1029
| Type     | Description                                 |
| ------- | ----------------------------------- |
| boolean | Returns **true** if the date is a weekend; returns **false** if the date is a weekday.|
S
shawn_he 已提交
1030

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


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


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

constructor(country: string, options?: PhoneNumberFormatOptions)

Creates a **PhoneNumberFormat** object.

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

S
shawn_he 已提交
1052 1053
**Parameters**

S
shawn_he 已提交
1054 1055 1056
| Name    | Type                                      | Mandatory  | Description              |
| ------- | ---------------------------------------- | ---- | ---------------- |
| country | string                                   | Yes   | Country or region to which the phone number to be formatted belongs.|
S
shawn_he 已提交
1057
| options | [PhoneNumberFormatOptions](#phonenumberformatoptions9) | No   | Options of the **PhoneNumberFormat** object. |
Z
zengyawen 已提交
1058

S
shawn_he 已提交
1059
**Example**
S
shawn_he 已提交
1060
  ```js
S
shawn_he 已提交
1061 1062 1063 1064 1065 1066 1067
  var phoneNumberFormat= new i18n.PhoneNumberFormat("CN", {"type": "E164"});
  ```


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

isValidNumber(number: string): boolean
Z
zengyawen 已提交
1068 1069 1070

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

S
shawn_he 已提交
1071 1072
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
1073
**Parameters**
S
shawn_he 已提交
1074

S
shawn_he 已提交
1075 1076 1077
| Name   | Type    | Mandatory  | Description       |
| ------ | ------ | ---- | --------- |
| number | string | Yes   | Phone number to be checked.|
S
shawn_he 已提交
1078

S
shawn_he 已提交
1079
**Return value**
S
shawn_he 已提交
1080

S
shawn_he 已提交
1081 1082 1083
| Type     | Description                                   |
| ------- | ------------------------------------- |
| boolean | Returns **true** if the phone number format is valid; returns **false** otherwise.|
S
shawn_he 已提交
1084

S
shawn_he 已提交
1085
**Example**
S
shawn_he 已提交
1086
  ```js
S
shawn_he 已提交
1087 1088 1089 1090 1091 1092 1093 1094
  var phonenumberfmt = new i18n.PhoneNumberFormat("CN");
  phonenumberfmt.isValidNumber("15812312312");
  ```


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

format(number: string): string
Z
zengyawen 已提交
1095 1096 1097

Formats a phone number.

S
shawn_he 已提交
1098 1099
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
1100
**Parameters**
S
shawn_he 已提交
1101

S
shawn_he 已提交
1102 1103 1104
| Name   | Type    | Mandatory  | Description        |
| ------ | ------ | ---- | ---------- |
| number | string | Yes   | Phone number to be formatted.|
S
shawn_he 已提交
1105

S
shawn_he 已提交
1106
**Return value**
S
shawn_he 已提交
1107

S
shawn_he 已提交
1108 1109 1110
| Type    | Description        |
| ------ | ---------- |
| string | Formatted phone number.|
S
shawn_he 已提交
1111

S
shawn_he 已提交
1112
**Example**
S
shawn_he 已提交
1113
  ```js
S
shawn_he 已提交
1114
  var phonenumberfmt = new i18n.PhoneNumberFormat("CN");
S
shawn_he 已提交
1115
  phonenumberfmt.format("15812312312");
S
shawn_he 已提交
1116 1117
  ```

S
shawn_he 已提交
1118

S
shawn_he 已提交
1119
### getLocationName<sup>9+</sup>
S
shawn_he 已提交
1120

S
shawn_he 已提交
1121
getLocationName(number: string, locale: string): string
S
shawn_he 已提交
1122 1123 1124 1125 1126 1127

Obtains the home location of a phone number.

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

**Parameters**
S
shawn_he 已提交
1128

S
shawn_he 已提交
1129 1130
| Name   | Type    | Mandatory  | Description  |
| ------ | ------ | ---- | ---- |
S
shawn_he 已提交
1131 1132 1133 1134
| number | string | Yes   | Phone number.|
| locale | string | Yes   | Locale ID.|

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

S
shawn_he 已提交
1136 1137
| Type    | Description      |
| ------ | -------- |
S
shawn_he 已提交
1138 1139 1140
| string | Home location of the phone number.|

**Example**
S
shawn_he 已提交
1141 1142
  ```js
  var phonenumberfmt = new i18n.PhoneNumberFormat("CN");
S
shawn_he 已提交
1143
  phonenumberfmt.getLocationName("15812312345", "zh-CN");
S
shawn_he 已提交
1144 1145
  ```

S
shawn_he 已提交
1146

S
shawn_he 已提交
1147
## PhoneNumberFormatOptions<sup>9+</sup>
S
shawn_he 已提交
1148 1149 1150

Defines the options for this PhoneNumberFormat object.

S
shawn_he 已提交
1151
**System capability**: SystemCapability.Global.I18n
S
shawn_he 已提交
1152

S
shawn_he 已提交
1153 1154
| Name  | Type  | Readable  | Writable  | Description                                      |
| ---- | ------ | ---- | ---- | ---------------------------------------- |
S
shawn_he 已提交
1155
| 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 已提交
1156 1157 1158


## UnitInfo<sup>8+</sup>
Z
zengyawen 已提交
1159 1160 1161

Defines the measurement unit information.

S
shawn_he 已提交
1162
**System capability**: SystemCapability.Global.I18n
S
shawn_he 已提交
1163

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


S
shawn_he 已提交
1170
## getInstance<sup>8+</sup>
S
shawn_he 已提交
1171

S
shawn_he 已提交
1172
getInstance(locale?:string): IndexUtil
S
shawn_he 已提交
1173 1174 1175 1176 1177

Creates an **IndexUtil** object.

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

S
shawn_he 已提交
1178
**Parameters**
S
shawn_he 已提交
1179

S
shawn_he 已提交
1180 1181 1182
| Name   | Type    | Mandatory  | Description                          |
| ------ | ------ | ---- | ---------------------------- |
| locale | string | No   | A string containing locale information, including the language, optional script, and region.|
S
shawn_he 已提交
1183

S
shawn_he 已提交
1184
**Return value**
S
shawn_he 已提交
1185

S
shawn_he 已提交
1186 1187 1188
| Type                      | Description                   |
| ------------------------ | --------------------- |
| [IndexUtil](#indexutil8) | **IndexUtil** object mapping to the specified locale.|
S
shawn_he 已提交
1189

S
shawn_he 已提交
1190
**Example**
S
shawn_he 已提交
1191
  ```js
S
shawn_he 已提交
1192
  var indexUtil= i18n.getInstance("zh-CN");
S
shawn_he 已提交
1193 1194 1195
  ```


S
shawn_he 已提交
1196 1197 1198
## IndexUtil<sup>8+</sup>


S
shawn_he 已提交
1199 1200 1201 1202 1203 1204 1205 1206
### 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 已提交
1207
**Return value**
S
shawn_he 已提交
1208

S
shawn_he 已提交
1209 1210 1211
| Type                 | Description                |
| ------------------- | ------------------ |
| Array&lt;string&gt; | Index list for this **locale** object.|
S
shawn_he 已提交
1212

S
shawn_he 已提交
1213
**Example**
S
shawn_he 已提交
1214
  ```js
S
shawn_he 已提交
1215 1216 1217 1218 1219 1220 1221
  var indexUtil = i18n.getInstance("zh-CN");
  var indexList = indexUtil.getIndexList();
  ```


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

S
shawn_he 已提交
1222
addLocale(locale: string): void
S
shawn_he 已提交
1223 1224 1225 1226 1227

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

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

S
shawn_he 已提交
1228
**Parameters**
S
shawn_he 已提交
1229

S
shawn_he 已提交
1230 1231 1232
| Name   | Type    | Mandatory  | Description                          |
| ------ | ------ | ---- | ---------------------------- |
| locale | string | Yes   | A string containing locale information, including the language, optional script, and region.|
S
shawn_he 已提交
1233

S
shawn_he 已提交
1234
**Example**
S
shawn_he 已提交
1235
  ```js
S
shawn_he 已提交
1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248
  var indexUtil = i18n.getInstance("zh-CN");
  indexUtil.addLocale("en-US");
  ```


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

getIndex(text: string): string

Obtains the index of a text object.

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

S
shawn_he 已提交
1249
**Parameters**
S
shawn_he 已提交
1250

S
shawn_he 已提交
1251 1252 1253
| Name | Type    | Mandatory  | Description          |
| ---- | ------ | ---- | ------------ |
| text | string | Yes   | **text** object whose index is to be obtained.|
S
shawn_he 已提交
1254

S
shawn_he 已提交
1255
**Return value**
S
shawn_he 已提交
1256

S
shawn_he 已提交
1257 1258 1259
| Type    | Description         |
| ------ | ----------- |
| string | Index of the **text** object.|
S
shawn_he 已提交
1260

S
shawn_he 已提交
1261
**Example**
S
shawn_he 已提交
1262
  ```js
S
shawn_he 已提交
1263
  var indexUtil= i18n.getInstance("zh-CN");
S
shawn_he 已提交
1264
  indexUtil.getIndex("hi"); // Return hi.
S
shawn_he 已提交
1265 1266 1267
  ```


S
shawn_he 已提交
1268
## i18n.getLineInstance<sup>8+</sup>
S
shawn_he 已提交
1269

S
shawn_he 已提交
1270
getLineInstance(locale: string): BreakIterator
S
shawn_he 已提交
1271

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

S
shawn_he 已提交
1274
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1275

S
shawn_he 已提交
1276
**Parameters**
S
shawn_he 已提交
1277

S
shawn_he 已提交
1278 1279 1280
| 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 已提交
1281

S
shawn_he 已提交
1282
**Return value**
S
shawn_he 已提交
1283

S
shawn_he 已提交
1284 1285 1286
| Type                              | Description         |
| -------------------------------- | ----------- |
| [BreakIterator](#breakiterator8) | [BreakIterator](#breakiterator8) object used for text segmentation.|
Z
zengyawen 已提交
1287

S
shawn_he 已提交
1288
**Example**
S
shawn_he 已提交
1289
  ```js
S
shawn_he 已提交
1290
  var iterator = i18n.getLineInstance("en");
S
shawn_he 已提交
1291
  ```
Z
zengyawen 已提交
1292 1293


S
shawn_he 已提交
1294
## BreakIterator<sup>8+</sup>
Z
zengyawen 已提交
1295 1296


S
shawn_he 已提交
1297
### setLineBreakText<sup>8+</sup>
Z
zengyawen 已提交
1298

S
shawn_he 已提交
1299
setLineBreakText(text: string): void
Z
zengyawen 已提交
1300

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

S
shawn_he 已提交
1303
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1304

S
shawn_he 已提交
1305
**Parameters**
S
shawn_he 已提交
1306

S
shawn_he 已提交
1307 1308 1309
| Name | Type    | Mandatory  | Description                     |
| ---- | ------ | ---- | ----------------------- |
| text | string | Yes   | Text to be processed by the **BreakIterator** object.|
Z
zengyawen 已提交
1310

S
shawn_he 已提交
1311
**Example**
S
shawn_he 已提交
1312
  ```js
S
shawn_he 已提交
1313
  var iterator = i18n.getLineInstance("en");
S
shawn_he 已提交
1314 1315
  iterator.setLineBreakText("Apple is my favorite fruit.");
  ```
Z
zengyawen 已提交
1316 1317


S
shawn_he 已提交
1318
### getLineBreakText<sup>8+</sup>
Z
zengyawen 已提交
1319

S
shawn_he 已提交
1320
getLineBreakText(): string
Z
zengyawen 已提交
1321

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

S
shawn_he 已提交
1324
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1325

S
shawn_he 已提交
1326
**Return value**
S
shawn_he 已提交
1327

S
shawn_he 已提交
1328 1329 1330
| Type    | Description                    |
| ------ | ---------------------- |
| string | Text being processed by the **BreakIterator** object.|
Z
zengyawen 已提交
1331

S
shawn_he 已提交
1332
**Example**
S
shawn_he 已提交
1333
  ```js
S
shawn_he 已提交
1334
  var iterator = i18n.getLineInstance("en");
S
shawn_he 已提交
1335 1336 1337
  iterator.setLineBreakText("Apple is my favorite fruit.");
  iterator.getLineBreakText(); // Apple is my favorite fruit.
  ```
Z
zengyawen 已提交
1338 1339


S
shawn_he 已提交
1340
### current<sup>8+</sup>
Z
zengyawen 已提交
1341

S
shawn_he 已提交
1342 1343 1344 1345 1346 1347
current(): number

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

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

S
shawn_he 已提交
1348
**Return value**
S
shawn_he 已提交
1349

S
shawn_he 已提交
1350 1351 1352
| Type    | Description                         |
| ------ | --------------------------- |
| number | Position of the **BreakIterator** object in the text being processed.|
S
shawn_he 已提交
1353

S
shawn_he 已提交
1354
**Example**
S
shawn_he 已提交
1355
  ```js
S
shawn_he 已提交
1356
  var iterator = i18n.getLineInstance("en");
S
shawn_he 已提交
1357
  iterator.setLineBreakText("Apple is my favorite fruit.");
S
shawn_he 已提交
1358
  iterator.current(); // 0
S
shawn_he 已提交
1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369
  ```


### 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 已提交
1370
**Return value**
S
shawn_he 已提交
1371

S
shawn_he 已提交
1372 1373 1374
| Type    | Description               |
| ------ | ----------------- |
| number | Offset to the first text boundary of the processed text.|
S
shawn_he 已提交
1375

S
shawn_he 已提交
1376
**Example**
S
shawn_he 已提交
1377
  ```js
S
shawn_he 已提交
1378
  var iterator = i18n.getLineInstance("en");
S
shawn_he 已提交
1379
  iterator.setLineBreakText("Apple is my favorite fruit.");
S
shawn_he 已提交
1380
  iterator.first(); // 0
S
shawn_he 已提交
1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391
  ```


### 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 已提交
1392
**Return value**
S
shawn_he 已提交
1393

S
shawn_he 已提交
1394 1395
| Type    | Description                |
| ------ | ------------------ |
S
shawn_he 已提交
1396
| number | Offset to the last text boundary of the processed text.|
S
shawn_he 已提交
1397

S
shawn_he 已提交
1398
**Example**
S
shawn_he 已提交
1399
  ```js
S
shawn_he 已提交
1400
  var iterator = i18n.getLineInstance("en");
S
shawn_he 已提交
1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413
  iterator.setLineBreakText("Apple is my favorite fruit.");
  iterator.last(); // 27
  ```


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

next(index?: number): number

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

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

S
shawn_he 已提交
1414
**Parameters**
S
shawn_he 已提交
1415

S
shawn_he 已提交
1416 1417 1418
| 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 已提交
1419

S
shawn_he 已提交
1420
**Return value**
S
shawn_he 已提交
1421

S
shawn_he 已提交
1422 1423 1424
| 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 已提交
1425

S
shawn_he 已提交
1426
**Example**
S
shawn_he 已提交
1427
  ```js
S
shawn_he 已提交
1428
  var iterator = i18n.getLineInstance("en");
S
shawn_he 已提交
1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443
  iterator.setLineBreakText("Apple is my favorite fruit.");
  iterator.first(); // 0
  iterator.next(); // 6
  iterator.next(10); // -1
  ```


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

previous(): number

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

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

S
shawn_he 已提交
1444
**Return value**
S
shawn_he 已提交
1445

S
shawn_he 已提交
1446 1447 1448
| 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 已提交
1449

S
shawn_he 已提交
1450
**Example**
S
shawn_he 已提交
1451
  ```js
S
shawn_he 已提交
1452
  var iterator = i18n.getLineInstance("en");
S
shawn_he 已提交
1453 1454 1455 1456 1457
  iterator.setLineBreakText("Apple is my favorite fruit.");
  iterator.first(); // 0
  iterator.next(3); // 12
  iterator.previous(); // 9
  ```
Z
zengyawen 已提交
1458 1459


S
shawn_he 已提交
1460
### following<sup>8+</sup>
Z
zengyawen 已提交
1461

S
shawn_he 已提交
1462
following(offset: number): number
Z
zengyawen 已提交
1463

S
shawn_he 已提交
1464
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 已提交
1465

S
shawn_he 已提交
1466
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1467

S
shawn_he 已提交
1468
**Parameters**
S
shawn_he 已提交
1469

S
shawn_he 已提交
1470 1471 1472
| 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 已提交
1473

S
shawn_he 已提交
1474
**Return value**
S
shawn_he 已提交
1475

S
shawn_he 已提交
1476 1477 1478
| 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 已提交
1479

S
shawn_he 已提交
1480
**Example**
S
shawn_he 已提交
1481
  ```js
S
shawn_he 已提交
1482
  var iterator = i18n.getLineInstance("en");
S
shawn_he 已提交
1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497
  iterator.setLineBreakText("Apple is my favorite fruit.");
  iterator.following(0); // 6
  iterator.following(100); // -1
  iterator.current(); // 27
  ```


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

isBoundary(offset: number): boolean

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

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

S
shawn_he 已提交
1498
**Parameters**
S
shawn_he 已提交
1499

S
shawn_he 已提交
1500 1501 1502
| Name   | Type    | Mandatory  | Description         |
| ------ | ------ | ---- | ----------- |
| offset | number | Yes   | Position to check.|
S
shawn_he 已提交
1503

S
shawn_he 已提交
1504
**Return value**
S
shawn_he 已提交
1505

S
shawn_he 已提交
1506 1507 1508
| Type     | Description                             |
| ------- | ------------------------------- |
| boolean | Returns **true** if the position specified by the offset is a text boundary; returns **false** otherwise.|
S
shawn_he 已提交
1509

S
shawn_he 已提交
1510
**Example**
S
shawn_he 已提交
1511
  ```js
S
shawn_he 已提交
1512
  var iterator = i18n.getLineInstance("en");
S
shawn_he 已提交
1513 1514 1515 1516 1517 1518
  iterator.setLineBreakText("Apple is my favorite fruit.");
  iterator.isBoundary(0); // true;
  iterator.isBoundary(5); // false;
  ```


S
shawn_he 已提交
1519
## i18n.getTimeZone<sup>7+</sup>
S
shawn_he 已提交
1520

S
shawn_he 已提交
1521
getTimeZone(zoneID?: string): TimeZone
S
shawn_he 已提交
1522

S
shawn_he 已提交
1523
Obtains the **TimeZone** object corresponding to the specified time zone ID.
S
shawn_he 已提交
1524 1525 1526

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

S
shawn_he 已提交
1527 1528 1529 1530 1531 1532
**Parameters**

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

S
shawn_he 已提交
1533
**Return value**
S
shawn_he 已提交
1534

S
shawn_he 已提交
1535 1536 1537
| Type      | Description          |
| -------- | ------------ |
| TimeZone | **TimeZone** object corresponding to the time zone ID.|
S
shawn_he 已提交
1538

S
shawn_he 已提交
1539
**Example**
S
shawn_he 已提交
1540
  ```js
S
shawn_he 已提交
1541
  var timezone = i18n.getTimeZone();
S
shawn_he 已提交
1542 1543 1544
  ```


S
shawn_he 已提交
1545
## TimeZone
Z
zengyawen 已提交
1546 1547


S
shawn_he 已提交
1548
### getID
S
shawn_he 已提交
1549

S
shawn_he 已提交
1550
getID(): string
S
shawn_he 已提交
1551

S
shawn_he 已提交
1552
Obtains the ID of the specified **TimeZone** object.
S
shawn_he 已提交
1553

S
shawn_he 已提交
1554
**System capability**: SystemCapability.Global.I18n
S
shawn_he 已提交
1555

S
shawn_he 已提交
1556
**Return value**
S
shawn_he 已提交
1557

S
shawn_he 已提交
1558 1559 1560
| Type    | Description          |
| ------ | ------------ |
| string | Time zone ID corresponding to the **TimeZone** object.|
S
shawn_he 已提交
1561

S
shawn_he 已提交
1562
**Example**
S
shawn_he 已提交
1563
  ```js
S
shawn_he 已提交
1564 1565
  var timezone = i18n.getTimeZone();
  timezone.getID();
S
shawn_he 已提交
1566 1567 1568
  ```


S
shawn_he 已提交
1569
### getDisplayName
S
shawn_he 已提交
1570 1571 1572 1573 1574 1575 1576

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

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

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

S
shawn_he 已提交
1577
**Parameters**
S
shawn_he 已提交
1578

S
shawn_he 已提交
1579 1580
| Name   | Type     | Mandatory  | Description                  |
| ------ | ------- | ---- | -------------------- |
S
shawn_he 已提交
1581
| locale | string  | No   | Locale ID.               |
S
shawn_he 已提交
1582
| isDST  | boolean | No   | Whether to consider DST when obtaining the representation of the **TimeZone** object.|
S
shawn_he 已提交
1583

S
shawn_he 已提交
1584
**Return value**
S
shawn_he 已提交
1585

S
shawn_he 已提交
1586 1587 1588
| Type    | Description           |
| ------ | ------------- |
| string | Representation of the **TimeZone** object in the specified locale.|
S
shawn_he 已提交
1589

S
shawn_he 已提交
1590
**Example**
S
shawn_he 已提交
1591
  ```js
S
shawn_he 已提交
1592 1593 1594 1595 1596
  var timezone = i18n.getTimeZone();
  timezone.getDisplayName("zh-CN", false);
  ```


S
shawn_he 已提交
1597
### getRawOffset
S
shawn_he 已提交
1598 1599 1600 1601 1602 1603 1604

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 已提交
1605
**Return value**
S
shawn_he 已提交
1606

S
shawn_he 已提交
1607 1608 1609
| Type    | Description                 |
| ------ | ------------------- |
| number | Offset between the time zone represented by the **TimeZone** object and the UTC time zone.|
S
shawn_he 已提交
1610

S
shawn_he 已提交
1611
**Example**
S
shawn_he 已提交
1612
  ```js
S
shawn_he 已提交
1613 1614 1615 1616 1617
  var timezone = i18n.getTimeZone();
  timezone.getRawOffset();
  ```


S
shawn_he 已提交
1618
### getOffset
S
shawn_he 已提交
1619 1620 1621 1622 1623 1624 1625

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 已提交
1626
**Return value**
S
shawn_he 已提交
1627

S
shawn_he 已提交
1628 1629 1630
| 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 已提交
1631

S
shawn_he 已提交
1632
**Example**
S
shawn_he 已提交
1633
  ```js
S
shawn_he 已提交
1634 1635 1636
  var timezone = i18n.getTimeZone();
  timezone.getOffset(1234567890);
  ```
S
shawn_he 已提交
1637

S
shawn_he 已提交
1638

S
shawn_he 已提交
1639 1640 1641 1642 1643 1644 1645 1646 1647
### 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 已提交
1648

S
shawn_he 已提交
1649 1650
| Type                 | Description         |
| ------------------- | ----------- |
S
shawn_he 已提交
1651 1652 1653
| Array&lt;string&gt; | List of time zone IDs supported by the system.|

**Example**
S
shawn_he 已提交
1654
  ```ts
S
shawn_he 已提交
1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667
  var ids = i18n.TimeZone.getAvailableIDs();
  ```


### 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 已提交
1668

S
shawn_he 已提交
1669 1670
| Type                 | Description           |
| ------------------- | ------------- |
S
shawn_he 已提交
1671 1672 1673
| Array&lt;string&gt; | List of time zone city IDs supported by the system.|

**Example**
S
shawn_he 已提交
1674
  ```ts
S
shawn_he 已提交
1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687
  var cityIDs = i18n.TimeZone.getAvailableZoneCityIDs();
  ```


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

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

Obtains the localized display of a time zone city in the specified locale.

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

**Parameters**
S
shawn_he 已提交
1688

S
shawn_he 已提交
1689 1690
| Name   | Type    | Mandatory  | Description    |
| ------ | ------ | ---- | ------ |
S
shawn_he 已提交
1691
| cityID | string | Yes   | Time zone city ID.|
S
shawn_he 已提交
1692
| locale | string | Yes   | Locale ID.  |
S
shawn_he 已提交
1693 1694

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

S
shawn_he 已提交
1696 1697
| Type    | Description                |
| ------ | ------------------ |
S
shawn_he 已提交
1698 1699 1700
| string | Localized display of the time zone city in the specified locale.|

**Example**
S
shawn_he 已提交
1701
  ```ts
S
shawn_he 已提交
1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714
  var displayName = i18n.TimeZone.getCityDisplayName("Shanghai", "zh-CN");
  ```


### 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 已提交
1715

S
shawn_he 已提交
1716 1717
| Name   | Type    | Mandatory  | Description    |
| ------ | ------ | ---- | ------ |
S
shawn_he 已提交
1718 1719 1720
| cityID | string | Yes   | Time zone city ID.|

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

S
shawn_he 已提交
1722 1723
| Type      | Description         |
| -------- | ----------- |
S
shawn_he 已提交
1724 1725 1726
| TimeZone | **TimeZone** object corresponding to the specified time zone city ID.|

**Example**
S
shawn_he 已提交
1727
  ```ts
S
shawn_he 已提交
1728 1729 1730 1731
  var timezone = i18n.TimeZone.getTimezoneFromCity("Shanghai");
  ```


S
shawn_he 已提交
1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743
## 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 已提交
1744

S
shawn_he 已提交
1745 1746
| Type      | Description        |
| -------- | ---------- |
S
shawn_he 已提交
1747 1748 1749
| string[] | List of IDs supported by the **Transliterator** object.|

**Example**
S
shawn_he 已提交
1750
  ```ts
S
shawn_he 已提交
1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763
  i18n.Transliterator.getAvailableIDs();
  ```


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

static getInstance(id: string): Transliterator

Creates a **Transliterator** object.

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

**Parameters**
S
shawn_he 已提交
1764

S
shawn_he 已提交
1765 1766 1767
| Name | Type    | Mandatory  | Description      |
| ---- | ------ | ---- | -------- |
| id   | string | Yes   | ID supported by the **Transliterator** object.|
S
shawn_he 已提交
1768 1769

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

S
shawn_he 已提交
1771 1772
| Type                                | Description   |
| ---------------------------------- | ----- |
S
shawn_he 已提交
1773 1774 1775
| [Transliterator](#transliterator9) | **Transliterator** object.|

**Example**
S
shawn_he 已提交
1776
  ```ts
S
shawn_he 已提交
1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789
  var transliterator = i18n.Transliterator.getInstance("Any-Latn");
  ```


### 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 已提交
1790

S
shawn_he 已提交
1791 1792 1793
| Name | Type    | Mandatory  | Description    |
| ---- | ------ | ---- | ------ |
| text | string | Yes   | Input string.|
S
shawn_he 已提交
1794 1795

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

S
shawn_he 已提交
1797 1798
| Type    | Description      |
| ------ | -------- |
S
shawn_he 已提交
1799 1800 1801
| string | Target string.|

**Example**
S
shawn_he 已提交
1802
  ```ts
S
shawn_he 已提交
1803 1804 1805
  var transliterator = i18n.Transliterator.getInstance("Any-Latn");
  transliterator.transform ("China");
  ```
S
shawn_he 已提交
1806

S
shawn_he 已提交
1807

S
shawn_he 已提交
1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 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 1844 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 1870 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 1896 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 1922 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 1948 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 1974 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 2000 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 2026 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 2052 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 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101
## 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
  var isdigit = i18n.Unicode.isDigit("1"); // Return true.
  ```


### 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
  var isspacechar = i18n.Unicode.isSpaceChar("a"); // Return false.
  ```


### 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
  var iswhitespace = i18n.Unicode.isWhitespace("a"); // Return false.
  ```


### 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
  var isrtl = i18n.Unicode.isRTL("a"); // Return false.
  ```


### 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
  var isideograph = i18n.Unicode.isIdeograph("a"); // Return false.
  ```


### 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
  var isletter = i18n.Unicode.isLetter("a"); // Return true.
  ```


### 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
  var islowercase = i18n.Unicode.isLowerCase("a"); // Return true.
  ```


### 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
  var isuppercase = i18n.Unicode.isUpperCase("a"); // Return false.
  ```


### 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
  var type = i18n.Unicode.getType("a");
  ```


## 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
  i18n.I18NUtil.unitConvert({unit: "cup", measureSystem: "US"}, {unit: "liter", measureSystem: "SI"}, 1000, "en-US", "long");
  ```


### 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
  i18n.I18NUtil.getDateOrder("zh-CN");
  ```
S
shawn_he 已提交
2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 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 2141 2142 2143 2144 2145 2146 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 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 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 2292 2293 2294 2295 2296 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 2324 2325 2326 2327 2328 2329 2330 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 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 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


## i18n.getDisplayCountry<sup>(deprecated)</sup>

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
  i18n.getDisplayCountry("zh-CN", "en-GB", true);
  i18n.getDisplayCountry("zh-CN", "en-GB");
  ```


## i18n.getDisplayLanguage<sup>(deprecated)</sup>

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
  i18n.getDisplayLanguage("zh", "en-GB", true);
  i18n.getDisplayLanguage("zh", "en-GB");
  ```


## i18n.getSystemLanguage<sup>(deprecated)</sup>

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
  i18n.getSystemLanguage();
  ```


## i18n.getSystemRegion<sup>(deprecated)</sup>

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
  i18n.getSystemRegion();
  ```


## i18n.getSystemLocale<sup>(deprecated)</sup>

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
  i18n.getSystemLocale();
  ```


## i18n.is24HourClock<sup>(deprecated)</sup>

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
  var is24HourClock = i18n.is24HourClock();
  ```


## i18n.set24HourClock<sup>(deprecated)</sup>

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.
  var success = i18n.set24HourClock(true);
  ```


## i18n.addPreferredLanguage<sup>(deprecated)</sup>

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.
  var language = 'zh-CN';
  var index = 0;
  var success = i18n.addPreferredLanguage(language, index);
  ```


## i18n.removePreferredLanguage<sup>(deprecated)</sup>

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.
  var index = 0;
  var success = i18n.removePreferredLanguage(index);
  ```


## i18n.getPreferredLanguageList<sup>(deprecated)</sup>

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

Obtains the list of preferred languages.

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       |
| ------------------- | --------- |
| Array&lt;string&gt; | List of preferred languages.|

**Example**
  ```js
  var preferredLanguageList = i18n.getPreferredLanguageList();
  ```


## i18n.getFirstPreferredLanguage<sup>(deprecated)</sup>

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
  var firstPreferredLanguage = i18n.getFirstPreferredLanguage();
  ```


## 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.|