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

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

S
shawn_he 已提交
9 10

## Modules to Import
Z
zengyawen 已提交
11 12 13 14 15 16

```
import i18n from '@ohos.i18n';
```


S
shawn_he 已提交
17
## i18n.getDisplayLanguage
Z
zengyawen 已提交
18

S
shawn_he 已提交
19
getDisplayLanguage(language: string, locale: string, sentenceCase?: boolean): string
Z
zengyawen 已提交
20 21 22

Obtains the localized script for the specified language.

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

S
shawn_he 已提交
25 26 27 28 29 30
**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.|
S
shawn_he 已提交
31

S
shawn_he 已提交
32
**Return value**
S
shawn_he 已提交
33 34 35
| Type    | Description           |
| ------ | ------------- |
| string | Localized script for the specified language.|
S
shawn_he 已提交
36

S
shawn_he 已提交
37
**Example**
S
shawn_he 已提交
38
  ```js
S
shawn_he 已提交
39 40 41 42 43 44 45 46
  i18n.getDisplayLanguage("zh", "en-GB", true);
  i18n.getDisplayLanguage("zh", "en-GB");
  ```


## i18n.getDisplayCountry

getDisplayCountry(country: string, locale: string, sentenceCase?: boolean): string
Z
zengyawen 已提交
47 48 49

Obtains the localized script for the specified country.

S
shawn_he 已提交
50 51
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
52 53 54 55 56 57
**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.|
S
shawn_he 已提交
58

S
shawn_he 已提交
59
**Return value**
S
shawn_he 已提交
60 61 62
| Type    | Description           |
| ------ | ------------- |
| string | Localized script for the specified country.|
S
shawn_he 已提交
63

S
shawn_he 已提交
64
**Example**
S
shawn_he 已提交
65
  ```js
S
shawn_he 已提交
66 67 68 69 70
  i18n.getDisplayCountry("zh-CN", "en-GB", true);
  i18n.getDisplayCountry("zh-CN", "en-GB");
  ```


S
shawn_he 已提交
71
## i18n.isRTL<sup>7+</sup>
S
shawn_he 已提交
72 73

isRTL(locale: string): boolean
Z
zengyawen 已提交
74 75 76

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

S
shawn_he 已提交
77
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
78

S
shawn_he 已提交
79 80 81 82
**Parameters**
| Name   | Type    | Description     |
| ------ | ------ | ------- |
| locale | string | Locale ID.|
Z
zengyawen 已提交
83

S
shawn_he 已提交
84
**Return value**
S
shawn_he 已提交
85 86 87
| Type     | Description                                      |
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the localized script is displayed from right to left; returns **false** otherwise.|
Z
zengyawen 已提交
88

S
shawn_he 已提交
89
**Example**
S
shawn_he 已提交
90
  ```js
S
shawn_he 已提交
91 92 93
  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.
  ```
Z
zengyawen 已提交
94 95


S
shawn_he 已提交
96
## i18n.getSystemLanguage
Z
zengyawen 已提交
97

S
shawn_he 已提交
98
getSystemLanguage(): string
Z
zengyawen 已提交
99

S
shawn_he 已提交
100
Obtains the system language.
Z
zengyawen 已提交
101

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

S
shawn_he 已提交
104
**Return value**
S
shawn_he 已提交
105 106 107
| Type    | Description     |
| ------ | ------- |
| string | System language ID.|
S
shawn_he 已提交
108

S
shawn_he 已提交
109
**Example**
S
shawn_he 已提交
110
  ```js
S
shawn_he 已提交
111 112
  i18n.getSystemLanguage();
  ```
Z
zengyawen 已提交
113 114


S
shawn_he 已提交
115 116 117 118
## i18n.setSystemLanguage

setSystemLanguage(language: string): boolean

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

S
shawn_he 已提交
121 122
This is a system API.

S
shawn_he 已提交
123
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
S
shawn_he 已提交
124

S
shawn_he 已提交
125 126
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
127 128 129 130
**Parameters**
| Name     | Type    | Description   |
| -------- | ------ | ----- |
| language | string | Language ID.|
S
shawn_he 已提交
131

S
shawn_he 已提交
132
**Return value**
S
shawn_he 已提交
133 134 135
| Type     | Description                                   |
| ------- | ------------------------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
S
shawn_he 已提交
136

S
shawn_he 已提交
137
**Example**
S
shawn_he 已提交
138
  ```js
S
shawn_he 已提交
139 140 141 142 143 144
  i18n.setSystemLanguage('zh');
  ```


## i18n.getSystemLanguages

S
shawn_he 已提交
145
getSystemLanguages(): Array&lt;string&gt;
S
shawn_he 已提交
146 147 148 149 150

Obtains the list of system languages.

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

S
shawn_he 已提交
151 152 153
**System API**: This is a system API and cannot be called by third-party applications.

**Return value**
S
shawn_he 已提交
154 155 156
| Type                 | Description          |
| ------------------- | ------------ |
| Array&lt;string&gt; | List of the IDs of system languages.|
S
shawn_he 已提交
157

S
shawn_he 已提交
158
**Example**
S
shawn_he 已提交
159
  ```js
S
shawn_he 已提交
160 161 162 163 164 165
  i18n.getSystemLanguages();
  ```


## i18n.getSystemCountries

S
shawn_he 已提交
166
getSystemCountries(language: string): Array&lt;string&gt;
S
shawn_he 已提交
167 168 169 170 171

Obtains the list of countries and regions supported for the specified language.

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

S
shawn_he 已提交
172 173
**System API**: This is a system API and cannot be called by third-party applications.

S
shawn_he 已提交
174 175 176 177
**Parameters**
| Name     | Type    | Description   |
| -------- | ------ | ----- |
| language | string | Language ID.|
S
shawn_he 已提交
178

S
shawn_he 已提交
179
**Return value**
S
shawn_he 已提交
180 181 182
| Type                 | Description          |
| ------------------- | ------------ |
| Array&lt;string&gt; | List of the IDs of the countries and regions supported for the specified language.|
S
shawn_he 已提交
183

S
shawn_he 已提交
184
**Example**
S
shawn_he 已提交
185
  ```js
S
shawn_he 已提交
186 187 188 189
  i18n.getSystemCountries('zh');
  ```


S
shawn_he 已提交
190
## i18n.getSystemRegion
Z
zengyawen 已提交
191

S
shawn_he 已提交
192
getSystemRegion(): string
Z
zengyawen 已提交
193

S
shawn_he 已提交
194 195 196 197
Obtains the system region.

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

S
shawn_he 已提交
198
**Return value**
S
shawn_he 已提交
199 200 201
| Type    | Description     |
| ------ | ------- |
| string | System region ID.|
Z
zengyawen 已提交
202

S
shawn_he 已提交
203
**Example**
S
shawn_he 已提交
204
  ```js
S
shawn_he 已提交
205 206
  i18n.getSystemRegion();
  ```
Z
zengyawen 已提交
207 208


S
shawn_he 已提交
209 210 211 212 213 214
## i18n.setSystemRegion

setSystemRegion(region: string): boolean

Sets the system region.

S
shawn_he 已提交
215 216
This is a system API.

S
shawn_he 已提交
217
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
S
shawn_he 已提交
218

S
shawn_he 已提交
219 220
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
221 222 223 224
**Parameters**
| Name   | Type    | Description   |
| ------ | ------ | ----- |
| region | string | Region ID.|
S
shawn_he 已提交
225

S
shawn_he 已提交
226
**Return value**
S
shawn_he 已提交
227 228 229
| Type     | Description                                   |
| ------- | ------------------------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
S
shawn_he 已提交
230

S
shawn_he 已提交
231
**Example**
S
shawn_he 已提交
232
  ```js
S
shawn_he 已提交
233
  i18n.setSystemRegion('CN');
S
shawn_he 已提交
234 235 236
  ```


S
shawn_he 已提交
237
## i18n.getSystemLocale
Z
zengyawen 已提交
238

S
shawn_he 已提交
239
getSystemLocale(): string
Z
zengyawen 已提交
240 241 242

Obtains the system locale.

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

S
shawn_he 已提交
245
**Return value**
S
shawn_he 已提交
246 247 248
| Type    | Description     |
| ------ | ------- |
| string | System locale ID.|
Z
zengyawen 已提交
249

S
shawn_he 已提交
250
**Example**
S
shawn_he 已提交
251
  ```js
S
shawn_he 已提交
252 253
  i18n.getSystemLocale();
  ```
Z
zengyawen 已提交
254 255


S
shawn_he 已提交
256 257 258 259 260 261
## i18n.setSystemLocale

setSystemLocale(locale: string): boolean

Sets the system locale.

S
shawn_he 已提交
262 263
This is a system API.

S
shawn_he 已提交
264
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
S
shawn_he 已提交
265

S
shawn_he 已提交
266 267
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
268 269 270 271
**Parameters**
| Name   | Type    | Description             |
| ------ | ------ | --------------- |
| locale | string | System locale ID, for example, **zh-CN**.|
S
shawn_he 已提交
272

S
shawn_he 已提交
273
**Return value**
S
shawn_he 已提交
274 275 276
| Type     | Description                                      |
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
S
shawn_he 已提交
277

S
shawn_he 已提交
278
**Example**
S
shawn_he 已提交
279
  ```js
S
shawn_he 已提交
280 281 282 283 284 285 286 287 288 289 290 291
  i18n.setSystemLocale('zh-CN');
  ```


## i18n.isSuggested

isSuggested(language: string, region?: string): boolean

Checks whether the system language matches the specified region.

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

S
shawn_he 已提交
292 293
**System API**: This is a system API and cannot be called by third-party applications.

S
shawn_he 已提交
294 295 296 297 298
**Parameters**
| 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 已提交
299

S
shawn_he 已提交
300
**Return value**
S
shawn_he 已提交
301 302 303
| Type     | Description                                      |
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the system language matches the specified region; returns **false** otherwise.|
S
shawn_he 已提交
304

S
shawn_he 已提交
305
**Example**
S
shawn_he 已提交
306
  ```js
S
shawn_he 已提交
307 308 309 310
  i18n.isSuggested('zh', 'CN');
  ```


S
shawn_he 已提交
311
## i18n.getCalendar<sup>8+</sup>
Z
zengyawen 已提交
312

S
shawn_he 已提交
313
getCalendar(locale: string, type? : string): Calendar
Z
zengyawen 已提交
314

S
shawn_he 已提交
315
Obtains a **Calendar** object.
Z
zengyawen 已提交
316

S
shawn_he 已提交
317
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
318

S
shawn_he 已提交
319 320 321 322 323
**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.|
S
shawn_he 已提交
324

S
shawn_he 已提交
325
**Return value**
S
shawn_he 已提交
326 327 328
| Type                    | Description   |
| ---------------------- | ----- |
| [Calendar](#calendar8) | **Calendar** object.|
S
shawn_he 已提交
329

S
shawn_he 已提交
330
**Example**
S
shawn_he 已提交
331
  ```js
S
shawn_he 已提交
332 333 334 335 336 337 338 339 340 341 342 343 344 345 346
  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

S
shawn_he 已提交
347 348 349 350
**Parameters**
| Name | Type  | Mandatory  | Description               |
| ---- | ---- | ---- | ----------------- |
| date | Date | Yes   | Date to be set for the **Calendar** object.|
S
shawn_he 已提交
351

S
shawn_he 已提交
352
**Example**
S
shawn_he 已提交
353
  ```js
S
shawn_he 已提交
354
  var calendar = i18n.getCalendar("en-US", "gregory");
S
shawn_he 已提交
355 356 357 358 359 360 361 362 363 364 365 366 367
  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

S
shawn_he 已提交
368 369 370 371
**Parameters**
| Name | Type    | Mandatory  | Description                                      |
| ---- | ------ | ---- | ---------------------------------------- |
| time | number | Yes   | Number of milliseconds that have elapsed since the Unix epoch.|
S
shawn_he 已提交
372

S
shawn_he 已提交
373
**Example**
S
shawn_he 已提交
374
  ```js
S
shawn_he 已提交
375
  var calendar = i18n.getCalendar("en-US", "gregory");
S
shawn_he 已提交
376 377 378 379 380 381 382 383 384 385 386 387
  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

S
shawn_he 已提交
388 389 390 391 392 393 394 395 396
**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. |
S
shawn_he 已提交
397

S
shawn_he 已提交
398
**Example**
S
shawn_he 已提交
399
  ```js
S
shawn_he 已提交
400
  var calendar = i18n.getCalendar("zh-Hans");
S
shawn_he 已提交
401
  calendar.set(2021, 10, 1, 8, 0, 0); // set time to 2021.10.1 08:00:00
S
shawn_he 已提交
402 403 404 405 406 407 408 409 410 411 412
  ```


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

setTimeZone(timezone: string): void

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

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

S
shawn_he 已提交
413 414 415 416
**Parameters**
| Name     | Type    | Mandatory  | Description                       |
| -------- | ------ | ---- | ------------------------- |
| timezone | string | Yes   | Time zone, for example, **Asia/Shanghai**.|
S
shawn_he 已提交
417

S
shawn_he 已提交
418
**Example**
S
shawn_he 已提交
419
  ```js
S
shawn_he 已提交
420 421 422 423 424 425 426 427 428 429 430 431 432
  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 已提交
433
**Return value**
S
shawn_he 已提交
434 435 436
| Type    | Description        |
| ------ | ---------- |
| string | Time zone of the **Calendar** object.|
S
shawn_he 已提交
437

S
shawn_he 已提交
438
**Example**
S
shawn_he 已提交
439
  ```js
S
shawn_he 已提交
440 441 442 443 444 445 446 447 448 449 450 451 452 453
  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 已提交
454
**Return value**
S
shawn_he 已提交
455 456 457
| Type    | Description                   |
| ------ | --------------------- |
| number | Start day of a week. The value **1** indicates Sunday, and the value **7** indicates Saturday.|
S
shawn_he 已提交
458

S
shawn_he 已提交
459
**Example**
S
shawn_he 已提交
460
  ```js
S
shawn_he 已提交
461
  var calendar = i18n.getCalendar("en-US", "gregory");
S
shawn_he 已提交
462 463 464 465 466 467 468 469 470 471 472 473
  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 已提交
474 475 476 477
**Parameters**
| 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 已提交
478

S
shawn_he 已提交
479
**Example**
S
shawn_he 已提交
480
  ```js
S
shawn_he 已提交
481 482 483
  var calendar = i18n.getCalendar("zh-Hans");
  calendar.setFirstDayOfWeek(0);
  ```
Z
zengyawen 已提交
484 485


S
shawn_he 已提交
486
### getMinimalDaysInFirstWeek<sup>8+</sup>
Z
zengyawen 已提交
487

S
shawn_he 已提交
488 489 490 491 492 493
getMinimalDaysInFirstWeek(): number

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

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

S
shawn_he 已提交
494
**Return value**
S
shawn_he 已提交
495 496 497
| Type    | Description          |
| ------ | ------------ |
| number | Minimum number of days in the first week of a year.|
S
shawn_he 已提交
498

S
shawn_he 已提交
499
**Example**
S
shawn_he 已提交
500
  ```js
S
shawn_he 已提交
501 502 503
  var calendar = i18n.getCalendar("zh-Hans");
  calendar.getMinimalDaysInFirstWeek();
  ```
Z
zengyawen 已提交
504 505


S
shawn_he 已提交
506
### setMinimalDaysInFirstWeek<sup>8+</sup>
Z
zengyawen 已提交
507

S
shawn_he 已提交
508
setMinimalDaysInFirstWeek(value: number): void
Z
zengyawen 已提交
509 510 511

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

S
shawn_he 已提交
512 513
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
514 515 516 517
**Parameters**
| Name  | Type    | Mandatory  | Description          |
| ----- | ------ | ---- | ------------ |
| value | number | No   | Minimum number of days in the first week of a year.|
S
shawn_he 已提交
518

S
shawn_he 已提交
519
**Example**
S
shawn_he 已提交
520
  ```js
S
shawn_he 已提交
521 522 523 524 525 526 527 528 529 530 531 532 533
  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 已提交
534 535 536 537
**Parameters**
| 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 已提交
538

S
shawn_he 已提交
539
**Return value**
S
shawn_he 已提交
540 541 542
| 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 已提交
543

S
shawn_he 已提交
544
**Example**
S
shawn_he 已提交
545
  ```js
S
shawn_he 已提交
546
  var calendar = i18n.getCalendar("zh-Hans");
S
shawn_he 已提交
547
  calendar.set(2021, 10, 1, 8, 0, 0); // set time to 2021.10.1 08:00:00
S
shawn_he 已提交
548 549 550 551 552 553 554 555 556 557 558 559
  calendar.get("hour_of_day"); // 8
  ```


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

getDisplayName(locale: string): string

Obtains the name of the **Calendar** object displayed for the specified locale.

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

S
shawn_he 已提交
560 561 562 563
**Parameters**
| 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 已提交
564

S
shawn_he 已提交
565
**Return value**
S
shawn_he 已提交
566 567 568
| Type    | Description                 |
| ------ | ------------------- |
| string | Name of the **Calendar** object displayed for the specified locale.|
S
shawn_he 已提交
569

S
shawn_he 已提交
570
**Example**
S
shawn_he 已提交
571
  ```js
S
shawn_he 已提交
572 573 574 575 576 577 578 579 580 581 582 583 584
  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 已提交
585 586 587 588
**Parameters**
| 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 已提交
589

S
shawn_he 已提交
590
**Return value**
S
shawn_he 已提交
591 592 593
| Type     | Description                                 |
| ------- | ----------------------------------- |
| boolean | Returns **true** if the date is a weekend; returns **false** if the date is a weekday.|
S
shawn_he 已提交
594

S
shawn_he 已提交
595
**Example**
S
shawn_he 已提交
596
  ```js
S
shawn_he 已提交
597
  var calendar = i18n.getCalendar("zh-Hans");
S
shawn_he 已提交
598
  calendar.set(2021, 11, 11, 8, 0, 0); // set time to 2021.11.11 08:00:00
S
shawn_he 已提交
599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614
  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 已提交
615 616

Parameters
S
shawn_he 已提交
617 618 619 620
| Name    | Type                                      | Mandatory  | Description              |
| ------- | ---------------------------------------- | ---- | ---------------- |
| country | string                                   | Yes   | Country or region to which the phone number to be formatted belongs.|
| options | [PhoneNumberFormatOptions](#phonenumberformatoptions8) | No   | Options of the **PhoneNumberFormat** object. |
Z
zengyawen 已提交
621

S
shawn_he 已提交
622
**Example**
S
shawn_he 已提交
623
  ```js
S
shawn_he 已提交
624 625 626 627 628 629 630
  var phoneNumberFormat= new i18n.PhoneNumberFormat("CN", {"type": "E164"});
  ```


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

isValidNumber(number: string): boolean
Z
zengyawen 已提交
631 632 633

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

S
shawn_he 已提交
634 635
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
636 637 638 639
**Parameters**
| Name   | Type    | Mandatory  | Description       |
| ------ | ------ | ---- | --------- |
| number | string | Yes   | Phone number to be checked.|
S
shawn_he 已提交
640

S
shawn_he 已提交
641
**Return value**
S
shawn_he 已提交
642 643 644
| Type     | Description                                   |
| ------- | ------------------------------------- |
| boolean | Returns **true** if the phone number format is valid; returns **false** otherwise.|
S
shawn_he 已提交
645

S
shawn_he 已提交
646
**Example**
S
shawn_he 已提交
647
  ```js
S
shawn_he 已提交
648 649 650 651 652 653 654 655
  var phonenumberfmt = new i18n.PhoneNumberFormat("CN");
  phonenumberfmt.isValidNumber("15812312312");
  ```


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

format(number: string): string
Z
zengyawen 已提交
656 657 658

Formats a phone number.

S
shawn_he 已提交
659 660
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
661 662 663 664
**Parameters**
| Name   | Type    | Mandatory  | Description        |
| ------ | ------ | ---- | ---------- |
| number | string | Yes   | Phone number to be formatted.|
S
shawn_he 已提交
665

S
shawn_he 已提交
666
**Return value**
S
shawn_he 已提交
667 668 669
| Type    | Description        |
| ------ | ---------- |
| string | Formatted phone number.|
S
shawn_he 已提交
670

S
shawn_he 已提交
671
**Example**
S
shawn_he 已提交
672
  ```js
S
shawn_he 已提交
673
  var phonenumberfmt = new i18n.PhoneNumberFormat("CN");
S
shawn_he 已提交
674
  phonenumberfmt.isValidNumber("15812312312");
S
shawn_he 已提交
675 676
  ```

S
shawn_he 已提交
677
### getLocationName<sup>9+</sup>
S
shawn_he 已提交
678

S
shawn_he 已提交
679
getLocationName(number: string, locale: string): string
S
shawn_he 已提交
680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696

Obtains the home location of a phone number.

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

**Parameters**
| Name   | Type    | Mandatory  | Description        |
| ------ | ------ | ---- | ---------- |
| number | string | Yes   | Phone number.|
| locale | string | Yes   | Locale ID.|

**Return value**
| Type    | Description        |
| ------ | ---------- |
| string | Home location of the phone number.|

**Example**
S
shawn_he 已提交
697 698 699
  ```js
  var phonenumberfmt = new i18n.PhoneNumberFormat("CN");
  phonenumberfmt.isValidNumber("15812312312");
S
shawn_he 已提交
700 701
  ```

S
shawn_he 已提交
702 703 704 705 706

## PhoneNumberFormatOptions<sup>8+</sup>

Defines the options for this PhoneNumberFormat object.

S
shawn_he 已提交
707
**System capability**: SystemCapability.Global.I18n
S
shawn_he 已提交
708

S
shawn_he 已提交
709 710
| Name  | Type  | Readable  | Writable  | Description                                      |
| ---- | ------ | ---- | ---- | ---------------------------------------- |
S
shawn_he 已提交
711
| 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 已提交
712 713 714


## UnitInfo<sup>8+</sup>
Z
zengyawen 已提交
715 716 717

Defines the measurement unit information.

S
shawn_he 已提交
718
**System capability**: SystemCapability.Global.I18n
S
shawn_he 已提交
719

S
shawn_he 已提交
720 721 722
| Name           | Type  | Readable  | Writable  | Description                                      |
| ------------- | ------ | ---- | ---- | ---------------------------------------- |
| unit          | string | Yes   | Yes   | Name of the measurement unit, for example, **meter**, **inch**, or **cup**.|
S
shawn_he 已提交
723
| measureSystem | string | Yes   | Yes   | Measurement system. The value can be **SI**,&nbsp;**US**, or&nbsp;**UK**.|
S
shawn_he 已提交
724 725 726 727 728 729 730


## Util<sup>8+</sup>


### unitConvert<sup>8+</sup>

S
shawn_he 已提交
731
static unitConvert(fromUnit: UnitInfo, toUnit: UnitInfo, value: number, locale: string, style?: string): string
Z
zengyawen 已提交
732 733 734

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

S
shawn_he 已提交
735 736
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
737 738 739 740 741 742 743
**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**.               |
S
shawn_he 已提交
744
| style    | string                 | No   | Style used for formatting. The value can be **long**, **short**, or **narrow**.|
S
shawn_he 已提交
745

S
shawn_he 已提交
746
**Return value**
S
shawn_he 已提交
747 748 749
| Type    | Description                     |
| ------ | ----------------------- |
| string | Character string obtained after formatting based on the measurement unit specified by **toUnit**.|
S
shawn_he 已提交
750

S
shawn_he 已提交
751
**Example**
S
shawn_he 已提交
752
  ```js
S
shawn_he 已提交
753
  i18n.Util.unitConvert({unit: "cup", measureSystem: "US"}, {unit: "liter", measureSystem: "SI"}, 1000, "en-US", "long");
S
shawn_he 已提交
754 755
  ```

S
shawn_he 已提交
756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778
### 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**
  ```
  i18n.Util.getDateOrder("zh-CN");
  ```

S
shawn_he 已提交
779

S
shawn_he 已提交
780
## getInstance<sup>8+</sup>
S
shawn_he 已提交
781

S
shawn_he 已提交
782
getInstance(locale?:string): IndexUtil
S
shawn_he 已提交
783 784 785 786 787

Creates an **IndexUtil** object.

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

S
shawn_he 已提交
788 789 790 791
**Parameters**
| Name   | Type    | Mandatory  | Description                          |
| ------ | ------ | ---- | ---------------------------- |
| locale | string | No   | A string containing locale information, including the language, optional script, and region.|
S
shawn_he 已提交
792

S
shawn_he 已提交
793
**Return value**
S
shawn_he 已提交
794 795 796
| Type                      | Description                   |
| ------------------------ | --------------------- |
| [IndexUtil](#indexutil8) | **IndexUtil** object mapping to the specified locale.|
S
shawn_he 已提交
797

S
shawn_he 已提交
798
**Example**
S
shawn_he 已提交
799
  ```js
S
shawn_he 已提交
800
  var indexUtil= i18n.getInstance("zh-CN");
S
shawn_he 已提交
801 802 803
  ```


S
shawn_he 已提交
804 805 806
## IndexUtil<sup>8+</sup>


S
shawn_he 已提交
807 808 809 810 811 812 813 814
### 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 已提交
815
**Return value**
S
shawn_he 已提交
816 817 818
| Type                 | Description                |
| ------------------- | ------------------ |
| Array&lt;string&gt; | Index list for this **locale** object.|
S
shawn_he 已提交
819

S
shawn_he 已提交
820
**Example**
S
shawn_he 已提交
821
  ```js
S
shawn_he 已提交
822 823 824 825 826 827 828
  var indexUtil = i18n.getInstance("zh-CN");
  var indexList = indexUtil.getIndexList();
  ```


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

S
shawn_he 已提交
829
addLocale(locale: string): void
S
shawn_he 已提交
830 831 832 833 834

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

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

S
shawn_he 已提交
835 836 837 838
**Parameters**
| Name   | Type    | Mandatory  | Description                          |
| ------ | ------ | ---- | ---------------------------- |
| locale | string | Yes   | A string containing locale information, including the language, optional script, and region.|
S
shawn_he 已提交
839

S
shawn_he 已提交
840
**Example**
S
shawn_he 已提交
841
  ```js
S
shawn_he 已提交
842 843 844 845 846 847 848 849 850 851 852 853 854
  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 已提交
855 856 857 858
**Parameters**
| Name | Type    | Mandatory  | Description          |
| ---- | ------ | ---- | ------------ |
| text | string | Yes   | **text** object whose index is to be obtained.|
S
shawn_he 已提交
859

S
shawn_he 已提交
860
**Return value**
S
shawn_he 已提交
861 862 863
| Type    | Description         |
| ------ | ----------- |
| string | Index of the **text** object.|
S
shawn_he 已提交
864

S
shawn_he 已提交
865
**Example**
S
shawn_he 已提交
866
  ```js
S
shawn_he 已提交
867 868 869 870 871 872 873 874 875 876
  var indexUtil= i18n.getInstance("zh-CN");
  indexUtil.getIndex("hi"); // Return h.
  ```


## Character<sup>8+</sup>


### isDigit<sup>8+</sup>

S
shawn_he 已提交
877
static isDigit(char: string): boolean
S
shawn_he 已提交
878 879 880 881 882

Checks whether the input character string is composed of digits.

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

S
shawn_he 已提交
883 884 885 886
**Parameters**
| Name | Type    | Mandatory  | Description   |
| ---- | ------ | ---- | ----- |
| char | string | Yes   | Input character.|
S
shawn_he 已提交
887

S
shawn_he 已提交
888
**Return value**
S
shawn_he 已提交
889 890 891
| Type     | Description                                  |
| ------- | ------------------------------------ |
| boolean | Returns **true** if the input character is a digit; returns **false** otherwise.|
S
shawn_he 已提交
892

S
shawn_he 已提交
893
**Example**
S
shawn_he 已提交
894
  ```js
S
shawn_he 已提交
895
  var isdigit = i18n.Character.isDigit("1"); // Return true.
S
shawn_he 已提交
896 897 898 899 900
  ```


### isSpaceChar<sup>8+</sup>

S
shawn_he 已提交
901
static isSpaceChar(char: string): boolean
Z
zengyawen 已提交
902

Z
zengyawen 已提交
903
Checks whether the input character is a space.
Z
zengyawen 已提交
904

S
shawn_he 已提交
905 906
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
907 908 909 910
**Parameters**
| Name | Type    | Mandatory  | Description   |
| ---- | ------ | ---- | ----- |
| char | string | Yes   | Input character.|
S
shawn_he 已提交
911

S
shawn_he 已提交
912
**Return value**
S
shawn_he 已提交
913 914 915
| Type     | Description                                    |
| ------- | -------------------------------------- |
| boolean | Returns **true** if the input character is a space; returns **false** otherwise.|
S
shawn_he 已提交
916

S
shawn_he 已提交
917
**Example**
S
shawn_he 已提交
918
  ```js
S
shawn_he 已提交
919
  var isspacechar = i18n.Character.isSpaceChar("a"); // Return false.
S
shawn_he 已提交
920 921 922 923 924
  ```


### isWhitespace<sup>8+</sup>

S
shawn_he 已提交
925
static isWhitespace(char: string): boolean
Z
zengyawen 已提交
926

Z
zengyawen 已提交
927
Checks whether the input character is a white space.
Z
zengyawen 已提交
928

S
shawn_he 已提交
929 930
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
931 932 933 934
**Parameters**
| Name | Type    | Mandatory  | Description   |
| ---- | ------ | ---- | ----- |
| char | string | Yes   | Input character.|
S
shawn_he 已提交
935

S
shawn_he 已提交
936
**Return value**
S
shawn_he 已提交
937 938 939
| Type     | Description                                    |
| ------- | -------------------------------------- |
| boolean | Returns **true** if the input character is a white space; returns **false** otherwise.|
S
shawn_he 已提交
940

S
shawn_he 已提交
941
**Example**
S
shawn_he 已提交
942
  ```js
S
shawn_he 已提交
943
  var isspacechar = i18n.Character.isSpaceChar("a"); // Return false.
S
shawn_he 已提交
944 945 946 947 948
  ```


### isRTL<sup>8+</sup>

S
shawn_he 已提交
949
static isRTL(char: string): boolean
S
shawn_he 已提交
950 951 952 953 954

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

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

S
shawn_he 已提交
955 956 957 958
**Parameters**
| Name | Type    | Mandatory  | Description   |
| ---- | ------ | ---- | ----- |
| char | string | Yes   | Input character.|
S
shawn_he 已提交
959

S
shawn_he 已提交
960
**Return value**
S
shawn_he 已提交
961 962 963
| Type     | Description                                      |
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the input character is of the RTL language; returns **false** otherwise.|
S
shawn_he 已提交
964

S
shawn_he 已提交
965
**Example**
S
shawn_he 已提交
966
  ```js
S
shawn_he 已提交
967
  var isrtl = i18n.Character.isRTL("a"); // Return false.
S
shawn_he 已提交
968 969 970 971 972
  ```


### isIdeograph<sup>8+</sup>

S
shawn_he 已提交
973
static isIdeograph(char: string): boolean
Z
zengyawen 已提交
974

Z
zengyawen 已提交
975
Checks whether the input character is an ideographic character.
Z
zengyawen 已提交
976

S
shawn_he 已提交
977 978
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
979 980 981 982
**Parameters**
| Name | Type    | Mandatory  | Description   |
| ---- | ------ | ---- | ----- |
| char | string | Yes   | Input character.|
S
shawn_he 已提交
983

S
shawn_he 已提交
984
**Return value**
S
shawn_he 已提交
985 986 987
| Type     | Description                                      |
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the input character is an ideographic character; returns **false** otherwise.|
S
shawn_he 已提交
988

S
shawn_he 已提交
989
**Example**
S
shawn_he 已提交
990
  ```js
S
shawn_he 已提交
991
  var isideograph = i18n.Character.isIdeograph("a"); // Return false.
S
shawn_he 已提交
992 993 994 995 996
  ```


### isLetter<sup>8+</sup>

S
shawn_he 已提交
997
static isLetter(char: string): boolean
Z
zengyawen 已提交
998

Z
zengyawen 已提交
999
Checks whether the input character is a letter.
Z
zengyawen 已提交
1000

S
shawn_he 已提交
1001 1002
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
1003 1004 1005 1006
**Parameters**
| Name | Type    | Mandatory  | Description   |
| ---- | ------ | ---- | ----- |
| char | string | Yes   | Input character.|
S
shawn_he 已提交
1007

S
shawn_he 已提交
1008
**Return value**
S
shawn_he 已提交
1009 1010 1011
| Type     | Description                                  |
| ------- | ------------------------------------ |
| boolean | Returns **true** if the input character is a letter; returns **false** otherwise.|
S
shawn_he 已提交
1012

S
shawn_he 已提交
1013
**Example**
S
shawn_he 已提交
1014
  ```js
S
shawn_he 已提交
1015
  var isletter = i18n.Character.isLetter("a"); // Return true.
S
shawn_he 已提交
1016 1017 1018 1019 1020
  ```


### isLowerCase<sup>8+</sup>

S
shawn_he 已提交
1021
static isLowerCase(char: string): boolean
Z
zengyawen 已提交
1022

Z
zengyawen 已提交
1023
Checks whether the input character is a lowercase letter.
Z
zengyawen 已提交
1024

S
shawn_he 已提交
1025 1026
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
1027 1028 1029 1030
**Parameters**
| Name | Type    | Mandatory  | Description   |
| ---- | ------ | ---- | ----- |
| char | string | Yes   | Input character.|
S
shawn_he 已提交
1031

S
shawn_he 已提交
1032
**Return value**
S
shawn_he 已提交
1033 1034 1035
| Type     | Description                                      |
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the input character is a lowercase letter; returns **false** otherwise.|
S
shawn_he 已提交
1036

S
shawn_he 已提交
1037
**Example**
S
shawn_he 已提交
1038
  ```js
S
shawn_he 已提交
1039
  var islowercase = i18n.Character.isLowerCase("a"); // Return true.
S
shawn_he 已提交
1040 1041 1042 1043 1044
  ```


### isUpperCase<sup>8+</sup>

S
shawn_he 已提交
1045
static isUpperCase(char: string): boolean
Z
zengyawen 已提交
1046

Z
zengyawen 已提交
1047
Checks whether the input character is an uppercase letter.
Z
zengyawen 已提交
1048

S
shawn_he 已提交
1049 1050
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
1051 1052 1053 1054
**Parameters**
| Name | Type    | Mandatory  | Description   |
| ---- | ------ | ---- | ----- |
| char | string | Yes   | Input character.|
S
shawn_he 已提交
1055

S
shawn_he 已提交
1056
**Return value**
S
shawn_he 已提交
1057 1058 1059
| Type     | Description                                      |
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the input character is an uppercase letter; returns **false** otherwise.|
S
shawn_he 已提交
1060

S
shawn_he 已提交
1061
**Example**
S
shawn_he 已提交
1062
  ```js
S
shawn_he 已提交
1063
  var isuppercase = i18n.Character.isUpperCase("a"); // Return false.
S
shawn_he 已提交
1064 1065 1066 1067 1068
  ```


### getType<sup>8+</sup>

S
shawn_he 已提交
1069
static getType(char: string): string
Z
zengyawen 已提交
1070 1071 1072

Obtains the type of the input character string.

S
shawn_he 已提交
1073
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1074

S
shawn_he 已提交
1075 1076 1077 1078
**Parameters**
| Name | Type    | Mandatory  | Description   |
| ---- | ------ | ---- | ----- |
| char | string | Yes   | Input character.|
Z
zengyawen 已提交
1079

S
shawn_he 已提交
1080
**Return value**
S
shawn_he 已提交
1081 1082 1083
| Type    | Description         |
| ------ | ----------- |
| string | Type of the input character.|
Z
zengyawen 已提交
1084

S
shawn_he 已提交
1085
**Example**
S
shawn_he 已提交
1086
  ```js
S
shawn_he 已提交
1087
  var type = i18n.Character.getType("a");
S
shawn_he 已提交
1088
  ```
Z
zengyawen 已提交
1089 1090


S
shawn_he 已提交
1091
## i18n.getLineInstance<sup>8+</sup>
Z
zengyawen 已提交
1092

S
shawn_he 已提交
1093
getLineInstance(locale: string): BreakIterator
Z
zengyawen 已提交
1094

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

S
shawn_he 已提交
1097
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1098

S
shawn_he 已提交
1099 1100 1101 1102
**Parameters**
| 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 已提交
1103

S
shawn_he 已提交
1104
**Return value**
S
shawn_he 已提交
1105 1106 1107
| Type                              | Description         |
| -------------------------------- | ----------- |
| [BreakIterator](#breakiterator8) | [BreakIterator](#breakiterator8) object used for text segmentation.|
Z
zengyawen 已提交
1108

S
shawn_he 已提交
1109
**Example**
S
shawn_he 已提交
1110
  ```js
S
shawn_he 已提交
1111
  var iterator = i18n.getLineInstance("en");
S
shawn_he 已提交
1112
  ```
Z
zengyawen 已提交
1113 1114


S
shawn_he 已提交
1115
## BreakIterator<sup>8+</sup>
Z
zengyawen 已提交
1116 1117


S
shawn_he 已提交
1118
### setLineBreakText<sup>8+</sup>
Z
zengyawen 已提交
1119

S
shawn_he 已提交
1120
setLineBreakText(text: string): void
Z
zengyawen 已提交
1121

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

S
shawn_he 已提交
1124
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1125

S
shawn_he 已提交
1126 1127 1128 1129
**Parameters**
| Name | Type    | Mandatory  | Description                     |
| ---- | ------ | ---- | ----------------------- |
| text | string | Yes   | Text to be processed by the **BreakIterator** object.|
Z
zengyawen 已提交
1130

S
shawn_he 已提交
1131
**Example**
S
shawn_he 已提交
1132
  ```js
S
shawn_he 已提交
1133
  var iterator = i18n.getLineInstance("en");
S
shawn_he 已提交
1134 1135
  iterator.setLineBreakText("Apple is my favorite fruit.");
  ```
Z
zengyawen 已提交
1136 1137


S
shawn_he 已提交
1138
### getLineBreakText<sup>8+</sup>
Z
zengyawen 已提交
1139

S
shawn_he 已提交
1140
getLineBreakText(): string
Z
zengyawen 已提交
1141

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

S
shawn_he 已提交
1144
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1145

S
shawn_he 已提交
1146
**Return value**
S
shawn_he 已提交
1147 1148 1149
| Type    | Description                    |
| ------ | ---------------------- |
| string | Text being processed by the **BreakIterator** object.|
Z
zengyawen 已提交
1150

S
shawn_he 已提交
1151
**Example**
S
shawn_he 已提交
1152
  ```js
S
shawn_he 已提交
1153
  var iterator = i18n.getLineInstance("en");
S
shawn_he 已提交
1154 1155 1156
  iterator.setLineBreakText("Apple is my favorite fruit.");
  iterator.getLineBreakText(); // Apple is my favorite fruit.
  ```
Z
zengyawen 已提交
1157 1158


S
shawn_he 已提交
1159
### current<sup>8+</sup>
Z
zengyawen 已提交
1160

S
shawn_he 已提交
1161 1162 1163 1164 1165 1166
current(): number

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

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

S
shawn_he 已提交
1167
**Return value**
S
shawn_he 已提交
1168 1169 1170
| Type    | Description                         |
| ------ | --------------------------- |
| number | Position of the **BreakIterator** object in the text being processed.|
S
shawn_he 已提交
1171

S
shawn_he 已提交
1172
**Example**
S
shawn_he 已提交
1173
  ```js
S
shawn_he 已提交
1174
  var iterator = i18n.getLineInstance("en");
S
shawn_he 已提交
1175
  iterator.setLineBreakText("Apple is my favorite fruit.");
S
shawn_he 已提交
1176
  iterator.current(); // 0
S
shawn_he 已提交
1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187
  ```


### 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 已提交
1188
**Return value**
S
shawn_he 已提交
1189 1190 1191
| Type    | Description               |
| ------ | ----------------- |
| number | Offset to the first text boundary of the processed text.|
S
shawn_he 已提交
1192

S
shawn_he 已提交
1193
**Example**
S
shawn_he 已提交
1194
  ```js
S
shawn_he 已提交
1195
  var iterator = i18n.getLineInstance("en");
S
shawn_he 已提交
1196
  iterator.setLineBreakText("Apple is my favorite fruit.");
S
shawn_he 已提交
1197
  iterator.first(); // 0
S
shawn_he 已提交
1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208
  ```


### 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 已提交
1209
**Return value**
S
shawn_he 已提交
1210 1211 1212
| Type    | Description                |
| ------ | ------------------ |
| number | Offset of the last text boundary of the processed text.|
S
shawn_he 已提交
1213

S
shawn_he 已提交
1214
**Example**
S
shawn_he 已提交
1215
  ```js
S
shawn_he 已提交
1216
  var iterator = i18n.getLineInstance("en");
S
shawn_he 已提交
1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229
  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 已提交
1230 1231 1232 1233
**Parameters**
| 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 已提交
1234

S
shawn_he 已提交
1235
**Return value**
S
shawn_he 已提交
1236 1237 1238
| 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 已提交
1239

S
shawn_he 已提交
1240
**Example**
S
shawn_he 已提交
1241
  ```js
S
shawn_he 已提交
1242
  var iterator = i18n.getLineInstance("en");
S
shawn_he 已提交
1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257
  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 已提交
1258
**Return value**
S
shawn_he 已提交
1259 1260 1261
| 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 已提交
1262

S
shawn_he 已提交
1263
**Example**
S
shawn_he 已提交
1264
  ```js
S
shawn_he 已提交
1265
  var iterator = i18n.getLineInstance("en");
S
shawn_he 已提交
1266 1267 1268 1269 1270
  iterator.setLineBreakText("Apple is my favorite fruit.");
  iterator.first(); // 0
  iterator.next(3); // 12
  iterator.previous(); // 9
  ```
Z
zengyawen 已提交
1271 1272


S
shawn_he 已提交
1273
### following<sup>8+</sup>
Z
zengyawen 已提交
1274

S
shawn_he 已提交
1275
following(offset: number): number
Z
zengyawen 已提交
1276

S
shawn_he 已提交
1277
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 已提交
1278

S
shawn_he 已提交
1279
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1280

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

S
shawn_he 已提交
1286
**Return value**
S
shawn_he 已提交
1287 1288 1289
| 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 已提交
1290

S
shawn_he 已提交
1291
**Example**
S
shawn_he 已提交
1292
  ```js
S
shawn_he 已提交
1293
  var iterator = i18n.getLineInstance("en");
S
shawn_he 已提交
1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308
  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 已提交
1309 1310 1311 1312
**Parameters**
| Name   | Type    | Mandatory  | Description         |
| ------ | ------ | ---- | ----------- |
| offset | number | Yes   | Position to check.|
S
shawn_he 已提交
1313

S
shawn_he 已提交
1314
**Return value**
S
shawn_he 已提交
1315 1316 1317
| Type     | Description                             |
| ------- | ------------------------------- |
| boolean | Returns **true** if the position specified by the offset is a text boundary; returns **false** otherwise.|
S
shawn_he 已提交
1318

S
shawn_he 已提交
1319
**Example**
S
shawn_he 已提交
1320
  ```js
S
shawn_he 已提交
1321
  var iterator = i18n.getLineInstance("en");
S
shawn_he 已提交
1322 1323 1324 1325 1326 1327
  iterator.setLineBreakText("Apple is my favorite fruit.");
  iterator.isBoundary(0); // true;
  iterator.isBoundary(5); // false;
  ```


S
shawn_he 已提交
1328
## i18n.is24HourClock<sup>7+</sup>
S
shawn_he 已提交
1329 1330 1331 1332 1333 1334 1335

is24HourClock(): boolean

Checks whether the 24-hour clock is used.

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

S
shawn_he 已提交
1336
**Return value**
S
shawn_he 已提交
1337 1338 1339
| Type     | Description                                      |
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the 24-hour clock is used; returns **false** otherwise.|
S
shawn_he 已提交
1340

S
shawn_he 已提交
1341
**Example**
S
shawn_he 已提交
1342
  ```js
S
shawn_he 已提交
1343 1344 1345 1346
  var is24HourClock = i18n.is24HourClock();
  ```


S
shawn_he 已提交
1347
## i18n.set24HourClock<sup>7+</sup>
S
shawn_he 已提交
1348 1349

set24HourClock(option: boolean): boolean
Z
zengyawen 已提交
1350 1351 1352

Sets the 24-hour clock.

S
shawn_he 已提交
1353
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
S
shawn_he 已提交
1354

S
shawn_he 已提交
1355 1356
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
1357 1358 1359 1360
**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.|
S
shawn_he 已提交
1361

S
shawn_he 已提交
1362
**Return value**
S
shawn_he 已提交
1363 1364 1365
| Type     | Description                           |
| ------- | ----------------------------- |
| boolean | Returns **true** if the 24-hour clock is enabled; returns **false** otherwise.|
S
shawn_he 已提交
1366

S
shawn_he 已提交
1367
**Example**
S
shawn_he 已提交
1368
  ```js
S
shawn_he 已提交
1369
  // Set the system time to the 24-hour clock.
S
shawn_he 已提交
1370
  var success = i18n.set24HourClock(true);
S
shawn_he 已提交
1371 1372 1373 1374 1375 1376
  ```


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

addPreferredLanguage(language: string, index?: number): boolean
Z
zengyawen 已提交
1377 1378 1379

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

S
shawn_he 已提交
1380
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
S
shawn_he 已提交
1381

S
shawn_he 已提交
1382 1383
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
1384 1385 1386 1387 1388
**Parameters**
| Name     | Type    | Mandatory  | Description        |
| -------- | ------ | ---- | ---------- |
| language | string | Yes   | Preferred language to add. |
| index    | number | No   | Position to which the preferred language is added.|
S
shawn_he 已提交
1389

S
shawn_he 已提交
1390
**Return value**
S
shawn_he 已提交
1391 1392 1393
| Type     | Description                           |
| ------- | ----------------------------- |
| boolean | Returns **true** if the preferred language is successfully added; returns **false** otherwise.|
S
shawn_he 已提交
1394

S
shawn_he 已提交
1395
**Example**
S
shawn_he 已提交
1396
  ```js
S
shawn_he 已提交
1397 1398 1399 1400 1401 1402 1403
  // Add zh-CN to the preferred language list.
  var language = 'zh-CN';
  var index = 0;
  var success = i18n.addPreferredLanguage(language, index);
  ```


S
shawn_he 已提交
1404
## i18n.removePreferredLanguage<sup>8+</sup>
S
shawn_he 已提交
1405

S
shawn_he 已提交
1406
removePreferredLanguage(index: number): boolean
Z
zengyawen 已提交
1407 1408 1409

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

S
shawn_he 已提交
1410
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
S
shawn_he 已提交
1411

S
shawn_he 已提交
1412
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1413

S
shawn_he 已提交
1414 1415 1416 1417
**Parameters**
| Name  | Type    | Mandatory  | Description                   |
| ----- | ------ | ---- | --------------------- |
| index | number | Yes   | Position of the preferred language to delete.|
Z
zengyawen 已提交
1418

S
shawn_he 已提交
1419
**Return value**
S
shawn_he 已提交
1420 1421 1422
| Type     | Description                           |
| ------- | ----------------------------- |
| boolean | Returns **true** if the preferred language is deleted; returns **false** otherwise.|
Z
zengyawen 已提交
1423

S
shawn_he 已提交
1424
**Example**
S
shawn_he 已提交
1425
  ```js
S
shawn_he 已提交
1426 1427 1428 1429
  // Delete the first preferred language from the preferred language list.
  var index = 0;
  var success = i18n.removePreferredLanguage(index);
  ```
Z
zengyawen 已提交
1430 1431


S
shawn_he 已提交
1432
## i18n.getPreferredLanguageList<sup>8+</sup>
Z
zengyawen 已提交
1433

S
shawn_he 已提交
1434
getPreferredLanguageList(): Array&lt;string&gt;
Z
zengyawen 已提交
1435

S
shawn_he 已提交
1436
Obtains the list of preferred languages.
Z
zengyawen 已提交
1437

S
shawn_he 已提交
1438
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1439

S
shawn_he 已提交
1440
**Return value**
S
shawn_he 已提交
1441 1442 1443
| Type                 | Description       |
| ------------------- | --------- |
| Array&lt;string&gt; | List of preferred languages.|
Z
zengyawen 已提交
1444

S
shawn_he 已提交
1445
**Example**
S
shawn_he 已提交
1446
  ```js
S
shawn_he 已提交
1447 1448
  var preferredLanguageList = i18n.getPreferredLanguageList();
  ```
Z
zengyawen 已提交
1449 1450


S
shawn_he 已提交
1451
## i18n.getFirstPreferredLanguage<sup>8+</sup>
Z
zengyawen 已提交
1452

S
shawn_he 已提交
1453 1454
getFirstPreferredLanguage(): string

S
shawn_he 已提交
1455
Obtains the first language in the preferred language list.
Z
zengyawen 已提交
1456

S
shawn_he 已提交
1457
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1458

S
shawn_he 已提交
1459
**Return value**
S
shawn_he 已提交
1460 1461 1462
| Type    | Description            |
| ------ | -------------- |
| string | First language in the preferred language list.|
Z
zengyawen 已提交
1463

S
shawn_he 已提交
1464
**Example**
S
shawn_he 已提交
1465
  ```js
S
shawn_he 已提交
1466 1467
  var firstPreferredLanguage = i18n.getFirstPreferredLanguage();
  ```
S
shawn_he 已提交
1468 1469


S
shawn_he 已提交
1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483
## i18n.getAppPreferredLanguage<sup>9+</sup>

getAppPreferredLanguage(): string

Obtains the preferred language of an application.

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

**Return value**
| Type    | Description            |
| ------ | -------------- |
| string | Preferred language of the application.|

**Example**
S
shawn_he 已提交
1484
  ```js
S
shawn_he 已提交
1485 1486 1487 1488
  var appPreferredLanguage = i18n.getAppPreferredLanguage();
  ```


S
shawn_he 已提交
1489
## i18n.getTimeZone<sup>7+</sup>
S
shawn_he 已提交
1490 1491 1492 1493 1494 1495 1496

getTimeZone(zoneID?: string): TimeZone

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

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

S
shawn_he 已提交
1497 1498 1499 1500
**Parameters**
| Name   | Type    | Mandatory  | Description   |
| ------ | ------ | ---- | ----- |
| zondID | string | No   | Time zone ID.|
S
shawn_he 已提交
1501

S
shawn_he 已提交
1502
**Return value**
S
shawn_he 已提交
1503 1504 1505
| Type      | Description          |
| -------- | ------------ |
| TimeZone | **TimeZone** object corresponding to the time zone ID.|
S
shawn_he 已提交
1506

S
shawn_he 已提交
1507
**Example**
S
shawn_he 已提交
1508
  ```js
S
shawn_he 已提交
1509 1510 1511 1512
  var timezone = i18n.getTimeZone();
  ```


S
shawn_he 已提交
1513
## TimeZone
S
shawn_he 已提交
1514 1515


S
shawn_he 已提交
1516
### getID
S
shawn_he 已提交
1517 1518 1519 1520 1521 1522 1523

getID(): string

Obtains the ID of the specified **TimeZone** object.

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

S
shawn_he 已提交
1524
**Return value**
S
shawn_he 已提交
1525 1526 1527
| Type    | Description          |
| ------ | ------------ |
| string | Time zone ID corresponding to the **TimeZone** object.|
S
shawn_he 已提交
1528

S
shawn_he 已提交
1529
**Example**
S
shawn_he 已提交
1530
  ```js
S
shawn_he 已提交
1531 1532 1533 1534 1535
  var timezone = i18n.getTimeZone();
  timezone.getID();
  ```


S
shawn_he 已提交
1536
### getDisplayName
S
shawn_he 已提交
1537 1538 1539 1540 1541 1542 1543

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 已提交
1544 1545 1546 1547 1548
**Parameters**
| Name   | Type     | Mandatory  | Description                  |
| ------ | ------- | ---- | -------------------- |
| locale | string  | No   | System locale ID.               |
| isDST  | boolean | No   | Whether to consider DST when obtaining the representation of the **TimeZone** object.|
S
shawn_he 已提交
1549

S
shawn_he 已提交
1550
**Return value**
S
shawn_he 已提交
1551 1552 1553
| Type    | Description           |
| ------ | ------------- |
| string | Representation of the **TimeZone** object in the specified locale.|
S
shawn_he 已提交
1554

S
shawn_he 已提交
1555
**Example**
S
shawn_he 已提交
1556
  ```js
S
shawn_he 已提交
1557 1558 1559 1560 1561
  var timezone = i18n.getTimeZone();
  timezone.getDisplayName("zh-CN", false);
  ```


S
shawn_he 已提交
1562
### getRawOffset
S
shawn_he 已提交
1563 1564 1565 1566 1567 1568 1569

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 已提交
1570
**Return value**
S
shawn_he 已提交
1571 1572 1573
| Type    | Description                 |
| ------ | ------------------- |
| number | Offset between the time zone represented by the **TimeZone** object and the UTC time zone.|
S
shawn_he 已提交
1574

S
shawn_he 已提交
1575
**Example**
S
shawn_he 已提交
1576
  ```js
S
shawn_he 已提交
1577 1578 1579 1580 1581
  var timezone = i18n.getTimeZone();
  timezone.getRawOffset();
  ```


S
shawn_he 已提交
1582
### getOffset
S
shawn_he 已提交
1583 1584 1585 1586 1587 1588 1589

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 已提交
1590
**Return value**
S
shawn_he 已提交
1591 1592 1593
| 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 已提交
1594

S
shawn_he 已提交
1595
**Example**
S
shawn_he 已提交
1596
  ```js
S
shawn_he 已提交
1597 1598 1599
  var timezone = i18n.getTimeZone();
  timezone.getOffset(1234567890);
  ```
S
shawn_he 已提交
1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614

### 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**
| Type    | Description                      |
| ------ | ----------------------- |
| Array&lt;string&gt; | List of time zone IDs supported by the system.|

**Example**
S
shawn_he 已提交
1615
  ```js
S
shawn_he 已提交
1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633
  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**
| Type    | Description                      |
| ------ | ----------------------- |
| Array&lt;string&gt; | List of time zone city IDs supported by the system.|

**Example**
S
shawn_he 已提交
1634
  ```js
S
shawn_he 已提交
1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658
  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**
| Name   | Type    | Mandatory  | Description   |
| ------ | ------ | ---- | ----- |
| cityID | string | Yes   | Time zone city ID.|
| locale | string | Yes   | Locale ID.|

**Return value**
| Type    | Description                     |
| ------ | ----------------------- |
| string | Localized display of the time zone city in the specified locale.|

**Example**
S
shawn_he 已提交
1659
  ```js
S
shawn_he 已提交
1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682
  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**
| Name   | Type    | Mandatory  | Description   |
| ------ | ------ | ---- | ----- |
| cityID | string | Yes   | Time zone city ID.|

**Return value**
| Type    | Description                     |
| ------ | ----------------------- |
| TimeZone | **TimeZone** object corresponding to the specified time zone city ID.|

**Example**
S
shawn_he 已提交
1683
  ```js
S
shawn_he 已提交
1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709
  var timezone = i18n.TimeZone.getTimezoneFromCity("Shanghai");
  ```


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

setUsingLocalDigit(flag: boolean): boolean

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

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

**Example**
S
shawn_he 已提交
1710
  ```js
S
shawn_he 已提交
1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728
  var status = i18n.setUsingLocalDigit(true);
  ```


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

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

**Example**
S
shawn_he 已提交
1729
  ```js
S
shawn_he 已提交
1730 1731
  var status = i18n.getUsingLocalDigit();
  ```
S
shawn_he 已提交
1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801

## 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**
| Type    | Description          |
| ------ | ------------ |
| string[] | List of IDs supported by the **Transliterator** object.|

**Example**
  ```
  i18n.Transliterator.getAvailableIDs();
  ```


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

static getInstance(id: string): Transliterator

Creates a **Transliterator** object.

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

**Parameters**
| Name   | Type     | Mandatory  | Description                  |
| ------ | ------- | ---- | -------------------- |
| id | string  | Yes   | ID supported by the **Transliterator** object.               |

**Return value**
| Type    | Description           |
| ------ | ------------- |
| [Transliterator](#transliterator9) | **Transliterator** object.|

**Example**
  ```
  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**
| Name   | Type     | Mandatory  | Description                  |
| ------ | ------- | ---- | -------------------- |
| text | string  | Yes   | Input string.               |

**Return value**
| Type    | Description           |
| ------ | ------------- |
| string | Target string.|

**Example**
  ```
  var transliterator = i18n.Transliterator.getInstance("Any-Latn");
  transliterator.transform ("China");
  ```