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

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

S
shawn_he 已提交
11 12

## Modules to Import
Z
zengyawen 已提交
13

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


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

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

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

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

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

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

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

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

S
shawn_he 已提交
39 40
| Type    | Description           |
| ------ | ------------- |
S
shawn_he 已提交
41 42 43 44 45 46 47 48 49
| 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 已提交
50

S
shawn_he 已提交
51
**Example**
S
shawn_he 已提交
52
  ```js
S
shawn_he 已提交
53 54 55 56 57
  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 已提交
58 59
  ```

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

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

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

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

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

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

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

S
shawn_he 已提交
78 79
| Type    | Description           |
| ------ | ------------- |
S
shawn_he 已提交
80 81 82 83 84 85 86 87 88
| 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 已提交
89

S
shawn_he 已提交
90
**Example**
S
shawn_he 已提交
91
  ```js
S
shawn_he 已提交
92 93 94 95 96
  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 已提交
97 98
  ```

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

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

S
shawn_he 已提交
103
Obtains the list of system languages.
Z
zengyawen 已提交
104

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

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

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

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

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

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

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

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

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

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

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

S
shawn_he 已提交
138 139 140 141 142 143
**Parameters**

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

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

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

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

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

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

S
shawn_he 已提交
158 159 160 161 162 163 164 165
**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 已提交
166

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

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

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

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

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

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

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

S
shawn_he 已提交
184 185 186 187 188 189 190 191 192 193 194
| 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 已提交
195

S
shawn_he 已提交
196
**Example**
S
shawn_he 已提交
197
  ```js
S
shawn_he 已提交
198 199 200 201 202
  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 已提交
203 204
  ```

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

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

S
shawn_he 已提交
209
Obtains the system language.
S
shawn_he 已提交
210 211 212

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

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

S
shawn_he 已提交
215 216 217 218 219 220 221 222 223 224 225
| 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 已提交
226

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

S
shawn_he 已提交
275 276 277 278
Obtains the system region.

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

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

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

S
shawn_he 已提交
285 286 287 288 289 290 291 292
**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 已提交
293
**Example**
S
shawn_he 已提交
294
  ```js
S
shawn_he 已提交
295 296 297 298 299
  try {
    var systemRegion = i18n.System.getSystemRegion();
  } catch(error) {
    console.error(`call System.getSystemRegion failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
300
  ```
Z
zengyawen 已提交
301

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

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

Sets the system region.

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

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

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

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

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

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

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

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

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

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

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

Obtains the system locale.

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

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

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

S
shawn_he 已提交
351 352 353 354 355 356 357 358
**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 已提交
359
**Example**
S
shawn_he 已提交
360
  ```js
S
shawn_he 已提交
361 362 363 364 365
  try {
    var systemLocale = i18n.System.getSystemLocale();
  } catch(error) {
    console.error(`call System.getSystemLocale failed, error code: ${error.code}, message: ${error.message}.`)
  }
S
shawn_he 已提交
366
  ```
Z
zengyawen 已提交
367

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

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

Sets the system locale.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

S
shawn_he 已提交
413 414
| Type     | Description                                      |
| ------- | ---------------------------------------- |
S
shawn_he 已提交
415 416 417 418 419 420 421 422 423
| 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 已提交
424

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

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

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

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

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

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

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

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

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

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

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

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

S
shawn_he 已提交
460
**Example**
S
shawn_he 已提交
461
  ```js
S
shawn_he 已提交
462 463 464 465 466 467
  // 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 已提交
468 469
  ```

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

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

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

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

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

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

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

S
shawn_he 已提交
484 485 486 487 488 489 490 491 492 493 494 495
| 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 已提交
496

S
shawn_he 已提交
497
**Example**
S
shawn_he 已提交
498
  ```js
S
shawn_he 已提交
499 500 501 502 503 504 505 506
  // 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 已提交
507 508
  ```

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

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

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

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

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

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

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

S
shawn_he 已提交
523 524 525 526 527 528 529 530 531 532 533
| 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 已提交
534

S
shawn_he 已提交
535
**Example**
S
shawn_he 已提交
536
  ```js
S
shawn_he 已提交
537 538 539 540 541 542 543
  // 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 已提交
544 545
  ```

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

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

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

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

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

S
shawn_he 已提交
556 557 558 559 560 561 562 563 564 565 566
| 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 已提交
567

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

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

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

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

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

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

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

S
shawn_he 已提交
591 592 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 713 714 715 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 844 845 846
**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**

| Name   | Type    | Description     |
| ------ | ------ | ------- |
| locale | string | Locale ID.|

**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 已提交
847
  ```js
S
shawn_he 已提交
848 849 850 851 852 853 854 855 856 857 858 859 860
  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 已提交
861
**Return value**
S
shawn_he 已提交
862

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

S
shawn_he 已提交
867
**Example**
S
shawn_he 已提交
868
  ```js
S
shawn_he 已提交
869 870 871 872 873 874 875 876 877 878 879 880 881 882
  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 已提交
883
**Return value**
S
shawn_he 已提交
884

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

S
shawn_he 已提交
889
**Example**
S
shawn_he 已提交
890
  ```js
S
shawn_he 已提交
891
  var calendar = i18n.getCalendar("en-US", "gregory");
S
shawn_he 已提交
892 893 894 895 896 897 898 899 900 901 902 903
  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 已提交
904
**Parameters**
S
shawn_he 已提交
905

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

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


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

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

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

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

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

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

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


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

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

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

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

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

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

S
shawn_he 已提交
952
**Example**
S
shawn_he 已提交
953
  ```js
S
shawn_he 已提交
954 955 956 957 958 959 960 961 962 963 964 965 966
  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 已提交
967
**Parameters**
S
shawn_he 已提交
968

S
shawn_he 已提交
969 970 971
| 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 已提交
972

S
shawn_he 已提交
973
**Return value**
S
shawn_he 已提交
974

S
shawn_he 已提交
975 976 977
| 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 已提交
978

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


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

getDisplayName(locale: string): string

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

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

S
shawn_he 已提交
995
**Parameters**
S
shawn_he 已提交
996

S
shawn_he 已提交
997 998 999
| 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 已提交
1000

S
shawn_he 已提交
1001
**Return value**
S
shawn_he 已提交
1002

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

S
shawn_he 已提交
1007
**Example**
S
shawn_he 已提交
1008
  ```js
S
shawn_he 已提交
1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021
  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 已提交
1022
**Parameters**
S
shawn_he 已提交
1023

S
shawn_he 已提交
1024 1025 1026
| 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 已提交
1027

S
shawn_he 已提交
1028
**Return value**
S
shawn_he 已提交
1029

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

S
shawn_he 已提交
1034
**Example**
S
shawn_he 已提交
1035
  ```js
S
shawn_he 已提交
1036
  var calendar = i18n.getCalendar("zh-Hans");
S
shawn_he 已提交
1037
  calendar.set(2021, 11, 11, 8, 0, 0); // set time to 2021.11.11 08:00:00
S
shawn_he 已提交
1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053
  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 已提交
1054

S
shawn_he 已提交
1055 1056
**Parameters**

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

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


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

isValidNumber(number: string): boolean
Z
zengyawen 已提交
1071 1072 1073

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

S
shawn_he 已提交
1074 1075
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
1076
**Parameters**
S
shawn_he 已提交
1077

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

S
shawn_he 已提交
1082
**Return value**
S
shawn_he 已提交
1083

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

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


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

format(number: string): string
Z
zengyawen 已提交
1098 1099 1100

Formats a phone number.

S
shawn_he 已提交
1101 1102
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
1103
**Parameters**
S
shawn_he 已提交
1104

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

S
shawn_he 已提交
1109
**Return value**
S
shawn_he 已提交
1110

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

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

S
shawn_he 已提交
1121

S
shawn_he 已提交
1122
### getLocationName<sup>9+</sup>
S
shawn_he 已提交
1123

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

Obtains the home location of a phone number.

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

**Parameters**
S
shawn_he 已提交
1131

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

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

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

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

S
shawn_he 已提交
1149

S
shawn_he 已提交
1150
## PhoneNumberFormatOptions<sup>9+</sup>
S
shawn_he 已提交
1151 1152 1153

Defines the options for this PhoneNumberFormat object.

S
shawn_he 已提交
1154
**System capability**: SystemCapability.Global.I18n
S
shawn_he 已提交
1155

S
shawn_he 已提交
1156 1157
| Name  | Type  | Readable  | Writable  | Description                                      |
| ---- | ------ | ---- | ---- | ---------------------------------------- |
S
shawn_he 已提交
1158
| 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 已提交
1159 1160 1161


## UnitInfo<sup>8+</sup>
Z
zengyawen 已提交
1162 1163 1164

Defines the measurement unit information.

S
shawn_he 已提交
1165
**System capability**: SystemCapability.Global.I18n
S
shawn_he 已提交
1166

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


S
shawn_he 已提交
1173
## getInstance<sup>8+</sup>
S
shawn_he 已提交
1174

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

Creates an **IndexUtil** object.

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

S
shawn_he 已提交
1181
**Parameters**
S
shawn_he 已提交
1182

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

S
shawn_he 已提交
1187
**Return value**
S
shawn_he 已提交
1188

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

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


S
shawn_he 已提交
1199 1200 1201
## IndexUtil<sup>8+</sup>


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

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

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


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

S
shawn_he 已提交
1225
addLocale(locale: string): void
S
shawn_he 已提交
1226 1227 1228 1229 1230

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

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

S
shawn_he 已提交
1231
**Parameters**
S
shawn_he 已提交
1232

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

S
shawn_he 已提交
1237
**Example**
S
shawn_he 已提交
1238
  ```js
S
shawn_he 已提交
1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251
  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 已提交
1252
**Parameters**
S
shawn_he 已提交
1253

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

S
shawn_he 已提交
1258
**Return value**
S
shawn_he 已提交
1259

S
shawn_he 已提交
1260 1261 1262
| Type    | Description         |
| ------ | ----------- |
| string | Index of the **text** object.|
S
shawn_he 已提交
1263

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


S
shawn_he 已提交
1271
## i18n.getLineInstance<sup>8+</sup>
S
shawn_he 已提交
1272

S
shawn_he 已提交
1273
getLineInstance(locale: string): BreakIterator
S
shawn_he 已提交
1274

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

S
shawn_he 已提交
1277
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1278

S
shawn_he 已提交
1279
**Parameters**
S
shawn_he 已提交
1280

S
shawn_he 已提交
1281 1282 1283
| 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 已提交
1284

S
shawn_he 已提交
1285
**Return value**
S
shawn_he 已提交
1286

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

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


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


S
shawn_he 已提交
1300
### setLineBreakText<sup>8+</sup>
Z
zengyawen 已提交
1301

S
shawn_he 已提交
1302
setLineBreakText(text: string): void
Z
zengyawen 已提交
1303

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

S
shawn_he 已提交
1306
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1307

S
shawn_he 已提交
1308
**Parameters**
S
shawn_he 已提交
1309

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

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


S
shawn_he 已提交
1321
### getLineBreakText<sup>8+</sup>
Z
zengyawen 已提交
1322

S
shawn_he 已提交
1323
getLineBreakText(): string
Z
zengyawen 已提交
1324

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

S
shawn_he 已提交
1327
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1328

S
shawn_he 已提交
1329
**Return value**
S
shawn_he 已提交
1330

S
shawn_he 已提交
1331 1332 1333
| Type    | Description                    |
| ------ | ---------------------- |
| string | Text being processed by the **BreakIterator** object.|
Z
zengyawen 已提交
1334

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


S
shawn_he 已提交
1343
### current<sup>8+</sup>
Z
zengyawen 已提交
1344

S
shawn_he 已提交
1345 1346 1347 1348 1349 1350
current(): number

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

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

S
shawn_he 已提交
1351
**Return value**
S
shawn_he 已提交
1352

S
shawn_he 已提交
1353 1354 1355
| Type    | Description                         |
| ------ | --------------------------- |
| number | Position of the **BreakIterator** object in the text being processed.|
S
shawn_he 已提交
1356

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


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

S
shawn_he 已提交
1375 1376 1377
| Type    | Description               |
| ------ | ----------------- |
| number | Offset to the first text boundary of the processed text.|
S
shawn_he 已提交
1378

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


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

S
shawn_he 已提交
1397 1398
| Type    | Description                |
| ------ | ------------------ |
S
shawn_he 已提交
1399
| number | Offset to the last text boundary of the processed text.|
S
shawn_he 已提交
1400

S
shawn_he 已提交
1401
**Example**
S
shawn_he 已提交
1402
  ```js
S
shawn_he 已提交
1403
  var iterator = i18n.getLineInstance("en");
S
shawn_he 已提交
1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416
  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 已提交
1417
**Parameters**
S
shawn_he 已提交
1418

S
shawn_he 已提交
1419 1420 1421
| 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 已提交
1422

S
shawn_he 已提交
1423
**Return value**
S
shawn_he 已提交
1424

S
shawn_he 已提交
1425 1426 1427
| 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 已提交
1428

S
shawn_he 已提交
1429
**Example**
S
shawn_he 已提交
1430
  ```js
S
shawn_he 已提交
1431
  var iterator = i18n.getLineInstance("en");
S
shawn_he 已提交
1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446
  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 已提交
1447
**Return value**
S
shawn_he 已提交
1448

S
shawn_he 已提交
1449 1450 1451
| 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 已提交
1452

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


S
shawn_he 已提交
1463
### following<sup>8+</sup>
Z
zengyawen 已提交
1464

S
shawn_he 已提交
1465
following(offset: number): number
Z
zengyawen 已提交
1466

S
shawn_he 已提交
1467
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 已提交
1468

S
shawn_he 已提交
1469
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1470

S
shawn_he 已提交
1471
**Parameters**
S
shawn_he 已提交
1472

S
shawn_he 已提交
1473 1474 1475
| 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 已提交
1476

S
shawn_he 已提交
1477
**Return value**
S
shawn_he 已提交
1478

S
shawn_he 已提交
1479 1480 1481
| 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 已提交
1482

S
shawn_he 已提交
1483
**Example**
S
shawn_he 已提交
1484
  ```js
S
shawn_he 已提交
1485
  var iterator = i18n.getLineInstance("en");
S
shawn_he 已提交
1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500
  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 已提交
1501
**Parameters**
S
shawn_he 已提交
1502

S
shawn_he 已提交
1503 1504 1505
| Name   | Type    | Mandatory  | Description         |
| ------ | ------ | ---- | ----------- |
| offset | number | Yes   | Position to check.|
S
shawn_he 已提交
1506

S
shawn_he 已提交
1507
**Return value**
S
shawn_he 已提交
1508

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

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


S
shawn_he 已提交
1522
## i18n.getTimeZone<sup>7+</sup>
S
shawn_he 已提交
1523

S
shawn_he 已提交
1524
getTimeZone(zoneID?: string): TimeZone
S
shawn_he 已提交
1525

S
shawn_he 已提交
1526
Obtains the **TimeZone** object corresponding to the specified time zone ID.
S
shawn_he 已提交
1527 1528 1529

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

S
shawn_he 已提交
1530 1531 1532 1533 1534 1535
**Parameters**

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

S
shawn_he 已提交
1536
**Return value**
S
shawn_he 已提交
1537

S
shawn_he 已提交
1538 1539 1540
| Type      | Description          |
| -------- | ------------ |
| TimeZone | **TimeZone** object corresponding to the time zone ID.|
S
shawn_he 已提交
1541

S
shawn_he 已提交
1542
**Example**
S
shawn_he 已提交
1543
  ```js
S
shawn_he 已提交
1544
  var timezone = i18n.getTimeZone();
S
shawn_he 已提交
1545 1546 1547
  ```


S
shawn_he 已提交
1548
## TimeZone
Z
zengyawen 已提交
1549 1550


S
shawn_he 已提交
1551
### getID
S
shawn_he 已提交
1552

S
shawn_he 已提交
1553
getID(): string
S
shawn_he 已提交
1554

S
shawn_he 已提交
1555
Obtains the ID of the specified **TimeZone** object.
S
shawn_he 已提交
1556

S
shawn_he 已提交
1557
**System capability**: SystemCapability.Global.I18n
S
shawn_he 已提交
1558

S
shawn_he 已提交
1559
**Return value**
S
shawn_he 已提交
1560

S
shawn_he 已提交
1561 1562 1563
| Type    | Description          |
| ------ | ------------ |
| string | Time zone ID corresponding to the **TimeZone** object.|
S
shawn_he 已提交
1564

S
shawn_he 已提交
1565
**Example**
S
shawn_he 已提交
1566
  ```js
S
shawn_he 已提交
1567 1568
  var timezone = i18n.getTimeZone();
  timezone.getID();
S
shawn_he 已提交
1569 1570 1571
  ```


S
shawn_he 已提交
1572
### getDisplayName
S
shawn_he 已提交
1573 1574 1575 1576 1577 1578 1579

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 已提交
1580
**Parameters**
S
shawn_he 已提交
1581

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

S
shawn_he 已提交
1587
**Return value**
S
shawn_he 已提交
1588

S
shawn_he 已提交
1589 1590 1591
| Type    | Description           |
| ------ | ------------- |
| string | Representation of the **TimeZone** object in the specified locale.|
S
shawn_he 已提交
1592

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


S
shawn_he 已提交
1600
### getRawOffset
S
shawn_he 已提交
1601 1602 1603 1604 1605 1606 1607

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

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

S
shawn_he 已提交
1614
**Example**
S
shawn_he 已提交
1615
  ```js
S
shawn_he 已提交
1616 1617 1618 1619 1620
  var timezone = i18n.getTimeZone();
  timezone.getRawOffset();
  ```


S
shawn_he 已提交
1621
### getOffset
S
shawn_he 已提交
1622 1623 1624 1625 1626 1627 1628

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

S
shawn_he 已提交
1631 1632 1633
| 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 已提交
1634

S
shawn_he 已提交
1635
**Example**
S
shawn_he 已提交
1636
  ```js
S
shawn_he 已提交
1637 1638 1639
  var timezone = i18n.getTimeZone();
  timezone.getOffset(1234567890);
  ```
S
shawn_he 已提交
1640

S
shawn_he 已提交
1641

S
shawn_he 已提交
1642 1643 1644 1645 1646 1647 1648 1649 1650
### 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 已提交
1651

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

**Example**
S
shawn_he 已提交
1657
  ```ts
S
shawn_he 已提交
1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670
  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 已提交
1671

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

**Example**
S
shawn_he 已提交
1677
  ```ts
S
shawn_he 已提交
1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690
  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 已提交
1691

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

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

S
shawn_he 已提交
1699 1700
| Type    | Description                |
| ------ | ------------------ |
S
shawn_he 已提交
1701 1702 1703
| string | Localized display of the time zone city in the specified locale.|

**Example**
S
shawn_he 已提交
1704
  ```ts
S
shawn_he 已提交
1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717
  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 已提交
1718

S
shawn_he 已提交
1719 1720
| Name   | Type    | Mandatory  | Description    |
| ------ | ------ | ---- | ------ |
S
shawn_he 已提交
1721 1722 1723
| cityID | string | Yes   | Time zone city ID.|

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

S
shawn_he 已提交
1725 1726
| Type      | Description         |
| -------- | ----------- |
S
shawn_he 已提交
1727 1728 1729
| TimeZone | **TimeZone** object corresponding to the specified time zone city ID.|

**Example**
S
shawn_he 已提交
1730
  ```ts
S
shawn_he 已提交
1731 1732 1733 1734
  var timezone = i18n.TimeZone.getTimezoneFromCity("Shanghai");
  ```


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

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

**Example**
S
shawn_he 已提交
1753
  ```ts
S
shawn_he 已提交
1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766
  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 已提交
1767

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

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

S
shawn_he 已提交
1774 1775
| Type                                | Description   |
| ---------------------------------- | ----- |
S
shawn_he 已提交
1776 1777 1778
| [Transliterator](#transliterator9) | **Transliterator** object.|

**Example**
S
shawn_he 已提交
1779
  ```ts
S
shawn_he 已提交
1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792
  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 已提交
1793

S
shawn_he 已提交
1794 1795 1796
| Name | Type    | Mandatory  | Description    |
| ---- | ------ | ---- | ------ |
| text | string | Yes   | Input string.|
S
shawn_he 已提交
1797 1798

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

S
shawn_he 已提交
1800 1801
| Type    | Description      |
| ------ | -------- |
S
shawn_he 已提交
1802 1803 1804
| string | Target string.|

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

S
shawn_he 已提交
1810

S
shawn_he 已提交
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 2102 2103 2104
## 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 已提交
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 2633 2634 2635


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