js-apis-i18n.md 59.1 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
**Parameters**
S
shawn_he 已提交
29

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

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

S
shawn_he 已提交
38 39 40
| Type    | Description           |
| ------ | ------------- |
| string | Localized script for the specified language.|
S
shawn_he 已提交
41

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


## i18n.getDisplayCountry

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

Obtains the localized script for the specified country.

S
shawn_he 已提交
55 56
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
57
**Parameters**
S
shawn_he 已提交
58

S
shawn_he 已提交
59 60 61 62 63
| 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 已提交
64

S
shawn_he 已提交
65
**Return value**
S
shawn_he 已提交
66

S
shawn_he 已提交
67 68 69
| Type    | Description           |
| ------ | ------------- |
| string | Localized script for the specified country.|
S
shawn_he 已提交
70

S
shawn_he 已提交
71
**Example**
S
shawn_he 已提交
72
  ```js
S
shawn_he 已提交
73 74 75 76 77
  i18n.getDisplayCountry("zh-CN", "en-GB", true);
  i18n.getDisplayCountry("zh-CN", "en-GB");
  ```


S
shawn_he 已提交
78
## i18n.isRTL<sup>7+</sup>
S
shawn_he 已提交
79 80

isRTL(locale: string): boolean
Z
zengyawen 已提交
81 82 83

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

S
shawn_he 已提交
84
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
85

S
shawn_he 已提交
86
**Parameters**
S
shawn_he 已提交
87

S
shawn_he 已提交
88 89 90
| Name   | Type    | Description     |
| ------ | ------ | ------- |
| locale | string | Locale ID.|
Z
zengyawen 已提交
91

S
shawn_he 已提交
92
**Return value**
S
shawn_he 已提交
93

S
shawn_he 已提交
94 95 96
| Type     | Description                                      |
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the localized script is displayed from right to left; returns **false** otherwise.|
Z
zengyawen 已提交
97

S
shawn_he 已提交
98
**Example**
S
shawn_he 已提交
99
  ```js
S
shawn_he 已提交
100 101 102
  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 已提交
103 104


S
shawn_he 已提交
105
## i18n.getSystemLanguage
Z
zengyawen 已提交
106

S
shawn_he 已提交
107
getSystemLanguage(): string
Z
zengyawen 已提交
108

S
shawn_he 已提交
109
Obtains the system language.
Z
zengyawen 已提交
110

S
shawn_he 已提交
111 112
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
113
**Return value**
S
shawn_he 已提交
114

S
shawn_he 已提交
115 116 117
| Type    | Description     |
| ------ | ------- |
| string | System language ID.|
S
shawn_he 已提交
118

S
shawn_he 已提交
119
**Example**
S
shawn_he 已提交
120
  ```js
S
shawn_he 已提交
121 122
  i18n.getSystemLanguage();
  ```
Z
zengyawen 已提交
123 124


S
shawn_he 已提交
125 126 127 128
## i18n.setSystemLanguage

setSystemLanguage(language: string): boolean

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

S
shawn_he 已提交
131 132
This is a system API.

S
shawn_he 已提交
133
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
S
shawn_he 已提交
134

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

S
shawn_he 已提交
137
**Parameters**
S
shawn_he 已提交
138

S
shawn_he 已提交
139 140 141
| Name     | Type    | Description   |
| -------- | ------ | ----- |
| language | string | Language ID.|
S
shawn_he 已提交
142

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

S
shawn_he 已提交
145 146 147
| Type     | Description                                   |
| ------- | ------------------------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
S
shawn_he 已提交
148

S
shawn_he 已提交
149
**Example**
S
shawn_he 已提交
150
  ```js
S
shawn_he 已提交
151 152 153 154
  i18n.setSystemLanguage('zh');
  ```


S
shawn_he 已提交
155
## i18n.getSystemLanguages<sup>9+</sup>
S
shawn_he 已提交
156

S
shawn_he 已提交
157
getSystemLanguages(): Array&lt;string&gt;
S
shawn_he 已提交
158 159 160 161 162

Obtains the list of system languages.

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

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

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

S
shawn_he 已提交
167 168 169
| Type                 | Description          |
| ------------------- | ------------ |
| Array&lt;string&gt; | List of the IDs of system languages.|
S
shawn_he 已提交
170

S
shawn_he 已提交
171
**Example**
S
shawn_he 已提交
172
  ```js
S
shawn_he 已提交
173 174 175 176
  i18n.getSystemLanguages();
  ```


S
shawn_he 已提交
177
## i18n.getSystemCountries<sup>9+</sup>
S
shawn_he 已提交
178

S
shawn_he 已提交
179
getSystemCountries(language: string): Array&lt;string&gt;
S
shawn_he 已提交
180 181 182 183 184

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

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

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

S
shawn_he 已提交
187
**Parameters**
S
shawn_he 已提交
188

S
shawn_he 已提交
189 190 191
| Name     | Type    | Description   |
| -------- | ------ | ----- |
| language | string | Language ID.|
S
shawn_he 已提交
192

S
shawn_he 已提交
193
**Return value**
S
shawn_he 已提交
194

S
shawn_he 已提交
195 196 197
| Type                 | Description          |
| ------------------- | ------------ |
| Array&lt;string&gt; | List of the IDs of the countries and regions supported for the specified language.|
S
shawn_he 已提交
198

S
shawn_he 已提交
199
**Example**
S
shawn_he 已提交
200
  ```js
S
shawn_he 已提交
201 202 203 204
  i18n.getSystemCountries('zh');
  ```


S
shawn_he 已提交
205
## i18n.getSystemRegion
Z
zengyawen 已提交
206

S
shawn_he 已提交
207
getSystemRegion(): string
Z
zengyawen 已提交
208

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

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

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

S
shawn_he 已提交
215 216 217
| Type    | Description     |
| ------ | ------- |
| string | System region ID.|
Z
zengyawen 已提交
218

S
shawn_he 已提交
219
**Example**
S
shawn_he 已提交
220
  ```js
S
shawn_he 已提交
221 222
  i18n.getSystemRegion();
  ```
Z
zengyawen 已提交
223 224


S
shawn_he 已提交
225 226 227 228 229 230
## i18n.setSystemRegion

setSystemRegion(region: string): boolean

Sets the system region.

S
shawn_he 已提交
231 232
This is a system API.

S
shawn_he 已提交
233
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
S
shawn_he 已提交
234

S
shawn_he 已提交
235 236
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
237
**Parameters**
S
shawn_he 已提交
238

S
shawn_he 已提交
239 240 241
| Name   | Type    | Description   |
| ------ | ------ | ----- |
| region | string | Region ID.|
S
shawn_he 已提交
242

S
shawn_he 已提交
243
**Return value**
S
shawn_he 已提交
244

S
shawn_he 已提交
245 246 247
| Type     | Description                                   |
| ------- | ------------------------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
S
shawn_he 已提交
248

S
shawn_he 已提交
249
**Example**
S
shawn_he 已提交
250
  ```js
S
shawn_he 已提交
251
  i18n.setSystemRegion('CN');
S
shawn_he 已提交
252 253 254
  ```


S
shawn_he 已提交
255
## i18n.getSystemLocale
Z
zengyawen 已提交
256

S
shawn_he 已提交
257
getSystemLocale(): string
Z
zengyawen 已提交
258 259 260

Obtains the system locale.

S
shawn_he 已提交
261
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
262

S
shawn_he 已提交
263
**Return value**
S
shawn_he 已提交
264

S
shawn_he 已提交
265 266 267
| Type    | Description     |
| ------ | ------- |
| string | System locale ID.|
Z
zengyawen 已提交
268

S
shawn_he 已提交
269
**Example**
S
shawn_he 已提交
270
  ```js
S
shawn_he 已提交
271 272
  i18n.getSystemLocale();
  ```
Z
zengyawen 已提交
273 274


S
shawn_he 已提交
275 276 277 278 279 280
## i18n.setSystemLocale

setSystemLocale(locale: string): boolean

Sets the system locale.

S
shawn_he 已提交
281 282
This is a system API.

S
shawn_he 已提交
283
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
S
shawn_he 已提交
284

S
shawn_he 已提交
285 286
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
287
**Parameters**
S
shawn_he 已提交
288

S
shawn_he 已提交
289 290 291
| Name   | Type    | Description             |
| ------ | ------ | --------------- |
| locale | string | System locale ID, for example, **zh-CN**.|
S
shawn_he 已提交
292

S
shawn_he 已提交
293
**Return value**
S
shawn_he 已提交
294

S
shawn_he 已提交
295 296 297
| Type     | Description                                      |
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
S
shawn_he 已提交
298

S
shawn_he 已提交
299
**Example**
S
shawn_he 已提交
300
  ```js
S
shawn_he 已提交
301 302 303 304
  i18n.setSystemLocale('zh-CN');
  ```


S
shawn_he 已提交
305
## i18n.isSuggested<sup>9+</sup>
S
shawn_he 已提交
306 307 308 309 310 311 312

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

Checks whether the system language matches the specified region.

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

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

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

S
shawn_he 已提交
317 318 319 320
| 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 已提交
321

S
shawn_he 已提交
322
**Return value**
S
shawn_he 已提交
323

S
shawn_he 已提交
324 325 326
| Type     | Description                                      |
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the system language matches the specified region; returns **false** otherwise.|
S
shawn_he 已提交
327

S
shawn_he 已提交
328
**Example**
S
shawn_he 已提交
329
  ```js
S
shawn_he 已提交
330 331 332 333
  i18n.isSuggested('zh', 'CN');
  ```


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

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

S
shawn_he 已提交
338
Obtains a **Calendar** object.
Z
zengyawen 已提交
339

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

S
shawn_he 已提交
342
**Parameters**
S
shawn_he 已提交
343

S
shawn_he 已提交
344 345 346 347
| 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 已提交
348

S
shawn_he 已提交
349
**Return value**
S
shawn_he 已提交
350

S
shawn_he 已提交
351 352 353
| Type                    | Description   |
| ---------------------- | ----- |
| [Calendar](#calendar8) | **Calendar** object.|
S
shawn_he 已提交
354

S
shawn_he 已提交
355
**Example**
S
shawn_he 已提交
356
  ```js
S
shawn_he 已提交
357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
  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 已提交
372
**Parameters**
S
shawn_he 已提交
373

S
shawn_he 已提交
374 375 376
| Name | Type  | Mandatory  | Description               |
| ---- | ---- | ---- | ----------------- |
| date | Date | Yes   | Date to be set for the **Calendar** object.|
S
shawn_he 已提交
377

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

S
shawn_he 已提交
396 397 398
| Name | Type    | Mandatory  | Description                                      |
| ---- | ------ | ---- | ---------------------------------------- |
| time | number | Yes   | Number of milliseconds that have elapsed since the Unix epoch.|
S
shawn_he 已提交
399

S
shawn_he 已提交
400
**Example**
S
shawn_he 已提交
401
  ```js
S
shawn_he 已提交
402
  var calendar = i18n.getCalendar("en-US", "gregory");
S
shawn_he 已提交
403 404 405 406 407 408 409 410 411 412 413 414
  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 已提交
415
**Parameters**
S
shawn_he 已提交
416

S
shawn_he 已提交
417 418 419 420 421 422 423 424
| 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 已提交
425

S
shawn_he 已提交
426
**Example**
S
shawn_he 已提交
427
  ```js
S
shawn_he 已提交
428
  var calendar = i18n.getCalendar("zh-Hans");
S
shawn_he 已提交
429
  calendar.set(2021, 10, 1, 8, 0, 0); // set time to 2021.10.1 08:00:00
S
shawn_he 已提交
430 431 432 433 434 435 436 437 438 439 440
  ```


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

setTimeZone(timezone: string): void

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

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

S
shawn_he 已提交
441
**Parameters**
S
shawn_he 已提交
442

S
shawn_he 已提交
443 444 445
| Name     | Type    | Mandatory  | Description                       |
| -------- | ------ | ---- | ------------------------- |
| timezone | string | Yes   | Time zone, for example, **Asia/Shanghai**.|
S
shawn_he 已提交
446

S
shawn_he 已提交
447
**Example**
S
shawn_he 已提交
448
  ```js
S
shawn_he 已提交
449 450 451 452 453 454 455 456 457 458 459 460 461
  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 已提交
462
**Return value**
S
shawn_he 已提交
463

S
shawn_he 已提交
464 465 466
| Type    | Description        |
| ------ | ---------- |
| string | Time zone of the **Calendar** object.|
S
shawn_he 已提交
467

S
shawn_he 已提交
468
**Example**
S
shawn_he 已提交
469
  ```js
S
shawn_he 已提交
470 471 472 473 474 475 476 477 478 479 480 481 482 483
  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 已提交
484
**Return value**
S
shawn_he 已提交
485

S
shawn_he 已提交
486 487 488
| Type    | Description                   |
| ------ | --------------------- |
| number | Start day of a week. The value **1** indicates Sunday, and the value **7** indicates Saturday.|
S
shawn_he 已提交
489

S
shawn_he 已提交
490
**Example**
S
shawn_he 已提交
491
  ```js
S
shawn_he 已提交
492
  var calendar = i18n.getCalendar("en-US", "gregory");
S
shawn_he 已提交
493 494 495 496 497 498 499 500 501 502 503 504
  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 已提交
505
**Parameters**
S
shawn_he 已提交
506

S
shawn_he 已提交
507 508 509
| 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 已提交
510

S
shawn_he 已提交
511
**Example**
S
shawn_he 已提交
512
  ```js
S
shawn_he 已提交
513 514 515
  var calendar = i18n.getCalendar("zh-Hans");
  calendar.setFirstDayOfWeek(0);
  ```
Z
zengyawen 已提交
516 517


S
shawn_he 已提交
518
### getMinimalDaysInFirstWeek<sup>8+</sup>
Z
zengyawen 已提交
519

S
shawn_he 已提交
520 521 522 523 524 525
getMinimalDaysInFirstWeek(): number

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

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

S
shawn_he 已提交
526
**Return value**
S
shawn_he 已提交
527

S
shawn_he 已提交
528 529 530
| Type    | Description          |
| ------ | ------------ |
| number | Minimum number of days in the first week of a year.|
S
shawn_he 已提交
531

S
shawn_he 已提交
532
**Example**
S
shawn_he 已提交
533
  ```js
S
shawn_he 已提交
534 535 536
  var calendar = i18n.getCalendar("zh-Hans");
  calendar.getMinimalDaysInFirstWeek();
  ```
Z
zengyawen 已提交
537 538


S
shawn_he 已提交
539
### setMinimalDaysInFirstWeek<sup>8+</sup>
Z
zengyawen 已提交
540

S
shawn_he 已提交
541
setMinimalDaysInFirstWeek(value: number): void
Z
zengyawen 已提交
542 543 544

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

S
shawn_he 已提交
545 546
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
547
**Parameters**
S
shawn_he 已提交
548

S
shawn_he 已提交
549 550 551
| Name  | Type    | Mandatory  | Description          |
| ----- | ------ | ---- | ------------ |
| value | number | No   | Minimum number of days in the first week of a year.|
S
shawn_he 已提交
552

S
shawn_he 已提交
553
**Example**
S
shawn_he 已提交
554
  ```js
S
shawn_he 已提交
555 556 557 558 559 560 561 562 563 564 565 566 567
  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 已提交
568
**Parameters**
S
shawn_he 已提交
569

S
shawn_he 已提交
570 571 572
| 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 已提交
573

S
shawn_he 已提交
574
**Return value**
S
shawn_he 已提交
575

S
shawn_he 已提交
576 577 578
| 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 已提交
579

S
shawn_he 已提交
580
**Example**
S
shawn_he 已提交
581
  ```js
S
shawn_he 已提交
582
  var calendar = i18n.getCalendar("zh-Hans");
S
shawn_he 已提交
583
  calendar.set(2021, 10, 1, 8, 0, 0); // set time to 2021.10.1 08:00:00
S
shawn_he 已提交
584 585 586 587 588 589 590 591 592 593 594 595
  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 已提交
596
**Parameters**
S
shawn_he 已提交
597

S
shawn_he 已提交
598 599 600
| 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 已提交
601

S
shawn_he 已提交
602
**Return value**
S
shawn_he 已提交
603

S
shawn_he 已提交
604 605 606
| Type    | Description                 |
| ------ | ------------------- |
| string | Name of the **Calendar** object displayed for the specified locale.|
S
shawn_he 已提交
607

S
shawn_he 已提交
608
**Example**
S
shawn_he 已提交
609
  ```js
S
shawn_he 已提交
610 611 612 613 614 615 616 617 618 619 620 621 622
  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 已提交
623
**Parameters**
S
shawn_he 已提交
624

S
shawn_he 已提交
625 626 627
| 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 已提交
628

S
shawn_he 已提交
629
**Return value**
S
shawn_he 已提交
630

S
shawn_he 已提交
631 632 633
| Type     | Description                                 |
| ------- | ----------------------------------- |
| boolean | Returns **true** if the date is a weekend; returns **false** if the date is a weekday.|
S
shawn_he 已提交
634

S
shawn_he 已提交
635
**Example**
S
shawn_he 已提交
636
  ```js
S
shawn_he 已提交
637
  var calendar = i18n.getCalendar("zh-Hans");
S
shawn_he 已提交
638
  calendar.set(2021, 11, 11, 8, 0, 0); // set time to 2021.11.11 08:00:00
S
shawn_he 已提交
639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654
  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 已提交
655 656

Parameters
S
shawn_he 已提交
657 658 659
| Name    | Type                                      | Mandatory  | Description              |
| ------- | ---------------------------------------- | ---- | ---------------- |
| country | string                                   | Yes   | Country or region to which the phone number to be formatted belongs.|
S
shawn_he 已提交
660
| options | [PhoneNumberFormatOptions](#phonenumberformatoptions9) | No   | Options of the **PhoneNumberFormat** object. |
Z
zengyawen 已提交
661

S
shawn_he 已提交
662
**Example**
S
shawn_he 已提交
663
  ```js
S
shawn_he 已提交
664 665 666 667 668 669 670
  var phoneNumberFormat= new i18n.PhoneNumberFormat("CN", {"type": "E164"});
  ```


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

isValidNumber(number: string): boolean
Z
zengyawen 已提交
671 672 673

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

S
shawn_he 已提交
674 675
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
676
**Parameters**
S
shawn_he 已提交
677

S
shawn_he 已提交
678 679 680
| Name   | Type    | Mandatory  | Description       |
| ------ | ------ | ---- | --------- |
| number | string | Yes   | Phone number to be checked.|
S
shawn_he 已提交
681

S
shawn_he 已提交
682
**Return value**
S
shawn_he 已提交
683

S
shawn_he 已提交
684 685 686
| Type     | Description                                   |
| ------- | ------------------------------------- |
| boolean | Returns **true** if the phone number format is valid; returns **false** otherwise.|
S
shawn_he 已提交
687

S
shawn_he 已提交
688
**Example**
S
shawn_he 已提交
689
  ```js
S
shawn_he 已提交
690 691 692 693 694 695 696 697
  var phonenumberfmt = new i18n.PhoneNumberFormat("CN");
  phonenumberfmt.isValidNumber("15812312312");
  ```


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

format(number: string): string
Z
zengyawen 已提交
698 699 700

Formats a phone number.

S
shawn_he 已提交
701 702
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
703
**Parameters**
S
shawn_he 已提交
704

S
shawn_he 已提交
705 706 707
| Name   | Type    | Mandatory  | Description        |
| ------ | ------ | ---- | ---------- |
| number | string | Yes   | Phone number to be formatted.|
S
shawn_he 已提交
708

S
shawn_he 已提交
709
**Return value**
S
shawn_he 已提交
710

S
shawn_he 已提交
711 712 713
| Type    | Description        |
| ------ | ---------- |
| string | Formatted phone number.|
S
shawn_he 已提交
714

S
shawn_he 已提交
715
**Example**
S
shawn_he 已提交
716
  ```js
S
shawn_he 已提交
717
  var phonenumberfmt = new i18n.PhoneNumberFormat("CN");
S
shawn_he 已提交
718
  phonenumberfmt.isValidNumber("15812312312");
S
shawn_he 已提交
719 720
  ```

S
shawn_he 已提交
721
### getLocationName<sup>9+</sup>
S
shawn_he 已提交
722

S
shawn_he 已提交
723
getLocationName(number: string, locale: string): string
S
shawn_he 已提交
724 725 726 727 728 729

Obtains the home location of a phone number.

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

**Parameters**
S
shawn_he 已提交
730

S
shawn_he 已提交
731 732 733 734 735 736
| Name   | Type    | Mandatory  | Description        |
| ------ | ------ | ---- | ---------- |
| number | string | Yes   | Phone number.|
| locale | string | Yes   | Locale ID.|

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

S
shawn_he 已提交
738 739 740 741 742
| Type    | Description        |
| ------ | ---------- |
| string | Home location of the phone number.|

**Example**
S
shawn_he 已提交
743 744 745
  ```js
  var phonenumberfmt = new i18n.PhoneNumberFormat("CN");
  phonenumberfmt.isValidNumber("15812312312");
S
shawn_he 已提交
746 747
  ```

S
shawn_he 已提交
748

S
shawn_he 已提交
749
## PhoneNumberFormatOptions<sup>9+</sup>
S
shawn_he 已提交
750 751 752

Defines the options for this PhoneNumberFormat object.

S
shawn_he 已提交
753
**System capability**: SystemCapability.Global.I18n
S
shawn_he 已提交
754

S
shawn_he 已提交
755 756
| Name  | Type  | Readable  | Writable  | Description                                      |
| ---- | ------ | ---- | ---- | ---------------------------------------- |
S
shawn_he 已提交
757
| 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 已提交
758 759 760


## UnitInfo<sup>8+</sup>
Z
zengyawen 已提交
761 762 763

Defines the measurement unit information.

S
shawn_he 已提交
764
**System capability**: SystemCapability.Global.I18n
S
shawn_he 已提交
765

S
shawn_he 已提交
766 767 768
| Name           | Type  | Readable  | Writable  | Description                                      |
| ------------- | ------ | ---- | ---- | ---------------------------------------- |
| unit          | string | Yes   | Yes   | Name of the measurement unit, for example, **meter**, **inch**, or **cup**.|
S
shawn_he 已提交
769
| measureSystem | string | Yes   | Yes   | Measurement system. The value can be **SI**,&nbsp;**US**, or&nbsp;**UK**.|
S
shawn_he 已提交
770 771


S
shawn_he 已提交
772
## Util<sup>(deprecated)</sup>
S
shawn_he 已提交
773 774


S
shawn_he 已提交
775
### unitConvert<sup>(deprecated)</sup>
S
shawn_he 已提交
776

S
shawn_he 已提交
777
static unitConvert(fromUnit: UnitInfo, toUnit: UnitInfo, value: number, locale: string, style?: string): string
Z
zengyawen 已提交
778 779 780

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

S
shawn_he 已提交
781 782 783 784 785
> **NOTE**
> This API is deprecated since API version 9. You are advised to use [unitConvert](#unitconvert9) instead.
>
> This API is supported since API version 8.

S
shawn_he 已提交
786 787
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
788
**Parameters**
S
shawn_he 已提交
789

S
shawn_he 已提交
790 791 792 793 794 795
| 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 已提交
796
| style    | string                 | No   | Style used for formatting. The value can be **long**, **short**, or **narrow**.|
S
shawn_he 已提交
797

S
shawn_he 已提交
798
**Return value**
S
shawn_he 已提交
799 800 801

| Type    | Description                     |
| ------ | ----------------------- |
S
shawn_he 已提交
802
| string | Character string obtained after formatting based on the measurement unit specified by **toUnit**.|
S
shawn_he 已提交
803

S
shawn_he 已提交
804

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

S
shawn_he 已提交
807
getInstance(locale?:string): IndexUtil
S
shawn_he 已提交
808 809 810 811 812

Creates an **IndexUtil** object.

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

S
shawn_he 已提交
813
**Parameters**
S
shawn_he 已提交
814

S
shawn_he 已提交
815 816 817
| Name   | Type    | Mandatory  | Description                          |
| ------ | ------ | ---- | ---------------------------- |
| locale | string | No   | A string containing locale information, including the language, optional script, and region.|
S
shawn_he 已提交
818

S
shawn_he 已提交
819
**Return value**
S
shawn_he 已提交
820

S
shawn_he 已提交
821 822 823
| Type                      | Description                   |
| ------------------------ | --------------------- |
| [IndexUtil](#indexutil8) | **IndexUtil** object mapping to the specified locale.|
S
shawn_he 已提交
824

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


S
shawn_he 已提交
831 832 833
## IndexUtil<sup>8+</sup>


S
shawn_he 已提交
834 835 836 837 838 839 840 841
### 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 已提交
842
**Return value**
S
shawn_he 已提交
843

S
shawn_he 已提交
844 845 846
| Type                 | Description                |
| ------------------- | ------------------ |
| Array&lt;string&gt; | Index list for this **locale** object.|
S
shawn_he 已提交
847

S
shawn_he 已提交
848
**Example**
S
shawn_he 已提交
849
  ```js
S
shawn_he 已提交
850 851 852 853 854 855 856
  var indexUtil = i18n.getInstance("zh-CN");
  var indexList = indexUtil.getIndexList();
  ```


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

S
shawn_he 已提交
857
addLocale(locale: string): void
S
shawn_he 已提交
858 859 860 861 862

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

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

S
shawn_he 已提交
863
**Parameters**
S
shawn_he 已提交
864

S
shawn_he 已提交
865 866 867
| Name   | Type    | Mandatory  | Description                          |
| ------ | ------ | ---- | ---------------------------- |
| locale | string | Yes   | A string containing locale information, including the language, optional script, and region.|
S
shawn_he 已提交
868

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

S
shawn_he 已提交
886 887 888
| Name | Type    | Mandatory  | Description          |
| ---- | ------ | ---- | ------------ |
| text | string | Yes   | **text** object whose index is to be obtained.|
S
shawn_he 已提交
889

S
shawn_he 已提交
890
**Return value**
S
shawn_he 已提交
891

S
shawn_he 已提交
892 893 894
| Type    | Description         |
| ------ | ----------- |
| string | Index of the **text** object.|
S
shawn_he 已提交
895

S
shawn_he 已提交
896
**Example**
S
shawn_he 已提交
897
  ```js
S
shawn_he 已提交
898 899 900 901 902
  var indexUtil= i18n.getInstance("zh-CN");
  indexUtil.getIndex("hi"); // Return h.
  ```


S
shawn_he 已提交
903
## Character<sup>(deprecated)</sup>
S
shawn_he 已提交
904 905


S
shawn_he 已提交
906
### isDigit<sup>(deprecated)</sup>
S
shawn_he 已提交
907

S
shawn_he 已提交
908
static isDigit(char: string): boolean
S
shawn_he 已提交
909 910 911

Checks whether the input character string is composed of digits.

S
shawn_he 已提交
912 913 914 915 916
> **NOTE**
> This API is deprecated since API version 9. You are advised to use [isDigit](#isdigit9) instead.
>
> This API is supported since API version 8.

S
shawn_he 已提交
917 918
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
919
**Parameters**
S
shawn_he 已提交
920

S
shawn_he 已提交
921 922 923
| Name | Type    | Mandatory  | Description   |
| ---- | ------ | ---- | ----- |
| char | string | Yes   | Input character.|
S
shawn_he 已提交
924

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

S
shawn_he 已提交
927 928 929
| Type     | Description                                  |
| ------- | ------------------------------------ |
| boolean | Returns **true** if the input character is a digit; returns **false** otherwise.|
S
shawn_he 已提交
930 931 932



S
shawn_he 已提交
933
### isSpaceChar<sup>(deprecated)</sup>
S
shawn_he 已提交
934

S
shawn_he 已提交
935
static isSpaceChar(char: string): boolean
Z
zengyawen 已提交
936

Z
zengyawen 已提交
937
Checks whether the input character is a space.
Z
zengyawen 已提交
938

S
shawn_he 已提交
939 940 941 942 943
> **NOTE**
> This API is deprecated since API version 9. You are advised to use [isSpaceChar](#isspacechar9) instead.
>
> This API is supported since API version 8.

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

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

S
shawn_he 已提交
948 949 950
| Name | Type    | Mandatory  | Description   |
| ---- | ------ | ---- | ----- |
| char | string | Yes   | Input character.|
S
shawn_he 已提交
951

S
shawn_he 已提交
952
**Return value**
S
shawn_he 已提交
953

S
shawn_he 已提交
954 955 956
| Type     | Description                                    |
| ------- | -------------------------------------- |
| boolean | Returns **true** if the input character is a space; returns **false** otherwise.|
S
shawn_he 已提交
957 958 959



S
shawn_he 已提交
960
### isWhitespace<sup>(deprecated)</sup>
S
shawn_he 已提交
961

S
shawn_he 已提交
962
static isWhitespace(char: string): boolean
Z
zengyawen 已提交
963

Z
zengyawen 已提交
964
Checks whether the input character is a white space.
Z
zengyawen 已提交
965

S
shawn_he 已提交
966 967 968 969 970
> **NOTE**
> This API is deprecated since API version 9. You are advised to use [isWhitespace](#iswhitespace9) instead.
>
> This API is supported since API version 8.

S
shawn_he 已提交
971 972
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
973
**Parameters**
S
shawn_he 已提交
974

S
shawn_he 已提交
975 976 977
| Name | Type    | Mandatory  | Description   |
| ---- | ------ | ---- | ----- |
| char | string | Yes   | Input character.|
S
shawn_he 已提交
978

S
shawn_he 已提交
979
**Return value**
S
shawn_he 已提交
980

S
shawn_he 已提交
981 982 983
| Type     | Description                                    |
| ------- | -------------------------------------- |
| boolean | Returns **true** if the input character is a white space; returns **false** otherwise.|
S
shawn_he 已提交
984 985 986



S
shawn_he 已提交
987
### isRTL<sup>(deprecated)</sup>
S
shawn_he 已提交
988

S
shawn_he 已提交
989
static isRTL(char: string): boolean
S
shawn_he 已提交
990 991 992

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

S
shawn_he 已提交
993 994 995 996 997
> **NOTE**
> This API is deprecated since API version 9. You are advised to use [isRTL](#isrtl9) instead.
>
> This API is supported since API version 8.

S
shawn_he 已提交
998 999
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
1000
**Parameters**
S
shawn_he 已提交
1001

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

S
shawn_he 已提交
1006
**Return value**
S
shawn_he 已提交
1007

S
shawn_he 已提交
1008 1009 1010
| Type     | Description                                      |
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the input character is of the RTL language; returns **false** otherwise.|
S
shawn_he 已提交
1011 1012 1013



S
shawn_he 已提交
1014
### isIdeograph<sup>(deprecated)</sup>
S
shawn_he 已提交
1015

S
shawn_he 已提交
1016
static isIdeograph(char: string): boolean
Z
zengyawen 已提交
1017

Z
zengyawen 已提交
1018
Checks whether the input character is an ideographic character.
Z
zengyawen 已提交
1019

S
shawn_he 已提交
1020 1021 1022 1023 1024
> **NOTE**
> This API is deprecated since API version 9. You are advised to use [isIdeograph](#isideograph9) instead.
>
> This API is supported since API version 8.

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

S
shawn_he 已提交
1027
**Parameters**
S
shawn_he 已提交
1028

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

S
shawn_he 已提交
1033
**Return value**
S
shawn_he 已提交
1034

S
shawn_he 已提交
1035 1036 1037
| Type     | Description                                      |
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the input character is an ideographic character; returns **false** otherwise.|
S
shawn_he 已提交
1038 1039 1040



S
shawn_he 已提交
1041
### isLetter<sup>(deprecated)</sup>
S
shawn_he 已提交
1042

S
shawn_he 已提交
1043
static isLetter(char: string): boolean
Z
zengyawen 已提交
1044

Z
zengyawen 已提交
1045
Checks whether the input character is a letter.
Z
zengyawen 已提交
1046

S
shawn_he 已提交
1047 1048 1049 1050 1051
> **NOTE**
> This API is deprecated since API version 9. You are advised to use [isLetter](#isletter9) instead.
>
> This API is supported since API version 8.

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

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

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

S
shawn_he 已提交
1060
**Return value**
S
shawn_he 已提交
1061

S
shawn_he 已提交
1062 1063 1064
| Type     | Description                                  |
| ------- | ------------------------------------ |
| boolean | Returns **true** if the input character is a letter; returns **false** otherwise.|
S
shawn_he 已提交
1065 1066 1067



S
shawn_he 已提交
1068
### isLowerCase<sup>(deprecated)</sup>
S
shawn_he 已提交
1069

S
shawn_he 已提交
1070
static isLowerCase(char: string): boolean
Z
zengyawen 已提交
1071

Z
zengyawen 已提交
1072
Checks whether the input character is a lowercase letter.
Z
zengyawen 已提交
1073

S
shawn_he 已提交
1074 1075 1076 1077 1078
> **NOTE**
> This API is deprecated since API version 9. You are advised to use [isLowerCase](#islowercase9) instead.
>
> This API is supported since API version 8.

S
shawn_he 已提交
1079 1080
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
1081
**Parameters**
S
shawn_he 已提交
1082

S
shawn_he 已提交
1083 1084 1085
| Name | Type    | Mandatory  | Description   |
| ---- | ------ | ---- | ----- |
| char | string | Yes   | Input character.|
S
shawn_he 已提交
1086

S
shawn_he 已提交
1087
**Return value**
S
shawn_he 已提交
1088

S
shawn_he 已提交
1089 1090 1091
| Type     | Description                                      |
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the input character is a lowercase letter; returns **false** otherwise.|
S
shawn_he 已提交
1092 1093 1094



S
shawn_he 已提交
1095
### isUpperCase<sup>(deprecated)</sup>
S
shawn_he 已提交
1096

S
shawn_he 已提交
1097
static isUpperCase(char: string): boolean
Z
zengyawen 已提交
1098

Z
zengyawen 已提交
1099
Checks whether the input character is an uppercase letter.
Z
zengyawen 已提交
1100

S
shawn_he 已提交
1101 1102 1103 1104 1105
> **NOTE**
> This API is deprecated since API version 9. You are advised to use [isUpperCase](#isuppercase9) instead.
>
> This API is supported since API version 8.

S
shawn_he 已提交
1106 1107
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
1108
**Parameters**
S
shawn_he 已提交
1109

S
shawn_he 已提交
1110 1111 1112
| Name | Type    | Mandatory  | Description   |
| ---- | ------ | ---- | ----- |
| char | string | Yes   | Input character.|
S
shawn_he 已提交
1113

S
shawn_he 已提交
1114
**Return value**
S
shawn_he 已提交
1115

S
shawn_he 已提交
1116 1117 1118
| Type     | Description                                      |
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the input character is an uppercase letter; returns **false** otherwise.|
S
shawn_he 已提交
1119 1120 1121



S
shawn_he 已提交
1122
### getType<sup>(deprecated)</sup>
S
shawn_he 已提交
1123

S
shawn_he 已提交
1124
static getType(char: string): string
Z
zengyawen 已提交
1125 1126 1127

Obtains the type of the input character string.

S
shawn_he 已提交
1128 1129 1130 1131 1132
> **NOTE**
> This API is deprecated since API version 9. You are advised to use [getType](#gettype9) instead.
>
> This API is supported since API version 8.

S
shawn_he 已提交
1133
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1134

S
shawn_he 已提交
1135
**Parameters**
S
shawn_he 已提交
1136

S
shawn_he 已提交
1137 1138 1139
| Name | Type    | Mandatory  | Description   |
| ---- | ------ | ---- | ----- |
| char | string | Yes   | Input character.|
Z
zengyawen 已提交
1140

S
shawn_he 已提交
1141
**Return value**
S
shawn_he 已提交
1142

S
shawn_he 已提交
1143 1144 1145
| Type    | Description         |
| ------ | ----------- |
| string | Type of the input character.|
Z
zengyawen 已提交
1146 1147 1148



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

S
shawn_he 已提交
1151
getLineInstance(locale: string): BreakIterator
Z
zengyawen 已提交
1152

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

S
shawn_he 已提交
1155
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1156

S
shawn_he 已提交
1157
**Parameters**
S
shawn_he 已提交
1158

S
shawn_he 已提交
1159 1160 1161
| 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 已提交
1162

S
shawn_he 已提交
1163
**Return value**
S
shawn_he 已提交
1164

S
shawn_he 已提交
1165 1166 1167
| Type                              | Description         |
| -------------------------------- | ----------- |
| [BreakIterator](#breakiterator8) | [BreakIterator](#breakiterator8) object used for text segmentation.|
Z
zengyawen 已提交
1168

S
shawn_he 已提交
1169
**Example**
S
shawn_he 已提交
1170
  ```js
S
shawn_he 已提交
1171
  var iterator = i18n.getLineInstance("en");
S
shawn_he 已提交
1172
  ```
Z
zengyawen 已提交
1173 1174


S
shawn_he 已提交
1175
## BreakIterator<sup>8+</sup>
Z
zengyawen 已提交
1176 1177


S
shawn_he 已提交
1178
### setLineBreakText<sup>8+</sup>
Z
zengyawen 已提交
1179

S
shawn_he 已提交
1180
setLineBreakText(text: string): void
Z
zengyawen 已提交
1181

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

S
shawn_he 已提交
1184
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1185

S
shawn_he 已提交
1186
**Parameters**
S
shawn_he 已提交
1187

S
shawn_he 已提交
1188 1189 1190
| Name | Type    | Mandatory  | Description                     |
| ---- | ------ | ---- | ----------------------- |
| text | string | Yes   | Text to be processed by the **BreakIterator** object.|
Z
zengyawen 已提交
1191

S
shawn_he 已提交
1192
**Example**
S
shawn_he 已提交
1193
  ```js
S
shawn_he 已提交
1194
  var iterator = i18n.getLineInstance("en");
S
shawn_he 已提交
1195 1196
  iterator.setLineBreakText("Apple is my favorite fruit.");
  ```
Z
zengyawen 已提交
1197 1198


S
shawn_he 已提交
1199
### getLineBreakText<sup>8+</sup>
Z
zengyawen 已提交
1200

S
shawn_he 已提交
1201
getLineBreakText(): string
Z
zengyawen 已提交
1202

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

S
shawn_he 已提交
1205
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1206

S
shawn_he 已提交
1207
**Return value**
S
shawn_he 已提交
1208

S
shawn_he 已提交
1209 1210 1211
| Type    | Description                    |
| ------ | ---------------------- |
| string | Text being processed by the **BreakIterator** object.|
Z
zengyawen 已提交
1212

S
shawn_he 已提交
1213
**Example**
S
shawn_he 已提交
1214
  ```js
S
shawn_he 已提交
1215
  var iterator = i18n.getLineInstance("en");
S
shawn_he 已提交
1216 1217 1218
  iterator.setLineBreakText("Apple is my favorite fruit.");
  iterator.getLineBreakText(); // Apple is my favorite fruit.
  ```
Z
zengyawen 已提交
1219 1220


S
shawn_he 已提交
1221
### current<sup>8+</sup>
Z
zengyawen 已提交
1222

S
shawn_he 已提交
1223 1224 1225 1226 1227 1228
current(): number

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

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

S
shawn_he 已提交
1229
**Return value**
S
shawn_he 已提交
1230

S
shawn_he 已提交
1231 1232 1233
| Type    | Description                         |
| ------ | --------------------------- |
| number | Position of the **BreakIterator** object in the text being processed.|
S
shawn_he 已提交
1234

S
shawn_he 已提交
1235
**Example**
S
shawn_he 已提交
1236
  ```js
S
shawn_he 已提交
1237
  var iterator = i18n.getLineInstance("en");
S
shawn_he 已提交
1238
  iterator.setLineBreakText("Apple is my favorite fruit.");
S
shawn_he 已提交
1239
  iterator.current(); // 0
S
shawn_he 已提交
1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250
  ```


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

S
shawn_he 已提交
1253 1254 1255
| Type    | Description               |
| ------ | ----------------- |
| number | Offset to the first text boundary of the processed text.|
S
shawn_he 已提交
1256

S
shawn_he 已提交
1257
**Example**
S
shawn_he 已提交
1258
  ```js
S
shawn_he 已提交
1259
  var iterator = i18n.getLineInstance("en");
S
shawn_he 已提交
1260
  iterator.setLineBreakText("Apple is my favorite fruit.");
S
shawn_he 已提交
1261
  iterator.first(); // 0
S
shawn_he 已提交
1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272
  ```


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

S
shawn_he 已提交
1275 1276 1277
| Type    | Description                |
| ------ | ------------------ |
| number | Offset of the last text boundary of the processed text.|
S
shawn_he 已提交
1278

S
shawn_he 已提交
1279
**Example**
S
shawn_he 已提交
1280
  ```js
S
shawn_he 已提交
1281
  var iterator = i18n.getLineInstance("en");
S
shawn_he 已提交
1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294
  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 已提交
1295
**Parameters**
S
shawn_he 已提交
1296

S
shawn_he 已提交
1297 1298 1299
| 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 已提交
1300

S
shawn_he 已提交
1301
**Return value**
S
shawn_he 已提交
1302

S
shawn_he 已提交
1303 1304 1305
| 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 已提交
1306

S
shawn_he 已提交
1307
**Example**
S
shawn_he 已提交
1308
  ```js
S
shawn_he 已提交
1309
  var iterator = i18n.getLineInstance("en");
S
shawn_he 已提交
1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324
  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 已提交
1325
**Return value**
S
shawn_he 已提交
1326

S
shawn_he 已提交
1327 1328 1329
| 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 已提交
1330

S
shawn_he 已提交
1331
**Example**
S
shawn_he 已提交
1332
  ```js
S
shawn_he 已提交
1333
  var iterator = i18n.getLineInstance("en");
S
shawn_he 已提交
1334 1335 1336 1337 1338
  iterator.setLineBreakText("Apple is my favorite fruit.");
  iterator.first(); // 0
  iterator.next(3); // 12
  iterator.previous(); // 9
  ```
Z
zengyawen 已提交
1339 1340


S
shawn_he 已提交
1341
### following<sup>8+</sup>
Z
zengyawen 已提交
1342

S
shawn_he 已提交
1343
following(offset: number): number
Z
zengyawen 已提交
1344

S
shawn_he 已提交
1345
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 已提交
1346

S
shawn_he 已提交
1347
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1348

S
shawn_he 已提交
1349
**Parameters**
S
shawn_he 已提交
1350

S
shawn_he 已提交
1351 1352 1353
| 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 已提交
1354

S
shawn_he 已提交
1355
**Return value**
S
shawn_he 已提交
1356

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

S
shawn_he 已提交
1361
**Example**
S
shawn_he 已提交
1362
  ```js
S
shawn_he 已提交
1363
  var iterator = i18n.getLineInstance("en");
S
shawn_he 已提交
1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378
  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 已提交
1379
**Parameters**
S
shawn_he 已提交
1380

S
shawn_he 已提交
1381 1382 1383
| Name   | Type    | Mandatory  | Description         |
| ------ | ------ | ---- | ----------- |
| offset | number | Yes   | Position to check.|
S
shawn_he 已提交
1384

S
shawn_he 已提交
1385
**Return value**
S
shawn_he 已提交
1386

S
shawn_he 已提交
1387 1388 1389
| Type     | Description                             |
| ------- | ------------------------------- |
| boolean | Returns **true** if the position specified by the offset is a text boundary; returns **false** otherwise.|
S
shawn_he 已提交
1390

S
shawn_he 已提交
1391
**Example**
S
shawn_he 已提交
1392
  ```js
S
shawn_he 已提交
1393
  var iterator = i18n.getLineInstance("en");
S
shawn_he 已提交
1394 1395 1396 1397 1398 1399
  iterator.setLineBreakText("Apple is my favorite fruit.");
  iterator.isBoundary(0); // true;
  iterator.isBoundary(5); // false;
  ```


S
shawn_he 已提交
1400
## i18n.is24HourClock<sup>7+</sup>
S
shawn_he 已提交
1401 1402 1403 1404 1405 1406 1407

is24HourClock(): boolean

Checks whether the 24-hour clock is used.

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

S
shawn_he 已提交
1408
**Return value**
S
shawn_he 已提交
1409

S
shawn_he 已提交
1410 1411 1412
| Type     | Description                                      |
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the 24-hour clock is used; returns **false** otherwise.|
S
shawn_he 已提交
1413

S
shawn_he 已提交
1414
**Example**
S
shawn_he 已提交
1415
  ```js
S
shawn_he 已提交
1416 1417 1418 1419
  var is24HourClock = i18n.is24HourClock();
  ```


S
shawn_he 已提交
1420
## i18n.set24HourClock<sup>7+</sup>
S
shawn_he 已提交
1421 1422

set24HourClock(option: boolean): boolean
Z
zengyawen 已提交
1423 1424 1425

Sets the 24-hour clock.

S
shawn_he 已提交
1426
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
S
shawn_he 已提交
1427

S
shawn_he 已提交
1428 1429
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
1430
**Parameters**
S
shawn_he 已提交
1431

S
shawn_he 已提交
1432 1433 1434
| 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 已提交
1435

S
shawn_he 已提交
1436
**Return value**
S
shawn_he 已提交
1437

S
shawn_he 已提交
1438 1439 1440
| Type     | Description                           |
| ------- | ----------------------------- |
| boolean | Returns **true** if the 24-hour clock is enabled; returns **false** otherwise.|
S
shawn_he 已提交
1441

S
shawn_he 已提交
1442
**Example**
S
shawn_he 已提交
1443
  ```js
S
shawn_he 已提交
1444
  // Set the system time to the 24-hour clock.
S
shawn_he 已提交
1445
  var success = i18n.set24HourClock(true);
S
shawn_he 已提交
1446 1447 1448 1449 1450 1451
  ```


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

addPreferredLanguage(language: string, index?: number): boolean
Z
zengyawen 已提交
1452 1453 1454

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

S
shawn_he 已提交
1455
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
S
shawn_he 已提交
1456

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

S
shawn_he 已提交
1459
**Parameters**
S
shawn_he 已提交
1460

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

S
shawn_he 已提交
1466
**Return value**
S
shawn_he 已提交
1467

S
shawn_he 已提交
1468 1469 1470
| Type     | Description                           |
| ------- | ----------------------------- |
| boolean | Returns **true** if the preferred language is successfully added; returns **false** otherwise.|
S
shawn_he 已提交
1471

S
shawn_he 已提交
1472
**Example**
S
shawn_he 已提交
1473
  ```js
S
shawn_he 已提交
1474 1475 1476 1477 1478 1479 1480
  // Add zh-CN to the preferred language list.
  var language = 'zh-CN';
  var index = 0;
  var success = i18n.addPreferredLanguage(language, index);
  ```


S
shawn_he 已提交
1481
## i18n.removePreferredLanguage<sup>8+</sup>
S
shawn_he 已提交
1482

S
shawn_he 已提交
1483
removePreferredLanguage(index: number): boolean
Z
zengyawen 已提交
1484 1485 1486

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

S
shawn_he 已提交
1487
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
S
shawn_he 已提交
1488

S
shawn_he 已提交
1489
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1490

S
shawn_he 已提交
1491
**Parameters**
S
shawn_he 已提交
1492

S
shawn_he 已提交
1493 1494 1495
| Name  | Type    | Mandatory  | Description                   |
| ----- | ------ | ---- | --------------------- |
| index | number | Yes   | Position of the preferred language to delete.|
Z
zengyawen 已提交
1496

S
shawn_he 已提交
1497
**Return value**
S
shawn_he 已提交
1498

S
shawn_he 已提交
1499 1500 1501
| Type     | Description                           |
| ------- | ----------------------------- |
| boolean | Returns **true** if the preferred language is deleted; returns **false** otherwise.|
Z
zengyawen 已提交
1502

S
shawn_he 已提交
1503
**Example**
S
shawn_he 已提交
1504
  ```js
S
shawn_he 已提交
1505 1506 1507 1508
  // Delete the first preferred language from the preferred language list.
  var index = 0;
  var success = i18n.removePreferredLanguage(index);
  ```
Z
zengyawen 已提交
1509 1510


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

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

S
shawn_he 已提交
1515
Obtains the list of preferred languages.
Z
zengyawen 已提交
1516

S
shawn_he 已提交
1517
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1518

S
shawn_he 已提交
1519
**Return value**
S
shawn_he 已提交
1520

S
shawn_he 已提交
1521 1522 1523
| Type                 | Description       |
| ------------------- | --------- |
| Array&lt;string&gt; | List of preferred languages.|
Z
zengyawen 已提交
1524

S
shawn_he 已提交
1525
**Example**
S
shawn_he 已提交
1526
  ```js
S
shawn_he 已提交
1527 1528
  var preferredLanguageList = i18n.getPreferredLanguageList();
  ```
Z
zengyawen 已提交
1529 1530


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

S
shawn_he 已提交
1533 1534
getFirstPreferredLanguage(): string

S
shawn_he 已提交
1535
Obtains the first language in the preferred language list.
Z
zengyawen 已提交
1536

S
shawn_he 已提交
1537
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1538

S
shawn_he 已提交
1539
**Return value**
S
shawn_he 已提交
1540

S
shawn_he 已提交
1541 1542 1543
| Type    | Description            |
| ------ | -------------- |
| string | First language in the preferred language list.|
Z
zengyawen 已提交
1544

S
shawn_he 已提交
1545
**Example**
S
shawn_he 已提交
1546
  ```js
S
shawn_he 已提交
1547 1548
  var firstPreferredLanguage = i18n.getFirstPreferredLanguage();
  ```
S
shawn_he 已提交
1549 1550


S
shawn_he 已提交
1551 1552 1553 1554 1555 1556 1557 1558 1559
## i18n.getAppPreferredLanguage<sup>9+</sup>

getAppPreferredLanguage(): string

Obtains the preferred language of an application.

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

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

S
shawn_he 已提交
1561 1562 1563 1564 1565
| Type    | Description            |
| ------ | -------------- |
| string | Preferred language of the application.|

**Example**
S
shawn_he 已提交
1566
  ```js
S
shawn_he 已提交
1567 1568 1569 1570
  var appPreferredLanguage = i18n.getAppPreferredLanguage();
  ```


S
shawn_he 已提交
1571
## i18n.getTimeZone<sup>7+</sup>
S
shawn_he 已提交
1572 1573 1574 1575 1576 1577 1578

getTimeZone(zoneID?: string): TimeZone

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

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

S
shawn_he 已提交
1579
**Parameters**
S
shawn_he 已提交
1580

S
shawn_he 已提交
1581 1582 1583
| Name   | Type    | Mandatory  | Description   |
| ------ | ------ | ---- | ----- |
| zondID | string | No   | Time zone ID.|
S
shawn_he 已提交
1584

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

S
shawn_he 已提交
1587 1588 1589
| Type      | Description          |
| -------- | ------------ |
| TimeZone | **TimeZone** object corresponding to the time zone ID.|
S
shawn_he 已提交
1590

S
shawn_he 已提交
1591
**Example**
S
shawn_he 已提交
1592
  ```js
S
shawn_he 已提交
1593 1594 1595 1596
  var timezone = i18n.getTimeZone();
  ```


S
shawn_he 已提交
1597
## TimeZone
S
shawn_he 已提交
1598 1599


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

getID(): string

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

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

S
shawn_he 已提交
1608
**Return value**
S
shawn_he 已提交
1609

S
shawn_he 已提交
1610 1611 1612
| Type    | Description          |
| ------ | ------------ |
| string | Time zone ID corresponding to the **TimeZone** object.|
S
shawn_he 已提交
1613

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


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

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

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

S
shawn_he 已提交
1636
**Return value**
S
shawn_he 已提交
1637

S
shawn_he 已提交
1638 1639 1640
| Type    | Description           |
| ------ | ------------- |
| string | Representation of the **TimeZone** object in the specified locale.|
S
shawn_he 已提交
1641

S
shawn_he 已提交
1642
**Example**
S
shawn_he 已提交
1643
  ```js
S
shawn_he 已提交
1644 1645 1646 1647 1648
  var timezone = i18n.getTimeZone();
  timezone.getDisplayName("zh-CN", false);
  ```


S
shawn_he 已提交
1649
### getRawOffset
S
shawn_he 已提交
1650 1651 1652 1653 1654 1655 1656

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

S
shawn_he 已提交
1659 1660 1661
| Type    | Description                 |
| ------ | ------------------- |
| number | Offset between the time zone represented by the **TimeZone** object and the UTC time zone.|
S
shawn_he 已提交
1662

S
shawn_he 已提交
1663
**Example**
S
shawn_he 已提交
1664
  ```js
S
shawn_he 已提交
1665 1666 1667 1668 1669
  var timezone = i18n.getTimeZone();
  timezone.getRawOffset();
  ```


S
shawn_he 已提交
1670
### getOffset
S
shawn_he 已提交
1671 1672 1673 1674 1675 1676 1677

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

S
shawn_he 已提交
1680 1681 1682
| 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 已提交
1683

S
shawn_he 已提交
1684
**Example**
S
shawn_he 已提交
1685
  ```js
S
shawn_he 已提交
1686 1687 1688
  var timezone = i18n.getTimeZone();
  timezone.getOffset(1234567890);
  ```
S
shawn_he 已提交
1689 1690 1691 1692 1693 1694 1695 1696 1697 1698

### getAvailableIDs<sup>9+</sup>

static getAvailableIDs(): Array&lt;string&gt;

Obtains the list of time zone IDs supported by the system.

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

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

S
shawn_he 已提交
1700 1701 1702 1703 1704
| Type    | Description                      |
| ------ | ----------------------- |
| Array&lt;string&gt; | List of time zone IDs supported by the system.|

**Example**
S
shawn_he 已提交
1705
  ```js
S
shawn_he 已提交
1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718
  var ids = i18n.TimeZone.getAvailableIDs();
  ```


### getAvailableZoneCityIDs<sup>9+</sup>

static getAvailableZoneCityIDs(): Array&lt;string&gt;

Obtains the list of time zone city IDs supported by the system.

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

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

S
shawn_he 已提交
1720 1721 1722 1723 1724
| Type    | Description                      |
| ------ | ----------------------- |
| Array&lt;string&gt; | List of time zone city IDs supported by the system.|

**Example**
S
shawn_he 已提交
1725
  ```js
S
shawn_he 已提交
1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738
  var cityIDs = i18n.TimeZone.getAvailableZoneCityIDs();
  ```


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

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

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

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

**Parameters**
S
shawn_he 已提交
1739

S
shawn_he 已提交
1740 1741 1742 1743 1744 1745
| Name   | Type    | Mandatory  | Description   |
| ------ | ------ | ---- | ----- |
| cityID | string | Yes   | Time zone city ID.|
| locale | string | Yes   | Locale ID.|

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

S
shawn_he 已提交
1747 1748 1749 1750 1751
| Type    | Description                     |
| ------ | ----------------------- |
| string | Localized display of the time zone city in the specified locale.|

**Example**
S
shawn_he 已提交
1752
  ```js
S
shawn_he 已提交
1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765
  var displayName = i18n.TimeZone.getCityDisplayName("Shanghai", "zh-CN");
  ```


### getTimezoneFromCity<sup>9+</sup>

static getTimezoneFromCity(cityID: string): TimeZone

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

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

**Parameters**
S
shawn_he 已提交
1766

S
shawn_he 已提交
1767 1768 1769 1770 1771
| Name   | Type    | Mandatory  | Description   |
| ------ | ------ | ---- | ----- |
| cityID | string | Yes   | Time zone city ID.|

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

S
shawn_he 已提交
1773 1774 1775 1776 1777
| Type    | Description                     |
| ------ | ----------------------- |
| TimeZone | **TimeZone** object corresponding to the specified time zone city ID.|

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

S
shawn_he 已提交
1796 1797 1798 1799 1800
| 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**
S
shawn_he 已提交
1801

S
shawn_he 已提交
1802 1803 1804 1805 1806
| 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 已提交
1807
  ```js
S
shawn_he 已提交
1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820
  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**
S
shawn_he 已提交
1821

S
shawn_he 已提交
1822 1823 1824 1825 1826
| 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 已提交
1827
  ```js
S
shawn_he 已提交
1828 1829
  var status = i18n.getUsingLocalDigit();
  ```
S
shawn_he 已提交
1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842

## Transliterator<sup>9+</sup>


### getAvailableIDs<sup>9+</sup>

static getAvailableIDs(): string[]

Obtains a list of IDs supported by the **Transliterator** object.

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

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

S
shawn_he 已提交
1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862
| 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**
S
shawn_he 已提交
1863

S
shawn_he 已提交
1864 1865 1866 1867 1868
| Name   | Type     | Mandatory  | Description                  |
| ------ | ------- | ---- | -------------------- |
| id | string  | Yes   | ID supported by the **Transliterator** object.               |

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

S
shawn_he 已提交
1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888
| 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**
S
shawn_he 已提交
1889

S
shawn_he 已提交
1890 1891 1892 1893 1894
| Name   | Type     | Mandatory  | Description                  |
| ------ | ------- | ---- | -------------------- |
| text | string  | Yes   | Input string.               |

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

S
shawn_he 已提交
1896 1897 1898 1899 1900 1901 1902 1903 1904
| Type    | Description           |
| ------ | ------------- |
| string | Target string.|

**Example**
  ```
  var transliterator = i18n.Transliterator.getInstance("Any-Latn");
  transliterator.transform ("China");
  ```
S
shawn_he 已提交
1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199

## Unicode<sup>9+</sup>


### isDigit<sup>9+</sup>

static isDigit(char: string): boolean

Checks whether the input character string is composed of digits.

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

**Parameters**

| Name | Type    | Mandatory  | Description   |
| ---- | ------ | ---- | ----- |
| char | string | Yes   | Input character.|

**Return value**

| Type     | Description                                  |
| ------- | ------------------------------------ |
| boolean | Returns **true** if the input character is a digit; returns **false** otherwise.|

**Example**
  ```js
  var isdigit = i18n.Unicode.isDigit("1"); // Return true.
  ```


### isSpaceChar<sup>9+</sup>

static isSpaceChar(char: string): boolean

Checks whether the input character is a space.

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

**Parameters**

| Name | Type    | Mandatory  | Description   |
| ---- | ------ | ---- | ----- |
| char | string | Yes   | Input character.|

**Return value**

| Type     | Description                                    |
| ------- | -------------------------------------- |
| boolean | Returns **true** if the input character is a space; returns **false** otherwise.|

**Example**
  ```js
  var isspacechar = i18n.Unicode.isSpaceChar("a"); // Return false.
  ```


### isWhitespace<sup>9+</sup>

static isWhitespace(char: string): boolean

Checks whether the input character is a white space.

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

**Parameters**

| Name | Type    | Mandatory  | Description   |
| ---- | ------ | ---- | ----- |
| char | string | Yes   | Input character.|

**Return value**

| Type     | Description                                    |
| ------- | -------------------------------------- |
| boolean | Returns **true** if the input character is a white space; returns **false** otherwise.|

**Example**
  ```js
  var iswhitespace = i18n.Unicode.isWhitespace("a"); // Return false.
  ```


### isRTL<sup>9+</sup>

static isRTL(char: string): boolean

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

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

**Parameters**

| Name | Type    | Mandatory  | Description   |
| ---- | ------ | ---- | ----- |
| char | string | Yes   | Input character.|

**Return value**

| Type     | Description                                      |
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the input character is of the RTL language; returns **false** otherwise.|

**Example**
  ```js
  var isrtl = i18n.Unicode.isRTL("a"); // Return false.
  ```


### isIdeograph<sup>9+</sup>

static isIdeograph(char: string): boolean

Checks whether the input character is an ideographic character.

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

**Parameters**

| Name | Type    | Mandatory  | Description   |
| ---- | ------ | ---- | ----- |
| char | string | Yes   | Input character.|

**Return value**

| Type     | Description                                      |
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the input character is an ideographic character; returns **false** otherwise.|

**Example**
  ```js
  var isideograph = i18n.Unicode.isIdeograph("a"); // Return false.
  ```


### isLetter<sup>9+</sup>

static isLetter(char: string): boolean

Checks whether the input character is a letter.

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

**Parameters**

| Name | Type    | Mandatory  | Description   |
| ---- | ------ | ---- | ----- |
| char | string | Yes   | Input character.|

**Return value**

| Type     | Description                                  |
| ------- | ------------------------------------ |
| boolean | Returns **true** if the input character is a letter; returns **false** otherwise.|

**Example**
  ```js
  var isletter = i18n.Unicode.isLetter("a"); // Return true.
  ```


### isLowerCase<sup>9+</sup>

static isLowerCase(char: string): boolean

Checks whether the input character is a lowercase letter.

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

**Parameters**

| Name | Type    | Mandatory  | Description   |
| ---- | ------ | ---- | ----- |
| char | string | Yes   | Input character.|

**Return value**

| Type     | Description                                      |
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the input character is a lowercase letter; returns **false** otherwise.|

**Example**
  ```js
  var islowercase = i18n.Unicode.isLowerCase("a"); // Return true.
  ```


### isUpperCase<sup>9+</sup>

static isUpperCase(char: string): boolean

Checks whether the input character is an uppercase letter.

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

**Parameters**

| Name | Type    | Mandatory  | Description   |
| ---- | ------ | ---- | ----- |
| char | string | Yes   | Input character.|

**Return value**

| Type     | Description                                      |
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the input character is an uppercase letter; returns **false** otherwise.|

**Example**
  ```js
  var isuppercase = i18n.Unicode.isUpperCase("a"); // Return false.
  ```


### getType<sup>9+</sup>

static getType(char: string): string

Obtains the type of the input character string.

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

**Parameters**

| Name | Type    | Mandatory  | Description   |
| ---- | ------ | ---- | ----- |
| char | string | Yes   | Input character.|

**Return value**

| Type    | Description         |
| ------ | ----------- |
| string | Type of the input character.|

**Example**
  ```js
  var type = i18n.Unicode.getType("a");
  ```


## I18NUtil<sup>9+</sup>


### unitConvert<sup>9+</sup>

static unitConvert(fromUnit: UnitInfo, toUnit: UnitInfo, value: number, locale: string, style?: string): string

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

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

**Parameters**

| Name     | Type                    | Mandatory  | Description                                      |
| -------- | ---------------------- | ---- | ---------------------------------------- |
| fromUnit | [UnitInfo](#unitinfo8) | Yes   | Measurement unit to be converted.                                |
| toUnit   | [UnitInfo](#unitinfo8) | Yes   | Measurement unit to be converted to.                                |
| value    | number                 | Yes   | Value of the measurement unit to be converted.                            |
| locale   | string                 | Yes   | Locale used for formatting, for example, **zh-Hans-CN**.               |
| style    | string                 | No   | Style used for formatting. The value can be **long**, **short**, or **narrow**.|

**Return value**

| Type    | Description                     |
| ------ | ----------------------- |
| string | Character string obtained after formatting based on the measurement unit specified by **toUnit**.|

**Example**
  ```js
  i18n.I18NUtil.unitConvert({unit: "cup", measureSystem: "US"}, {unit: "liter", measureSystem: "SI"}, 1000, "en-US", "long");
  ```


### getDateOrder<sup>9+</sup>

static getDateOrder(locale: string): string

Obtains the sequence of the year, month, and day in the specified locale.

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

**Parameters**

| Name   | Type    | Mandatory  | Description                       |
| ------ | ------ | ---- | ------------------------- |
| locale | string | Yes   | Locale used for formatting, for example, **zh-Hans-CN**.|

**Return value**

| Type    | Description                 |
| ------ | ------------------- |
| string | Sequence of the year, month, and day.|

**Example**
  ```js
  i18n.I18NUtil.getDateOrder("zh-CN");
  ```