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

S
shawn_he 已提交
3 4 5 6 7
This module provides system-related or enhanced I18N capabilities, such as locale management, phone number formatting, and calendar, through supplementary I18N APIs that are not defined in ECMA 402.

The [Intl](js-apis-intl.md) module provides basic I18N capabilities through the standard I18N APIs defined in ECMA 402. It works with the I18N module to provide a complete suite of I18N capabilities.


S
shawn_he 已提交
8 9
> **NOTE**
> 
S
shawn_he 已提交
10
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version.
Z
zengyawen 已提交
11

S
shawn_he 已提交
12 13

## Modules to Import
Z
zengyawen 已提交
14 15 16 17 18 19

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


S
shawn_he 已提交
20
## i18n.getDisplayLanguage
Z
zengyawen 已提交
21

S
shawn_he 已提交
22
getDisplayLanguage(language: string, locale: string, sentenceCase?: boolean): string
Z
zengyawen 已提交
23 24 25

Obtains the localized script for the specified language.

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

S
shawn_he 已提交
28 29 30 31 32 33
**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 已提交
34

S
shawn_he 已提交
35
**Return value**
S
shawn_he 已提交
36 37 38
| Type    | Description           |
| ------ | ------------- |
| string | Localized script for the specified language.|
S
shawn_he 已提交
39

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


## i18n.getDisplayCountry

getDisplayCountry(country: string, locale: string, sentenceCase?: boolean): string
Z
zengyawen 已提交
50 51 52

Obtains the localized script for the specified country.

S
shawn_he 已提交
53 54
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
55 56 57 58 59 60
**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 已提交
61

S
shawn_he 已提交
62
**Return value**
S
shawn_he 已提交
63 64 65
| Type    | Description           |
| ------ | ------------- |
| string | Localized script for the specified country.|
S
shawn_he 已提交
66

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


S
shawn_he 已提交
74
## i18n.isRTL<sup>7+</sup>
S
shawn_he 已提交
75 76

isRTL(locale: string): boolean
Z
zengyawen 已提交
77 78 79

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

S
shawn_he 已提交
80
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
81

S
shawn_he 已提交
82 83 84 85
**Parameters**
| Name   | Type    | Description     |
| ------ | ------ | ------- |
| locale | string | Locale ID.|
Z
zengyawen 已提交
86

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

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


S
shawn_he 已提交
99
## i18n.getSystemLanguage
Z
zengyawen 已提交
100

S
shawn_he 已提交
101
getSystemLanguage(): string
Z
zengyawen 已提交
102

S
shawn_he 已提交
103
Obtains the system language.
Z
zengyawen 已提交
104

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

S
shawn_he 已提交
107
**Return value**
S
shawn_he 已提交
108 109 110
| Type    | Description     |
| ------ | ------- |
| string | System language ID.|
S
shawn_he 已提交
111

S
shawn_he 已提交
112
**Example**
S
shawn_he 已提交
113
  ```js
S
shawn_he 已提交
114 115
  i18n.getSystemLanguage();
  ```
Z
zengyawen 已提交
116 117


S
shawn_he 已提交
118 119 120 121
## i18n.setSystemLanguage

setSystemLanguage(language: string): boolean

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

S
shawn_he 已提交
124 125
This is a system API.

S
shawn_he 已提交
126
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
S
shawn_he 已提交
127

S
shawn_he 已提交
128 129
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
130 131 132 133
**Parameters**
| Name     | Type    | Description   |
| -------- | ------ | ----- |
| language | string | Language ID.|
S
shawn_he 已提交
134

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

S
shawn_he 已提交
140
**Example**
S
shawn_he 已提交
141
  ```js
S
shawn_he 已提交
142 143 144 145 146 147
  i18n.setSystemLanguage('zh');
  ```


## i18n.getSystemLanguages

S
shawn_he 已提交
148
getSystemLanguages(): Array&lt;string&gt;
S
shawn_he 已提交
149 150 151 152 153

Obtains the list of system languages.

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

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

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

S
shawn_he 已提交
161
**Example**
S
shawn_he 已提交
162
  ```js
S
shawn_he 已提交
163 164 165 166 167 168
  i18n.getSystemLanguages();
  ```


## i18n.getSystemCountries

S
shawn_he 已提交
169
getSystemCountries(language: string): Array&lt;string&gt;
S
shawn_he 已提交
170 171 172 173 174

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

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

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

S
shawn_he 已提交
177 178 179 180
**Parameters**
| Name     | Type    | Description   |
| -------- | ------ | ----- |
| language | string | Language ID.|
S
shawn_he 已提交
181

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

S
shawn_he 已提交
187
**Example**
S
shawn_he 已提交
188
  ```js
S
shawn_he 已提交
189 190 191 192
  i18n.getSystemCountries('zh');
  ```


S
shawn_he 已提交
193
## i18n.getSystemRegion
Z
zengyawen 已提交
194

S
shawn_he 已提交
195
getSystemRegion(): string
Z
zengyawen 已提交
196

S
shawn_he 已提交
197 198 199 200
Obtains the system region.

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

S
shawn_he 已提交
201
**Return value**
S
shawn_he 已提交
202 203 204
| Type    | Description     |
| ------ | ------- |
| string | System region ID.|
Z
zengyawen 已提交
205

S
shawn_he 已提交
206
**Example**
S
shawn_he 已提交
207
  ```js
S
shawn_he 已提交
208 209
  i18n.getSystemRegion();
  ```
Z
zengyawen 已提交
210 211


S
shawn_he 已提交
212 213 214 215 216 217
## i18n.setSystemRegion

setSystemRegion(region: string): boolean

Sets the system region.

S
shawn_he 已提交
218 219
This is a system API.

S
shawn_he 已提交
220
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
S
shawn_he 已提交
221

S
shawn_he 已提交
222 223
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
224 225 226 227
**Parameters**
| Name   | Type    | Description   |
| ------ | ------ | ----- |
| region | string | Region ID.|
S
shawn_he 已提交
228

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

S
shawn_he 已提交
234
**Example**
S
shawn_he 已提交
235
  ```js
S
shawn_he 已提交
236
  i18n.setSystemRegion('CN');
S
shawn_he 已提交
237 238 239
  ```


S
shawn_he 已提交
240
## i18n.getSystemLocale
Z
zengyawen 已提交
241

S
shawn_he 已提交
242
getSystemLocale(): string
Z
zengyawen 已提交
243 244 245

Obtains the system locale.

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

S
shawn_he 已提交
248
**Return value**
S
shawn_he 已提交
249 250 251
| Type    | Description     |
| ------ | ------- |
| string | System locale ID.|
Z
zengyawen 已提交
252

S
shawn_he 已提交
253
**Example**
S
shawn_he 已提交
254
  ```js
S
shawn_he 已提交
255 256
  i18n.getSystemLocale();
  ```
Z
zengyawen 已提交
257 258


S
shawn_he 已提交
259 260 261 262 263 264
## i18n.setSystemLocale

setSystemLocale(locale: string): boolean

Sets the system locale.

S
shawn_he 已提交
265 266
This is a system API.

S
shawn_he 已提交
267
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
S
shawn_he 已提交
268

S
shawn_he 已提交
269 270
**System capability**: SystemCapability.Global.I18n

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

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

S
shawn_he 已提交
281
**Example**
S
shawn_he 已提交
282
  ```js
S
shawn_he 已提交
283 284 285 286 287 288 289 290 291 292 293 294
  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 已提交
295 296
**System API**: This is a system API and cannot be called by third-party applications.

S
shawn_he 已提交
297 298 299 300 301
**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 已提交
302

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

S
shawn_he 已提交
308
**Example**
S
shawn_he 已提交
309
  ```js
S
shawn_he 已提交
310 311 312 313
  i18n.isSuggested('zh', 'CN');
  ```


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

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

S
shawn_he 已提交
318
Obtains a **Calendar** object.
Z
zengyawen 已提交
319

S
shawn_he 已提交
320
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
321

S
shawn_he 已提交
322 323 324 325 326
**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 已提交
327

S
shawn_he 已提交
328
**Return value**
S
shawn_he 已提交
329 330 331
| Type                    | Description   |
| ---------------------- | ----- |
| [Calendar](#calendar8) | **Calendar** object.|
S
shawn_he 已提交
332

S
shawn_he 已提交
333
**Example**
S
shawn_he 已提交
334
  ```js
S
shawn_he 已提交
335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
  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 已提交
350 351 352 353
**Parameters**
| Name | Type  | Mandatory  | Description               |
| ---- | ---- | ---- | ----------------- |
| date | Date | Yes   | Date to be set for the **Calendar** object.|
S
shawn_he 已提交
354

S
shawn_he 已提交
355
**Example**
S
shawn_he 已提交
356
  ```js
S
shawn_he 已提交
357
  var calendar = i18n.getCalendar("en-US", "gregory");
S
shawn_he 已提交
358 359 360 361 362 363 364 365 366 367 368 369 370
  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 已提交
371 372 373 374
**Parameters**
| Name | Type    | Mandatory  | Description                                      |
| ---- | ------ | ---- | ---------------------------------------- |
| time | number | Yes   | Number of milliseconds that have elapsed since the Unix epoch.|
S
shawn_he 已提交
375

S
shawn_he 已提交
376
**Example**
S
shawn_he 已提交
377
  ```js
S
shawn_he 已提交
378
  var calendar = i18n.getCalendar("en-US", "gregory");
S
shawn_he 已提交
379 380 381 382 383 384 385 386 387 388 389 390
  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 已提交
391 392 393 394 395 396 397 398 399
**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 已提交
400

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


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

setTimeZone(timezone: string): void

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

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

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

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

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

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

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


S
shawn_he 已提交
489
### getMinimalDaysInFirstWeek<sup>8+</sup>
Z
zengyawen 已提交
490

S
shawn_he 已提交
491 492 493 494 495 496
getMinimalDaysInFirstWeek(): number

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

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

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

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


S
shawn_he 已提交
509
### setMinimalDaysInFirstWeek<sup>8+</sup>
Z
zengyawen 已提交
510

S
shawn_he 已提交
511
setMinimalDaysInFirstWeek(value: number): void
Z
zengyawen 已提交
512 513 514

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

S
shawn_he 已提交
515 516
**System capability**: SystemCapability.Global.I18n

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

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

S
shawn_he 已提交
542
**Return value**
S
shawn_he 已提交
543 544 545
| 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 已提交
546

S
shawn_he 已提交
547
**Example**
S
shawn_he 已提交
548
  ```js
S
shawn_he 已提交
549
  var calendar = i18n.getCalendar("zh-Hans");
S
shawn_he 已提交
550
  calendar.set(2021, 10, 1, 8, 0, 0); // set time to 2021.10.1 08:00:00
S
shawn_he 已提交
551 552 553 554 555 556 557 558 559 560 561 562
  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 已提交
563 564 565 566
**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 已提交
567

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

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

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

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

Parameters
S
shawn_he 已提交
620 621 622 623
| 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 已提交
624

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


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

isValidNumber(number: string): boolean
Z
zengyawen 已提交
634 635 636

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

S
shawn_he 已提交
637 638
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
639 640 641 642
**Parameters**
| Name   | Type    | Mandatory  | Description       |
| ------ | ------ | ---- | --------- |
| number | string | Yes   | Phone number to be checked.|
S
shawn_he 已提交
643

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

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


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

format(number: string): string
Z
zengyawen 已提交
659 660 661

Formats a phone number.

S
shawn_he 已提交
662 663
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
664 665 666 667
**Parameters**
| Name   | Type    | Mandatory  | Description        |
| ------ | ------ | ---- | ---------- |
| number | string | Yes   | Phone number to be formatted.|
S
shawn_he 已提交
668

S
shawn_he 已提交
669
**Return value**
S
shawn_he 已提交
670 671 672
| Type    | Description        |
| ------ | ---------- |
| string | Formatted phone number.|
S
shawn_he 已提交
673

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

S
shawn_he 已提交
680
### getLocationName<sup>9+</sup>
S
shawn_he 已提交
681

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

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 已提交
700 701 702
  ```js
  var phonenumberfmt = new i18n.PhoneNumberFormat("CN");
  phonenumberfmt.isValidNumber("15812312312");
S
shawn_he 已提交
703 704
  ```

S
shawn_he 已提交
705 706 707 708 709

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

Defines the options for this PhoneNumberFormat object.

S
shawn_he 已提交
710
**System capability**: SystemCapability.Global.I18n
S
shawn_he 已提交
711

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


## UnitInfo<sup>8+</sup>
Z
zengyawen 已提交
718 719 720

Defines the measurement unit information.

S
shawn_he 已提交
721
**System capability**: SystemCapability.Global.I18n
S
shawn_he 已提交
722

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


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


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

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

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

S
shawn_he 已提交
738 739
**System capability**: SystemCapability.Global.I18n

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

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

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

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

S
shawn_he 已提交
783
## getInstance<sup>8+</sup>
S
shawn_he 已提交
784

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

Creates an **IndexUtil** object.

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

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

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

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


S
shawn_he 已提交
807 808 809
## IndexUtil<sup>8+</sup>


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

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


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

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

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

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

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

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

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

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


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


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

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

Checks whether the input character string is composed of digits.

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

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

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

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


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

S
shawn_he 已提交
904
static isSpaceChar(char: string): boolean
Z
zengyawen 已提交
905

Z
zengyawen 已提交
906
Checks whether the input character is a space.
Z
zengyawen 已提交
907

S
shawn_he 已提交
908 909
**System capability**: SystemCapability.Global.I18n

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

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

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


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

S
shawn_he 已提交
928
static isWhitespace(char: string): boolean
Z
zengyawen 已提交
929

Z
zengyawen 已提交
930
Checks whether the input character is a white space.
Z
zengyawen 已提交
931

S
shawn_he 已提交
932 933
**System capability**: SystemCapability.Global.I18n

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

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

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


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

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

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

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

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

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

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


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

S
shawn_he 已提交
976
static isIdeograph(char: string): boolean
Z
zengyawen 已提交
977

Z
zengyawen 已提交
978
Checks whether the input character is an ideographic character.
Z
zengyawen 已提交
979

S
shawn_he 已提交
980 981
**System capability**: SystemCapability.Global.I18n

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

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

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


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

S
shawn_he 已提交
1000
static isLetter(char: string): boolean
Z
zengyawen 已提交
1001

Z
zengyawen 已提交
1002
Checks whether the input character is a letter.
Z
zengyawen 已提交
1003

S
shawn_he 已提交
1004 1005
**System capability**: SystemCapability.Global.I18n

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

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

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


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

S
shawn_he 已提交
1024
static isLowerCase(char: string): boolean
Z
zengyawen 已提交
1025

Z
zengyawen 已提交
1026
Checks whether the input character is a lowercase letter.
Z
zengyawen 已提交
1027

S
shawn_he 已提交
1028 1029
**System capability**: SystemCapability.Global.I18n

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

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

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


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

S
shawn_he 已提交
1048
static isUpperCase(char: string): boolean
Z
zengyawen 已提交
1049

Z
zengyawen 已提交
1050
Checks whether the input character is an uppercase letter.
Z
zengyawen 已提交
1051

S
shawn_he 已提交
1052 1053
**System capability**: SystemCapability.Global.I18n

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

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

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


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

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

Obtains the type of the input character string.

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

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

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

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


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

S
shawn_he 已提交
1096
getLineInstance(locale: string): BreakIterator
Z
zengyawen 已提交
1097

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

S
shawn_he 已提交
1100
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1101

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

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

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


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


S
shawn_he 已提交
1121
### setLineBreakText<sup>8+</sup>
Z
zengyawen 已提交
1122

S
shawn_he 已提交
1123
setLineBreakText(text: string): void
Z
zengyawen 已提交
1124

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

S
shawn_he 已提交
1127
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1128

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

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


S
shawn_he 已提交
1141
### getLineBreakText<sup>8+</sup>
Z
zengyawen 已提交
1142

S
shawn_he 已提交
1143
getLineBreakText(): string
Z
zengyawen 已提交
1144

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

S
shawn_he 已提交
1147
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1148

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

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


S
shawn_he 已提交
1162
### current<sup>8+</sup>
Z
zengyawen 已提交
1163

S
shawn_he 已提交
1164 1165 1166 1167 1168 1169
current(): number

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

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

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

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


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

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


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

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

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

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

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


S
shawn_he 已提交
1276
### following<sup>8+</sup>
Z
zengyawen 已提交
1277

S
shawn_he 已提交
1278
following(offset: number): number
Z
zengyawen 已提交
1279

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

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

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

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

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

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

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


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

is24HourClock(): boolean

Checks whether the 24-hour clock is used.

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

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

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


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

set24HourClock(option: boolean): boolean
Z
zengyawen 已提交
1353 1354 1355

Sets the 24-hour clock.

S
shawn_he 已提交
1356
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
S
shawn_he 已提交
1357

S
shawn_he 已提交
1358 1359
**System capability**: SystemCapability.Global.I18n

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

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

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


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

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

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

S
shawn_he 已提交
1383
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
S
shawn_he 已提交
1384

S
shawn_he 已提交
1385 1386
**System capability**: SystemCapability.Global.I18n

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

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

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


S
shawn_he 已提交
1407
## i18n.removePreferredLanguage<sup>8+</sup>
S
shawn_he 已提交
1408

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

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

S
shawn_he 已提交
1413
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
S
shawn_he 已提交
1414

S
shawn_he 已提交
1415
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1416

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

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

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


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

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

S
shawn_he 已提交
1439
Obtains the list of preferred languages.
Z
zengyawen 已提交
1440

S
shawn_he 已提交
1441
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1442

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

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


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

S
shawn_he 已提交
1456 1457
getFirstPreferredLanguage(): string

S
shawn_he 已提交
1458
Obtains the first language in the preferred language list.
Z
zengyawen 已提交
1459

S
shawn_he 已提交
1460
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1461

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

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


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


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

getTimeZone(zoneID?: string): TimeZone

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

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

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

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

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


S
shawn_he 已提交
1516
## TimeZone
S
shawn_he 已提交
1517 1518


S
shawn_he 已提交
1519
### getID
S
shawn_he 已提交
1520 1521 1522 1523 1524 1525 1526

getID(): string

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

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

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

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


S
shawn_he 已提交
1539
### getDisplayName
S
shawn_he 已提交
1540 1541 1542 1543 1544 1545 1546

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

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

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


S
shawn_he 已提交
1565
### getRawOffset
S
shawn_he 已提交
1566 1567 1568 1569 1570 1571 1572

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

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


S
shawn_he 已提交
1585
### getOffset
S
shawn_he 已提交
1586 1587 1588 1589 1590 1591 1592

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

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

### 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 已提交
1618
  ```js
S
shawn_he 已提交
1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636
  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 已提交
1637
  ```js
S
shawn_he 已提交
1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661
  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 已提交
1662
  ```js
S
shawn_he 已提交
1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685
  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 已提交
1686
  ```js
S
shawn_he 已提交
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
  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 已提交
1713
  ```js
S
shawn_he 已提交
1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731
  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 已提交
1732
  ```js
S
shawn_he 已提交
1733 1734
  var status = i18n.getUsingLocalDigit();
  ```
S
shawn_he 已提交
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 1803 1804

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