js-apis-i18n.md 50.8 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 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 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 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 111 112
  ```
  i18n.getSystemLanguage();
  ```
Z
zengyawen 已提交
113 114


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

setSystemLanguage(language: string): boolean

Sets the system language.

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 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 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 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 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
  ```
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 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 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 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 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
  ```
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
  ```
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 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 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 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
  ```
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 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 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 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 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 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 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 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 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 673 674 675 676
  ```
  var phonenumberfmt = new i18n.PhoneNumberFormat("CN");
  phonenumberfmt.format("15812312312");
  ```

S
shawn_he 已提交
677
### getLocationName<sup>9+</sup>
S
shawn_he 已提交
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

static getLocationName(number: string, locale: string): string

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**
  ```
  var location = i18n.PhoneNumberFormat.getLocationName('15812312345', 'zh-CN');
  ```



S
shawn_he 已提交
703 704 705 706 707

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

Defines the options for this PhoneNumberFormat object.

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

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


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

Defines the measurement unit information.

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

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


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


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

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

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

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

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

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

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

S
shawn_he 已提交
757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779
### 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 已提交
780

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

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

Creates an **IndexUtil** object.

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

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

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

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


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


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

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


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

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

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

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

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

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

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

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


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


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

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

Checks whether the input character string is composed of digits.

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

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

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

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


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

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

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

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

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

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

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


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

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

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

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

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

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

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


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

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

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

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

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

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

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


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

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

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

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

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

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

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


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

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

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

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

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

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

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


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

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

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

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

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

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

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


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

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

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

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

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

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

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


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

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

Obtains the type of the input character string.

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

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

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

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


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

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

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

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

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

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

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


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


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

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

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

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

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

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


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

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

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

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

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

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


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

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

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

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

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

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


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

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


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

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

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

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

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


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

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

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

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

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

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

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

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

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


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

is24HourClock(): boolean

Checks whether the 24-hour clock is used.

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

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

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


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

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

Sets the 24-hour clock.

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

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

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

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

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


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

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

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

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

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

S
shawn_he 已提交
1385 1386 1387 1388 1389
**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 已提交
1390

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

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


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

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

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

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

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

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

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

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


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

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

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

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

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

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


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

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

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

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

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

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


S
shawn_he 已提交
1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489
## 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**
  ```
  var appPreferredLanguage = i18n.getAppPreferredLanguage();
  ```


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

getTimeZone(zoneID?: string): TimeZone

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

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

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

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

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


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


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

getID(): string

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

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

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

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


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

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 已提交
1545 1546 1547 1548 1549
**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 已提交
1550

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

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


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

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

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


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

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

S
shawn_he 已提交
1596
**Example**
S
shawn_he 已提交
1597 1598 1599 1600
  ```
  var timezone = i18n.getTimeZone();
  timezone.getOffset(1234567890);
  ```
S
shawn_he 已提交
1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 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 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732

### 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**
  ```
  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**
  ```
  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**
  ```
  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**
  ```
  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**
  ```
  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**
  ```
  var status = i18n.getUsingLocalDigit();
  ```
S
shawn_he 已提交
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 1802

## 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");
  ```