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

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

S
shawn_he 已提交
8 9

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

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


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

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

Obtains the localized script for the specified language.

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

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

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

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


## i18n.getDisplayCountry

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

Obtains the localized script for the specified country.

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

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

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

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


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

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

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

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

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

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

S
shawn_he 已提交
88
**Example**
S
shawn_he 已提交
89 90 91 92
  ```
  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 已提交
93 94


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

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

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

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

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

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


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

setSystemLanguage(language: string): boolean

Sets the system language.

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

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

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

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

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

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


## i18n.getSystemLanguages

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

Obtains the list of system languages.

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

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

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

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


## i18n.getSystemCountries

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

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

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

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

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

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

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


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

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

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

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

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

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


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

setSystemRegion(region: string): boolean

Sets the system region.

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

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

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

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

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

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


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

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

Obtains the system locale.

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

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

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


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

setSystemLocale(locale: string): boolean

Sets the system locale.

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

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

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

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


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

setTimeZone(timezone: string): void

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

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

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

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

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

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

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


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

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

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

Parameters
S
shawn_he 已提交
616 617 618 619
| 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 已提交
620

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


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

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

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

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

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

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

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


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

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

Formats a phone number.

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

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

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

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

S
shawn_he 已提交
676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701
### getLocationName<sup>8+</sup>

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

Obtains the home location of a phone number.

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

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

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

**Example**
  ```
  var location = i18n.PhoneNumberFormat.getLocationName('15812312345', 'zh-CN');
  ```



S
shawn_he 已提交
702 703 704 705 706

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

Defines the options for this PhoneNumberFormat object.

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

S
shawn_he 已提交
709 710
| Name  | Type  | Readable  | Writable  | Description                                      |
| ---- | ------ | ---- | ---- | ---------------------------------------- |
S
shawn_he 已提交
711
| type | string | Yes   | Yes   | Format type of a phone number. The available options are as follows: E164,&nbsp;INTERNATIONAL,&nbsp;NATIONAL, and&nbsp;RFC3966.|
S
shawn_he 已提交
712 713 714


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

Defines the measurement unit information.

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

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


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


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

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

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

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

S
shawn_he 已提交
737 738 739 740 741 742 743
**Parameters**
| Name     | Type                    | Mandatory  | Description                                      |
| -------- | ---------------------- | ---- | ---------------------------------------- |
| fromUnit | [UnitInfo](#unitinfo8) | Yes   | Measurement unit to be converted.                                |
| toUnit   | [UnitInfo](#unitinfo8) | Yes   | Measurement unit to be converted to.                                |
| value    | number                 | Yes   | Value of the measurement unit to be converted.                            |
| locale   | string                 | Yes   | Locale used for formatting, for example, **zh-Hans-CN**.               |
S
shawn_he 已提交
744
| style    | string                 | No   | Style used for formatting. The value can be **long**, **short**, or **narrow**.|
S
shawn_he 已提交
745

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

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


S
shawn_he 已提交
757
## getInstance<sup>8+</sup>
S
shawn_he 已提交
758

S
shawn_he 已提交
759
getInstance(locale?:string): IndexUtil
S
shawn_he 已提交
760 761 762 763 764

Creates an **IndexUtil** object.

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

S
shawn_he 已提交
765 766 767 768
**Parameters**
| Name   | Type    | Mandatory  | Description                          |
| ------ | ------ | ---- | ---------------------------- |
| locale | string | No   | A string containing locale information, including the language, optional script, and region.|
S
shawn_he 已提交
769

S
shawn_he 已提交
770
**Return value**
S
shawn_he 已提交
771 772 773
| Type                      | Description                   |
| ------------------------ | --------------------- |
| [IndexUtil](#indexutil8) | **IndexUtil** object mapping to the specified locale.|
S
shawn_he 已提交
774

S
shawn_he 已提交
775
**Example**
S
shawn_he 已提交
776
  ```
S
shawn_he 已提交
777
  var indexUtil= i18n.getInstance("zh-CN");
S
shawn_he 已提交
778 779 780
  ```


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


S
shawn_he 已提交
784 785 786 787 788 789 790 791
### 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 已提交
792
**Return value**
S
shawn_he 已提交
793 794 795
| Type                 | Description                |
| ------------------- | ------------------ |
| Array&lt;string&gt; | Index list for this **locale** object.|
S
shawn_he 已提交
796

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


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

S
shawn_he 已提交
806
addLocale(locale: string): void
S
shawn_he 已提交
807 808 809 810 811

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

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

S
shawn_he 已提交
812 813 814 815
**Parameters**
| Name   | Type    | Mandatory  | Description                          |
| ------ | ------ | ---- | ---------------------------- |
| locale | string | Yes   | A string containing locale information, including the language, optional script, and region.|
S
shawn_he 已提交
816

S
shawn_he 已提交
817
**Example**
S
shawn_he 已提交
818 819 820 821 822 823 824 825 826 827 828 829 830 831
  ```
  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 已提交
832 833 834 835
**Parameters**
| Name | Type    | Mandatory  | Description          |
| ---- | ------ | ---- | ------------ |
| text | string | Yes   | **text** object whose index is to be obtained.|
S
shawn_he 已提交
836

S
shawn_he 已提交
837
**Return value**
S
shawn_he 已提交
838 839 840
| Type    | Description         |
| ------ | ----------- |
| string | Index of the **text** object.|
S
shawn_he 已提交
841

S
shawn_he 已提交
842
**Example**
S
shawn_he 已提交
843 844 845 846 847 848 849 850 851 852 853
  ```
  var indexUtil= i18n.getInstance("zh-CN");
  indexUtil.getIndex("hi"); // Return h.
  ```


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


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

S
shawn_he 已提交
854
static isDigit(char: string): boolean
S
shawn_he 已提交
855 856 857 858 859

Checks whether the input character string is composed of digits.

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

S
shawn_he 已提交
860 861 862 863
**Parameters**
| Name | Type    | Mandatory  | Description   |
| ---- | ------ | ---- | ----- |
| char | string | Yes   | Input character.|
S
shawn_he 已提交
864

S
shawn_he 已提交
865
**Return value**
S
shawn_he 已提交
866 867 868
| Type     | Description                                  |
| ------- | ------------------------------------ |
| boolean | Returns **true** if the input character is a digit; returns **false** otherwise.|
S
shawn_he 已提交
869

S
shawn_he 已提交
870
**Example**
S
shawn_he 已提交
871
  ```
S
shawn_he 已提交
872
  var isdigit = i18n.Character.isDigit("1"); // Return true.
S
shawn_he 已提交
873 874 875 876 877
  ```


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

S
shawn_he 已提交
878
static isSpaceChar(char: string): boolean
Z
zengyawen 已提交
879

Z
zengyawen 已提交
880
Checks whether the input character is a space.
Z
zengyawen 已提交
881

S
shawn_he 已提交
882 883
**System capability**: SystemCapability.Global.I18n

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

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

S
shawn_he 已提交
894
**Example**
S
shawn_he 已提交
895
  ```
S
shawn_he 已提交
896
  var isspacechar = i18n.Character.isSpaceChar("a"); // Return false.
S
shawn_he 已提交
897 898 899 900 901
  ```


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

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

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

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

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

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

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


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

S
shawn_he 已提交
926
static isRTL(char: string): boolean
S
shawn_he 已提交
927 928 929 930 931

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

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

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

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

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


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

S
shawn_he 已提交
950
static isIdeograph(char: string): boolean
Z
zengyawen 已提交
951

Z
zengyawen 已提交
952
Checks whether the input character is an ideographic character.
Z
zengyawen 已提交
953

S
shawn_he 已提交
954 955
**System capability**: SystemCapability.Global.I18n

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

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

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


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

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

Z
zengyawen 已提交
976
Checks whether the input character is a letter.
Z
zengyawen 已提交
977

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

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

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

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


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

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

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

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

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

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

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


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

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

Z
zengyawen 已提交
1024
Checks whether the input character is an uppercase letter.
Z
zengyawen 已提交
1025

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

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

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

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


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

S
shawn_he 已提交
1046
static getType(char: string): string
Z
zengyawen 已提交
1047 1048 1049

Obtains the type of the input character string.

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

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

S
shawn_he 已提交
1057
**Return value**
S
shawn_he 已提交
1058 1059 1060
| Type    | Description         |
| ------ | ----------- |
| string | Type of the input character.|
Z
zengyawen 已提交
1061

S
shawn_he 已提交
1062
**Example**
S
shawn_he 已提交
1063
  ```
S
shawn_he 已提交
1064
  var type = i18n.Character.getType("a");
S
shawn_he 已提交
1065
  ```
Z
zengyawen 已提交
1066 1067


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

S
shawn_he 已提交
1070
getLineInstance(locale: string): BreakIterator
Z
zengyawen 已提交
1071

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

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

S
shawn_he 已提交
1076 1077 1078 1079
**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 已提交
1080

S
shawn_he 已提交
1081
**Return value**
S
shawn_he 已提交
1082 1083 1084
| Type                              | Description         |
| -------------------------------- | ----------- |
| [BreakIterator](#breakiterator8) | [BreakIterator](#breakiterator8) object used for text segmentation.|
Z
zengyawen 已提交
1085

S
shawn_he 已提交
1086
**Example**
S
shawn_he 已提交
1087
  ```
S
shawn_he 已提交
1088
  var iterator = i18n.getLineInstance("en");
S
shawn_he 已提交
1089
  ```
Z
zengyawen 已提交
1090 1091


S
shawn_he 已提交
1092
## BreakIterator<sup>8+</sup>
Z
zengyawen 已提交
1093 1094


S
shawn_he 已提交
1095
### setLineBreakText<sup>8+</sup>
Z
zengyawen 已提交
1096

S
shawn_he 已提交
1097
setLineBreakText(text: string): void
Z
zengyawen 已提交
1098

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

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

S
shawn_he 已提交
1103 1104 1105 1106
**Parameters**
| Name | Type    | Mandatory  | Description                     |
| ---- | ------ | ---- | ----------------------- |
| text | string | Yes   | Text to be processed by the **BreakIterator** object.|
Z
zengyawen 已提交
1107

S
shawn_he 已提交
1108
**Example**
S
shawn_he 已提交
1109
  ```
S
shawn_he 已提交
1110
  var iterator = i18n.getLineInstance("en");
S
shawn_he 已提交
1111 1112
  iterator.setLineBreakText("Apple is my favorite fruit.");
  ```
Z
zengyawen 已提交
1113 1114


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

S
shawn_he 已提交
1117
getLineBreakText(): string
Z
zengyawen 已提交
1118

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

S
shawn_he 已提交
1121
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1122

S
shawn_he 已提交
1123
**Return value**
S
shawn_he 已提交
1124 1125 1126
| Type    | Description                    |
| ------ | ---------------------- |
| string | Text being processed by the **BreakIterator** object.|
Z
zengyawen 已提交
1127

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


S
shawn_he 已提交
1136
### current<sup>8+</sup>
Z
zengyawen 已提交
1137

S
shawn_he 已提交
1138 1139 1140 1141 1142 1143
current(): number

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

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

S
shawn_he 已提交
1144
**Return value**
S
shawn_he 已提交
1145 1146 1147
| Type    | Description                         |
| ------ | --------------------------- |
| number | Position of the **BreakIterator** object in the text being processed.|
S
shawn_he 已提交
1148

S
shawn_he 已提交
1149
**Example**
S
shawn_he 已提交
1150
  ```
S
shawn_he 已提交
1151
  var iterator = i18n.getLineInstance("en");
S
shawn_he 已提交
1152
  iterator.setLineBreakText("Apple is my favorite fruit.");
S
shawn_he 已提交
1153
  iterator.current(); // 0
S
shawn_he 已提交
1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164
  ```


### 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 已提交
1165
**Return value**
S
shawn_he 已提交
1166 1167 1168
| Type    | Description               |
| ------ | ----------------- |
| number | Offset to the first text boundary of the processed text.|
S
shawn_he 已提交
1169

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


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

S
shawn_he 已提交
1191
**Example**
S
shawn_he 已提交
1192
  ```
S
shawn_he 已提交
1193
  var iterator = i18n.getLineInstance("en");
S
shawn_he 已提交
1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206
  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 已提交
1207 1208 1209 1210
**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 已提交
1211

S
shawn_he 已提交
1212
**Return value**
S
shawn_he 已提交
1213 1214 1215
| 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 已提交
1216

S
shawn_he 已提交
1217
**Example**
S
shawn_he 已提交
1218
  ```
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 1233 1234
  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 已提交
1235
**Return value**
S
shawn_he 已提交
1236 1237 1238
| Type    | Description                                      |
| ------ | ---------------------------------------- |
| number | Position of the [BreakIterator](#breakiterator8) object in the text after it is moved 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 已提交
1239

S
shawn_he 已提交
1240
**Example**
S
shawn_he 已提交
1241
  ```
S
shawn_he 已提交
1242
  var iterator = i18n.getLineInstance("en");
S
shawn_he 已提交
1243 1244 1245 1246 1247
  iterator.setLineBreakText("Apple is my favorite fruit.");
  iterator.first(); // 0
  iterator.next(3); // 12
  iterator.previous(); // 9
  ```
Z
zengyawen 已提交
1248 1249


S
shawn_he 已提交
1250
### following<sup>8+</sup>
Z
zengyawen 已提交
1251

S
shawn_he 已提交
1252
following(offset: number): number
Z
zengyawen 已提交
1253

S
shawn_he 已提交
1254
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 已提交
1255

S
shawn_he 已提交
1256
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1257

S
shawn_he 已提交
1258 1259 1260 1261
**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 已提交
1262

S
shawn_he 已提交
1263
**Return value**
S
shawn_he 已提交
1264 1265 1266
| 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 已提交
1267

S
shawn_he 已提交
1268
**Example**
S
shawn_he 已提交
1269
  ```
S
shawn_he 已提交
1270
  var iterator = i18n.getLineInstance("en");
S
shawn_he 已提交
1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285
  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 已提交
1286 1287 1288 1289
**Parameters**
| Name   | Type    | Mandatory  | Description         |
| ------ | ------ | ---- | ----------- |
| offset | number | Yes   | Position to check.|
S
shawn_he 已提交
1290

S
shawn_he 已提交
1291
**Return value**
S
shawn_he 已提交
1292 1293 1294
| Type     | Description                             |
| ------- | ------------------------------- |
| boolean | Returns **true** if the position specified by the offset is a text boundary; returns **false** otherwise.|
S
shawn_he 已提交
1295

S
shawn_he 已提交
1296
**Example**
S
shawn_he 已提交
1297
  ```
S
shawn_he 已提交
1298
  var iterator = i18n.getLineInstance("en");
S
shawn_he 已提交
1299 1300 1301 1302 1303 1304
  iterator.setLineBreakText("Apple is my favorite fruit.");
  iterator.isBoundary(0); // true;
  iterator.isBoundary(5); // false;
  ```


S
shawn_he 已提交
1305
## i18n.is24HourClock<sup>7+</sup>
S
shawn_he 已提交
1306 1307 1308 1309 1310 1311 1312

is24HourClock(): boolean

Checks whether the 24-hour clock is used.

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

S
shawn_he 已提交
1313
**Return value**
S
shawn_he 已提交
1314 1315 1316
| Type     | Description                                      |
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the 24-hour clock is used; returns **false** otherwise.|
S
shawn_he 已提交
1317

S
shawn_he 已提交
1318
**Example**
S
shawn_he 已提交
1319 1320 1321 1322 1323
  ```
  var is24HourClock = i18n.is24HourClock();
  ```


S
shawn_he 已提交
1324
## i18n.set24HourClock<sup>7+</sup>
S
shawn_he 已提交
1325 1326

set24HourClock(option: boolean): boolean
Z
zengyawen 已提交
1327 1328 1329

Sets the 24-hour clock.

S
shawn_he 已提交
1330
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
S
shawn_he 已提交
1331

S
shawn_he 已提交
1332 1333
**System capability**: SystemCapability.Global.I18n

S
shawn_he 已提交
1334 1335 1336 1337
**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 已提交
1338

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

S
shawn_he 已提交
1344
**Example**
S
shawn_he 已提交
1345 1346
  ```
  // Set the system time to the 24-hour clock.
S
shawn_he 已提交
1347
  var success = i18n.set24HourClock(true);
S
shawn_he 已提交
1348 1349 1350 1351 1352 1353
  ```


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

addPreferredLanguage(language: string, index?: number): boolean
Z
zengyawen 已提交
1354 1355 1356

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

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

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

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

S
shawn_he 已提交
1367
**Return value**
S
shawn_he 已提交
1368 1369 1370
| Type     | Description                           |
| ------- | ----------------------------- |
| boolean | Returns **true** if the preferred language is successfully added; returns **false** otherwise.|
S
shawn_he 已提交
1371

S
shawn_he 已提交
1372
**Example**
S
shawn_he 已提交
1373 1374 1375 1376 1377 1378 1379 1380
  ```
  // Add zh-CN to the preferred language list.
  var language = 'zh-CN';
  var index = 0;
  var success = i18n.addPreferredLanguage(language, index);
  ```


S
shawn_he 已提交
1381
## i18n.removePreferredLanguage<sup>8+</sup>
S
shawn_he 已提交
1382

S
shawn_he 已提交
1383
removePreferredLanguage(index: number): boolean
Z
zengyawen 已提交
1384 1385 1386

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

S
shawn_he 已提交
1387
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
S
shawn_he 已提交
1388

S
shawn_he 已提交
1389
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1390

S
shawn_he 已提交
1391 1392 1393 1394
**Parameters**
| Name  | Type    | Mandatory  | Description                   |
| ----- | ------ | ---- | --------------------- |
| index | number | Yes   | Position of the preferred language to delete.|
Z
zengyawen 已提交
1395

S
shawn_he 已提交
1396
**Return value**
S
shawn_he 已提交
1397 1398 1399
| Type     | Description                           |
| ------- | ----------------------------- |
| boolean | Returns **true** if the preferred language is deleted; returns **false** otherwise.|
Z
zengyawen 已提交
1400

S
shawn_he 已提交
1401
**Example**
S
shawn_he 已提交
1402 1403 1404 1405 1406
  ```
  // Delete the first preferred language from the preferred language list.
  var index = 0;
  var success = i18n.removePreferredLanguage(index);
  ```
Z
zengyawen 已提交
1407 1408


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

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

S
shawn_he 已提交
1413
Obtains the list of preferred languages.
Z
zengyawen 已提交
1414

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

S
shawn_he 已提交
1417
**Return value**
S
shawn_he 已提交
1418 1419 1420
| Type                 | Description       |
| ------------------- | --------- |
| Array&lt;string&gt; | List of preferred languages.|
Z
zengyawen 已提交
1421

S
shawn_he 已提交
1422
**Example**
S
shawn_he 已提交
1423 1424 1425
  ```
  var preferredLanguageList = i18n.getPreferredLanguageList();
  ```
Z
zengyawen 已提交
1426 1427


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

S
shawn_he 已提交
1430 1431
getFirstPreferredLanguage(): string

S
shawn_he 已提交
1432
Obtains the first language in the preferred language list.
Z
zengyawen 已提交
1433

S
shawn_he 已提交
1434
**System capability**: SystemCapability.Global.I18n
Z
zengyawen 已提交
1435

S
shawn_he 已提交
1436
**Return value**
S
shawn_he 已提交
1437 1438 1439
| Type    | Description            |
| ------ | -------------- |
| string | First language in the preferred language list.|
Z
zengyawen 已提交
1440

S
shawn_he 已提交
1441
**Example**
S
shawn_he 已提交
1442 1443 1444
  ```
  var firstPreferredLanguage = i18n.getFirstPreferredLanguage();
  ```
S
shawn_he 已提交
1445 1446


S
shawn_he 已提交
1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465
## i18n.getAppPreferredLanguage<sup>9+</sup>

getAppPreferredLanguage(): string

Obtains the preferred language of an application.

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

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

**Example**
  ```
  var appPreferredLanguage = i18n.getAppPreferredLanguage();
  ```


S
shawn_he 已提交
1466
## i18n.getTimeZone<sup>7+</sup>
S
shawn_he 已提交
1467 1468 1469 1470 1471 1472 1473

getTimeZone(zoneID?: string): TimeZone

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

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

S
shawn_he 已提交
1474 1475 1476 1477
**Parameters**
| Name   | Type    | Mandatory  | Description   |
| ------ | ------ | ---- | ----- |
| zondID | string | No   | Time zone ID.|
S
shawn_he 已提交
1478

S
shawn_he 已提交
1479
**Return value**
S
shawn_he 已提交
1480 1481 1482
| Type      | Description          |
| -------- | ------------ |
| TimeZone | **TimeZone** object corresponding to the time zone ID.|
S
shawn_he 已提交
1483

S
shawn_he 已提交
1484
**Example**
S
shawn_he 已提交
1485 1486 1487 1488 1489
  ```
  var timezone = i18n.getTimeZone();
  ```


S
shawn_he 已提交
1490
## TimeZone<sup>8+</sup>
S
shawn_he 已提交
1491 1492 1493 1494 1495 1496 1497 1498 1499 1500


### getID<sup>8+</sup>

getID(): string

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

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

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

S
shawn_he 已提交
1506
**Example**
S
shawn_he 已提交
1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520
  ```
  var timezone = i18n.getTimeZone();
  timezone.getID();
  ```


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

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 已提交
1521 1522 1523 1524 1525
**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 已提交
1526

S
shawn_he 已提交
1527
**Return value**
S
shawn_he 已提交
1528 1529 1530
| Type    | Description           |
| ------ | ------------- |
| string | Representation of the **TimeZone** object in the specified locale.|
S
shawn_he 已提交
1531

S
shawn_he 已提交
1532
**Example**
S
shawn_he 已提交
1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546
  ```
  var timezone = i18n.getTimeZone();
  timezone.getDisplayName("zh-CN", false);
  ```


### getRawOffset<sup>8+</sup>

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 已提交
1547
**Return value**
S
shawn_he 已提交
1548 1549 1550
| Type    | Description                 |
| ------ | ------------------- |
| number | Offset between the time zone represented by the **TimeZone** object and the UTC time zone.|
S
shawn_he 已提交
1551

S
shawn_he 已提交
1552
**Example**
S
shawn_he 已提交
1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566
  ```
  var timezone = i18n.getTimeZone();
  timezone.getRawOffset();
  ```


### getOffset<sup>8+</sup>

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 已提交
1567
**Return value**
S
shawn_he 已提交
1568 1569 1570
| 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 已提交
1571

S
shawn_he 已提交
1572
**Example**
S
shawn_he 已提交
1573 1574 1575 1576
  ```
  var timezone = i18n.getTimeZone();
  timezone.getOffset(1234567890);
  ```
S
shawn_he 已提交
1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708

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

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

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

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

**Return value**
| Type    | Description                      |
| ------ | ----------------------- |
| Array&lt;string&gt; | List of time zone IDs supported by the system.|

**Example**
  ```
  var ids = i18n.TimeZone.getAvailableIDs();
  ```


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

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

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

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

**Return value**
| Type    | Description                      |
| ------ | ----------------------- |
| Array&lt;string&gt; | List of time zone city IDs supported by the system.|

**Example**
  ```
  var cityIDs = i18n.TimeZone.getAvailableZoneCityIDs();
  ```


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

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

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

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

**Parameters**
| Name   | Type    | Mandatory  | Description   |
| ------ | ------ | ---- | ----- |
| cityID | string | Yes   | Time zone city ID.|
| locale | string | Yes   | Locale ID.|

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

**Example**
  ```
  var displayName = i18n.TimeZone.getCityDisplayName("Shanghai", "zh-CN");
  ```


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

static getTimezoneFromCity(cityID: string): TimeZone

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

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

**Parameters**
| Name   | Type    | Mandatory  | Description   |
| ------ | ------ | ---- | ----- |
| cityID | string | Yes   | Time zone city ID.|

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

**Example**
  ```
  var timezone = i18n.TimeZone.getTimezoneFromCity("Shanghai");
  ```


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

setUsingLocalDigit(flag: boolean): boolean

Sets whether to turn on the local digit switch.
This is a system API.

**Permission required**: ohos.permission.UPDATE_CONFIGURATION

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

**Parameters**
| Name   | Type    | Mandatory  | Description   |
| ------ | ------ | ---- | ----- |
| flag | boolean | Yes   | Whether to turn on the local digit switch. The value **true** means to turn on the local digit switch, and the value **false** indicates the opposite.|

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

**Example**
  ```
  var status = i18n.setUsingLocalDigit(true);
  ```


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

getUsingLocalDigit(): boolean

Checks whether the local digit switch is turned on.

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

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

**Example**
  ```
  var status = i18n.getUsingLocalDigit();
  ```