• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.i18n (Internationalization)
2
3 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.
4The [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.
5
6>  **NOTE**
7>  - 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.
8>
9>  - 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. For details about the basic I18N capabilities, see [Intl](js-apis-intl.md).
10
11
12## Modules to Import
13
14```js
15import I18n from '@ohos.i18n';
16```
17
18
19## System<sup>9+</sup>
20
21### getDisplayCountry<sup>9+</sup>
22
23static getDisplayCountry(country: string, locale: string, sentenceCase?: boolean): string
24
25Obtains the localized script for the specified country.
26
27**System capability**: SystemCapability.Global.I18n
28
29**Parameters**
30
31| Name         | Type     | Mandatory  | Description              |
32| ------------ | ------- | ---- | ---------------- |
33| country      | string  | Yes   | Specified country.           |
34| locale       | string  | Yes   | Locale ID.    |
35| sentenceCase | boolean | No   | Whether to use sentence case for the localized script.|
36
37**Return value**
38
39| Type    | Description           |
40| ------ | ------------- |
41| string | Localized script for the specified country.|
42
43**Error codes**
44
45For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
46
47| ID | Error Message                  |
48| ------ | ---------------------- |
49| 890001 | Unspported para value. |
50
51**Example**
52  ```js
53  try {
54    let displayCountry = I18n.System.getDisplayCountry("zh-CN", "en-GB"); // displayCountry = "China"
55  } catch(error) {
56    console.error(`call System.getDisplayCountry failed, error code: ${error.code}, message: ${error.message}.`);
57  }
58  ```
59
60### getDisplayLanguage<sup>9+</sup>
61
62static getDisplayLanguage(language: string, locale: string, sentenceCase?: boolean): string
63
64Obtains the localized script for the specified language.
65
66**System capability**: SystemCapability.Global.I18n
67
68**Parameters**
69
70| Name         | Type     | Mandatory  | Description              |
71| ------------ | ------- | ---- | ---------------- |
72| language     | string  | Yes   | Specified language.           |
73| locale       | string  | Yes   | Locale ID.    |
74| sentenceCase | boolean | No   | Whether to use sentence case for the localized script.|
75
76**Return value**
77
78| Type    | Description           |
79| ------ | ------------- |
80| string | Localized script for the specified language.|
81
82**Error codes**
83
84For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
85
86| ID | Error Message                  |
87| ------ | ---------------------- |
88| 890001 | Unspported para value. |
89
90**Example**
91  ```js
92  try {
93    let displayLanguage = I18n.System.getDisplayLanguage("zh", "en-GB"); // displayLanguage = Chinese
94  } catch(error) {
95    console.error(`call System.getDisplayLanguage failed, error code: ${error.code}, message: ${error.message}.`);
96  }
97  ```
98
99### getSystemLanguages<sup>9+</sup>
100
101static getSystemLanguages(): Array&lt;string&gt;
102
103Obtains the list of system languages. For details about languages, see [Instantiating the Locale Object](../../internationalization/intl-guidelines.md#how-to-develop).
104
105**System capability**: SystemCapability.Global.I18n
106
107**Return value**
108
109| Type                 | Description          |
110| ------------------- | ------------ |
111| Array&lt;string&gt; | List of the IDs of system languages.|
112
113**Error codes**
114
115For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
116
117| ID | Error Message                  |
118| ------ | ---------------------- |
119| 890001 | Unspported para value. |
120
121**Example**
122  ```js
123  try {
124    let systemLanguages = I18n.System.getSystemLanguages(); // [ "en-Latn-US", "zh-Hans" ]
125  } catch(error) {
126    console.error(`call System.getSystemLanguages failed, error code: ${error.code}, message: ${error.message}.`);
127  }
128  ```
129
130### getSystemCountries<sup>9+</sup>
131
132static getSystemCountries(language: string): Array&lt;string&gt;
133
134Obtains the list of countries and regions supported for the specified language. For details about countries or regions, see [Instantiating the Locale Object](../../internationalization/intl-guidelines.md#how-to-develop).
135
136**System capability**: SystemCapability.Global.I18n
137
138**Parameters**
139
140| Name     | Type    | Mandatory  | Description   |
141| -------- | ------ | ---- | ----- |
142| language | string | Yes   | Language ID.|
143
144**Return value**
145
146| Type                 | Description          |
147| ------------------- | ------------ |
148| Array&lt;string&gt; | List of the IDs of the countries and regions supported for the specified language.|
149
150**Error codes**
151
152For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
153
154| ID | Error Message                  |
155| ------ | ---------------------- |
156| 890001 | Unspported para value. |
157
158**Example**
159  ```js
160  try {
161    let systemCountries = I18n.System.getSystemCountries('zh'); // systemCountries = [ "ZW", "YT", "YE", ..., "ER", "CN", "DE" ], 240 countries or regions in total
162  } catch(error) {
163    console.error(`call System.getSystemCountries failed, error code: ${error.code}, message: ${error.message}.`);
164  }
165  ```
166
167### isSuggested<sup>9+</sup>
168
169static isSuggested(language: string, region?: string): boolean
170
171Checks whether the system language matches the specified region.
172
173**System capability**: SystemCapability.Global.I18n
174
175**Parameters**
176
177| Name     | Type    | Mandatory  | Description           |
178| -------- | ------ | ---- | ------------- |
179| language | string | Yes   | Valid language ID, for example, **zh**.|
180| region   | string | No   | Valid region ID, for example, **CN**. |
181
182**Return value**
183
184| Type     | Description                                      |
185| ------- | ---------------------------------------- |
186| boolean | Returns **true** if the system language matches the specified region; returns **false** otherwise.|
187
188**Error codes**
189
190For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
191
192| ID | Error Message                  |
193| ------ | ---------------------- |
194| 890001 | Unspported para value. |
195
196**Example**
197  ```js
198  try {
199    let res = I18n.System.isSuggested('zh', 'CN');  // res = true
200  } catch(error) {
201    console.error(`call System.isSuggested failed, error code: ${error.code}, message: ${error.message}.`);
202  }
203  ```
204
205### getSystemLanguage<sup>9+</sup>
206
207static getSystemLanguage(): string
208
209Obtains the system language. For details about languages, see [Instantiating the Locale Object](../../internationalization/intl-guidelines.md#how-to-develop).
210
211**System capability**: SystemCapability.Global.I18n
212
213**Return value**
214
215| Type    | Description     |
216| ------ | ------- |
217| string | System language ID.|
218
219**Error codes**
220
221For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
222
223| ID | Error Message                  |
224| ------ | ---------------------- |
225| 890001 | Unspported para value. |
226
227**Example**
228  ```js
229  try {
230    let systemLanguage = I18n.System.getSystemLanguage(); // systemLanguage indicates the current system language.
231  } catch(error) {
232    console.error(`call System.getSystemLanguage failed, error code: ${error.code}, message: ${error.message}.`);
233  }
234  ```
235
236### setSystemLanguage<sup>9+</sup>
237
238static setSystemLanguage(language: string): void
239
240Sets the system language. Currently, this API does not support real-time updating of the system language.
241
242This is a system API.
243
244**Permission required**: ohos.permission.UPDATE_CONFIGURATION
245
246**System capability**: SystemCapability.Global.I18n
247
248**Parameters**
249
250| Name     | Type    | Mandatory  | Description   |
251| -------- | ------ | ---- | ----- |
252| language | string | Yes   | Language ID.|
253
254**Error codes**
255
256For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
257
258| ID | Error Message                  |
259| ------ | ---------------------- |
260| 890001 | Unspported para value. |
261
262**Example**
263  ```js
264  try {
265    I18n.System.setSystemLanguage('zh'); // Set the current system language to zh.
266  } catch(error) {
267    console.error(`call System.setSystemLanguage failed, error code: ${error.code}, message: ${error.message}.`);
268  }
269  ```
270
271### getSystemRegion<sup>9+</sup>
272
273static getSystemRegion(): string
274
275Obtains the system region. For details about system regions, see [Instantiating the Locale Object](../../internationalization/intl-guidelines.md#how-to-develop).
276
277**System capability**: SystemCapability.Global.I18n
278
279**Return value**
280
281| Type    | Description     |
282| ------ | ------- |
283| string | System region ID.|
284
285**Error codes**
286
287For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
288
289| ID | Error Message                  |
290| ------ | ---------------------- |
291| 890001 | Unspported para value. |
292
293**Example**
294  ```js
295  try {
296    let systemRegion = I18n.System.getSystemRegion(); // Obtain the current system region.
297  } catch(error) {
298    console.error(`call System.getSystemRegion failed, error code: ${error.code}, message: ${error.message}.`);
299  }
300  ```
301
302### setSystemRegion<sup>9+</sup>
303
304static setSystemRegion(region: string): void
305
306Sets the system region.
307
308This is a system API.
309
310**Permission required**: ohos.permission.UPDATE_CONFIGURATION
311
312**System capability**: SystemCapability.Global.I18n
313
314**Parameters**
315
316| Name   | Type    | Mandatory  | Description   |
317| ------ | ------ | ---- | ----- |
318| region | string | Yes   | Region ID.|
319
320**Error codes**
321
322For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
323
324| ID | Error Message                  |
325| ------ | ---------------------- |
326| 890001 | Unspported para value. |
327
328**Example**
329  ```js
330  try {
331    I18n.System.setSystemRegion('CN'); // Set the current system region to CN.
332  } catch(error) {
333    console.error(`call System.setSystemRegion failed, error code: ${error.code}, message: ${error.message}.`);
334  }
335  ```
336
337### getSystemLocale<sup>9+</sup>
338
339static getSystemLocale(): string
340
341Obtains the system locale. For details about system locales, see [Instantiating the Locale Object](../../internationalization/intl-guidelines.md#how-to-develop).
342
343**System capability**: SystemCapability.Global.I18n
344
345**Return value**
346
347| Type    | Description     |
348| ------ | ------- |
349| string | System locale ID.|
350
351**Error codes**
352
353For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
354
355| ID | Error Message                  |
356| ------ | ---------------------- |
357| 890001 | Unspported para value. |
358
359**Example**
360  ```js
361  try {
362    let systemLocale = I18n.System.getSystemLocale(); // Obtain the current system locale.
363  } catch(error) {
364    console.error(`call System.getSystemLocale failed, error code: ${error.code}, message: ${error.message}.`);
365  }
366  ```
367
368### setSystemLocale<sup>9+</sup>
369
370static setSystemLocale(locale: string): void
371
372Sets the system locale.
373
374This is a system API.
375
376**Permission required**: ohos.permission.UPDATE_CONFIGURATION
377
378**System capability**: SystemCapability.Global.I18n
379
380**Parameters**
381
382| Name   | Type    | Mandatory  | Description             |
383| ------ | ------ | ---- | --------------- |
384| locale | string | Yes   | System locale ID, for example, **zh-CN**.|
385
386**Error codes**
387
388For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
389
390| ID | Error Message                  |
391| ------ | ---------------------- |
392| 890001 | Unspported para value. |
393
394**Example**
395  ```js
396  try {
397    I18n.System.setSystemLocale('zh-CN'); // Set the current system locale to zh-CN.
398  } catch(error) {
399    console.error(`call System.setSystemLocale failed, error code: ${error.code}, message: ${error.message}.`);
400  }
401  ```
402
403### is24HourClock<sup>9+</sup>
404
405static is24HourClock(): boolean
406
407Checks whether the 24-hour clock is used.
408
409**System capability**: SystemCapability.Global.I18n
410
411**Return value**
412
413| Type     | Description                                      |
414| ------- | ---------------------------------------- |
415| boolean | Returns **true** if the 24-hour clock is used; returns **false** otherwise.|
416
417**Error codes**
418
419For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
420
421| ID | Error Message                  |
422| ------ | ---------------------- |
423| 890001 | Unspported para value. |
424
425**Example**
426  ```js
427  try {
428    let is24HourClock = I18n.System.is24HourClock(); // Check whether the 24-hour clock is enabled.
429  } catch(error) {
430    console.error(`call System.is24HourClock failed, error code: ${error.code}, message: ${error.message}.`);
431  }
432  ```
433
434### set24HourClock<sup>9+</sup>
435
436static set24HourClock(option: boolean): void
437
438Sets the 24-hour clock.
439
440This is a system API.
441
442**Permission required**: ohos.permission.UPDATE_CONFIGURATION
443
444**System capability**: SystemCapability.Global.I18n
445
446**Parameters**
447
448| Name   | Type     | Mandatory  | Description                                      |
449| ------ | ------- | ---- | ---------------------------------------- |
450| 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.|
451
452**Error codes**
453
454For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
455
456| ID | Error Message                  |
457| ------ | ---------------------- |
458| 890001 | Unspported para value. |
459
460**Example**
461  ```js
462  // Set the system time to the 24-hour clock.
463  try {
464    I18n.System.set24HourClock(true);
465  } catch(error) {
466    console.error(`call System.set24HourClock failed, error code: ${error.code}, message: ${error.message}.`);
467  }
468  ```
469
470### addPreferredLanguage<sup>9+</sup>
471
472static addPreferredLanguage(language: string, index?: number): void
473
474Adds a preferred language to the specified position on the preferred language list.
475
476This is a system API.
477
478**Permission required**: ohos.permission.UPDATE_CONFIGURATION
479
480**System capability**: SystemCapability.Global.I18n
481
482**Parameters**
483
484| Name     | Type    | Mandatory  | Description        |
485| -------- | ------ | ---- | ---------- |
486| language | string | Yes   | Preferred language to add. |
487| index    | number | No   | Position to which the preferred language is added.|
488
489**Error codes**
490
491For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
492
493| ID | Error Message                  |
494| ------ | ---------------------- |
495| 890001 | Unspported para value. |
496
497**Example**
498  ```js
499  // Add zh-CN to the preferred language list.
500  let language = 'zh-CN';
501  let index = 0;
502  try {
503    I18n.System.addPreferredLanguage(language, index); // Add zh-CN to the first place in the preferred language list.
504  } catch(error) {
505    console.error(`call System.addPreferredLanguage failed, error code: ${error.code}, message: ${error.message}.`);
506  }
507  ```
508
509### removePreferredLanguage<sup>9+</sup>
510
511static removePreferredLanguage(index: number): void
512
513Deletes a preferred language from the specified position on the preferred language list.
514
515This is a system API.
516
517**Permission required**: ohos.permission.UPDATE_CONFIGURATION
518
519**System capability**: SystemCapability.Global.I18n
520
521**Parameters**
522
523| Name  | Type    | Mandatory  | Description                   |
524| ----- | ------ | ---- | --------------------- |
525| index | number | Yes   | Position of the preferred language to delete.|
526
527**Error codes**
528
529For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
530
531| ID | Error Message                  |
532| ------ | ---------------------- |
533| 890001 | Unspported para value. |
534
535**Example**
536  ```js
537  // Delete the first preferred language from the preferred language list.
538  let index = 0;
539  try {
540    I18n.System.removePreferredLanguage(index);
541  } catch(error) {
542    console.error(`call System.removePreferredLanguage failed, error code: ${error.code}, message: ${error.message}.`);
543  }
544  ```
545
546### getPreferredLanguageList<sup>9+</sup>
547
548static getPreferredLanguageList(): Array&lt;string&gt;
549
550Obtains the list of preferred languages.
551
552**System capability**: SystemCapability.Global.I18n
553
554**Return value**
555
556| Type                 | Description       |
557| ------------------- | --------- |
558| Array&lt;string&gt; | List of preferred languages.|
559
560**Error codes**
561
562For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
563
564| ID | Error Message                  |
565| ------ | ---------------------- |
566| 890001 | Unspported para value. |
567
568**Example**
569  ```js
570  try {
571    let preferredLanguageList = I18n.System.getPreferredLanguageList(); // Obtain the current preferred language list.
572  } catch(error) {
573    console.error(`call System.getPreferredLanguageList failed, error code: ${error.code}, message: ${error.message}.`);
574  }
575  ```
576
577### getFirstPreferredLanguage<sup>9+</sup>
578
579static getFirstPreferredLanguage(): string
580
581Obtains the first language in the preferred language list.
582
583**System capability**: SystemCapability.Global.I18n
584
585**Return value**
586
587| Type    | Description            |
588| ------ | -------------- |
589| string | First language in the preferred language list.|
590
591**Error codes**
592
593For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
594
595| ID | Error Message                  |
596| ------ | ---------------------- |
597| 890001 | Unspported para value. |
598
599**Example**
600  ```js
601  try {
602    let firstPreferredLanguage = I18n.System.getFirstPreferredLanguage(); // Obtain the first language in the preferred language list.
603  } catch(error) {
604    console.error(`call System.getFirstPreferredLanguage failed, error code: ${error.code}, message: ${error.message}.`);
605  }
606  ```
607
608### getAppPreferredLanguage<sup>9+</sup>
609
610static getAppPreferredLanguage(): string
611
612Obtains the preferred language of an application.
613
614**System capability**: SystemCapability.Global.I18n
615
616**Return value**
617
618| Type    | Description      |
619| ------ | -------- |
620| string | Preferred language of the application.|
621
622**Error codes**
623
624For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
625
626| ID | Error Message                  |
627| ------ | ---------------------- |
628| 890001 | Unspported para value. |
629
630**Example**
631  ```js
632  try {
633    let appPreferredLanguage = I18n.System.getAppPreferredLanguage(); // Obtain the preferred language of an application.
634  } catch(error) {
635    console.error(`call System.getAppPreferredLanguage failed, error code: ${error.code}, message: ${error.message}.`);
636  }
637  ```
638
639### setUsingLocalDigit<sup>9+</sup>
640
641static setUsingLocalDigit(flag: boolean): void
642
643Specifies whether to enable use of local digits.
644
645This is a system API.
646
647**Permission required**: ohos.permission.UPDATE_CONFIGURATION
648
649**System capability**: SystemCapability.Global.I18n
650
651**Parameters**
652
653| Name | Type     | Mandatory  | Description                             |
654| ---- | ------- | ---- | ------------------------------- |
655| 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.|
656
657**Error codes**
658
659For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
660
661| ID | Error Message                  |
662| ------ | ---------------------- |
663| 890001 | Unspported para value. |
664
665**Example**
666  ```ts
667  try {
668    I18n.System.setUsingLocalDigit(true); // Enable the local digit switch.
669  } catch(error) {
670    console.error(`call System.setUsingLocalDigit failed, error code: ${error.code}, message: ${error.message}.`);
671  }
672  ```
673
674### getUsingLocalDigit<sup>9+</sup>
675
676static getUsingLocalDigit(): boolean
677
678Checks whether use of local digits is enabled.
679
680**System capability**: SystemCapability.Global.I18n
681
682**Return value**
683
684| Type     | Description                                      |
685| ------- | ---------------------------------------- |
686| 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.|
687
688**Error codes**
689
690For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
691
692| ID | Error Message                  |
693| ------ | ---------------------- |
694| 890001 | Unspported para value. |
695
696**Example**
697  ```ts
698  try {
699    let status = I18n.System.getUsingLocalDigit(); // Check whether the local digit switch is enabled.
700  } catch(error) {
701    console.error(`call System.getUsingLocalDigit failed, error code: ${error.code}, message: ${error.message}.`);
702  }
703  ```
704
705
706## I18n.isRTL<sup>7+</sup>
707
708isRTL(locale: string): boolean
709
710Checks whether the localized script for the specified language is displayed from right to left.
711
712**System capability**: SystemCapability.Global.I18n
713
714**Parameters**
715
716| Name   | Type    | Mandatory  | Description     |
717| ------ | ------ | ---- | ------- |
718| locale | string | Yes   | Locale ID.|
719
720**Return value**
721
722| Type     | Description                                      |
723| ------- | ---------------------------------------- |
724| boolean | Returns **true** if the localized script is displayed from right to left; returns **false** otherwise.|
725
726**Example**
727  ```js
728  i18n.isRTL("zh-CN");// Since Chinese is not written from right to left, false is returned.
729  i18n.isRTL("ar-EG");// Since Arabic is written from right to left, true is returned.
730  ```
731
732
733## I18n.getCalendar<sup>8+</sup>
734
735getCalendar(locale: string, type? : string): Calendar
736
737Obtains a **Calendar** object.
738
739**System capability**: SystemCapability.Global.I18n
740
741**Parameters**
742
743| Name   | Type    | Mandatory  | Description                                      |
744| ------ | ------ | ---- | ---------------------------------------- |
745| locale | string | Yes   | Valid locale value, for example, **zh-Hans-CN**.                |
746| 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.|
747
748**Return value**
749
750| Type                    | Description   |
751| ---------------------- | ----- |
752| [Calendar](#calendar8) | **Calendar** object.|
753
754**Example**
755  ```js
756  I18n.getCalendar("zh-Hans", "chinese"); // Obtain the Calendar object for the Chinese lunar calendar.
757  ```
758
759
760## Calendar<sup>8+</sup>
761
762
763### setTime<sup>8+</sup>
764
765setTime(date: Date): void
766
767Sets the date for this **Calendar** object.
768
769**System capability**: SystemCapability.Global.I18n
770
771**Parameters**
772
773| Name | Type  | Mandatory  | Description               |
774| ---- | ---- | ---- | ----------------- |
775| date | Date | Yes   | Date to be set for the **Calendar** object.|
776
777**Example**
778  ```js
779  let calendar = I18n.getCalendar("en-US", "gregory");
780  let date = new Date(2021, 10, 7, 8, 0, 0, 0);
781  calendar.setTime(date);
782  ```
783
784
785### setTime<sup>8+</sup>
786
787setTime(time: number): void
788
789Sets 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).
790
791**System capability**: SystemCapability.Global.I18n
792
793**Parameters**
794
795| Name | Type    | Mandatory  | Description                                      |
796| ---- | ------ | ---- | ---------------------------------------- |
797| time | number | Yes   | Number of milliseconds that have elapsed since the Unix epoch.|
798
799**Example**
800  ```js
801  let calendar = I18n.getCalendar("en-US", "gregory");
802  calendar.setTime(10540800000);
803  ```
804
805
806### set<sup>8+</sup>
807
808set(year: number, month: number, date:number, hour?: number, minute?: number, second?: number): void
809
810Sets the year, month, day, hour, minute, and second for this **Calendar** object.
811
812**System capability**: SystemCapability.Global.I18n
813
814**Parameters**
815
816| Name   | Type    | Mandatory  | Description    |
817| ------ | ------ | ---- | ------ |
818| year   | number | Yes   | Year to set. |
819| month  | number | Yes   | Month to set. |
820| date   | number | Yes   | Day to set. |
821| hour   | number | No   | Hour to set.|
822| minute | number | No   | Minute to set.|
823| second | number | No   | Second to set. |
824
825**Example**
826  ```js
827  let calendar = I18n.getCalendar("zh-Hans");
828  calendar.set(2021, 10, 1, 8, 0, 0); // set time to 2021.10.1 08:00:00
829  ```
830
831
832### setTimeZone<sup>8+</sup>
833
834setTimeZone(timezone: string): void
835
836Sets the time zone of this **Calendar** object.
837
838**System capability**: SystemCapability.Global.I18n
839
840**Parameters**
841
842| Name     | Type    | Mandatory  | Description                       |
843| -------- | ------ | ---- | ------------------------- |
844| timezone | string | Yes   | Time zone, for example, **Asia/Shanghai**.|
845
846**Example**
847  ```js
848  let calendar = I18n.getCalendar("zh-Hans");
849  calendar.setTimeZone("Asia/Shanghai");
850  ```
851
852
853### getTimeZone<sup>8+</sup>
854
855getTimeZone(): string
856
857Obtains the time zone of this **Calendar** object.
858
859**System capability**: SystemCapability.Global.I18n
860
861**Return value**
862
863| Type    | Description        |
864| ------ | ---------- |
865| string | Time zone of the **Calendar** object.|
866
867**Example**
868  ```js
869  let calendar = I18n.getCalendar("zh-Hans");
870  calendar.setTimeZone("Asia/Shanghai");
871  let timezone = calendar.getTimeZone(); // timezone = "Asia/Shanghai"
872  ```
873
874
875### getFirstDayOfWeek<sup>8+</sup>
876
877getFirstDayOfWeek(): number
878
879Obtains the start day of a week for this **Calendar** object.
880
881**System capability**: SystemCapability.Global.I18n
882
883**Return value**
884
885| Type    | Description                   |
886| ------ | --------------------- |
887| number | Start day of a week. The value **1** indicates Sunday, and the value **7** indicates Saturday.|
888
889**Example**
890  ```js
891  let calendar = I18n.getCalendar("en-US", "gregory");
892  let firstDayOfWeek = calendar.getFirstDayOfWeek(); // firstDayOfWeek = 1
893  ```
894
895
896### setFirstDayOfWeek<sup>8+</sup>
897
898setFirstDayOfWeek(value: number): void
899
900Sets the start day of a week for this **Calendar** object.
901
902**System capability**: SystemCapability.Global.I18n
903
904**Parameters**
905
906| Name  | Type    | Mandatory  | Description                   |
907| ----- | ------ | ---- | --------------------- |
908| value | number | Yes   | Start day of a week. The value **1** indicates Sunday, and the value **7** indicates Saturday.|
909
910**Example**
911  ```js
912  let calendar = I18n.getCalendar("zh-Hans");
913  calendar.setFirstDayOfWeek(3);
914  let firstDayOfWeek = calendar.getFirstDayOfWeek(); // firstDayOfWeek = 3
915  ```
916
917
918### getMinimalDaysInFirstWeek<sup>8+</sup>
919
920getMinimalDaysInFirstWeek(): number
921
922Obtains the minimum number of days in the first week of a year.
923
924**System capability**: SystemCapability.Global.I18n
925
926**Return value**
927
928| Type    | Description          |
929| ------ | ------------ |
930| number | Minimum number of days in the first week of a year.|
931
932**Example**
933  ```js
934  let calendar = I18n.getCalendar("zh-Hans");
935  let minimalDaysInFirstWeek = calendar.getMinimalDaysInFirstWeek(); // minimalDaysInFirstWeek = 1
936  ```
937
938
939### setMinimalDaysInFirstWeek<sup>8+</sup>
940
941setMinimalDaysInFirstWeek(value: number): void
942
943Sets the minimum number of days in the first week of a year.
944
945**System capability**: SystemCapability.Global.I18n
946
947**Parameters**
948
949| Name  | Type    | Mandatory  | Description          |
950| ----- | ------ | ---- | ------------ |
951| value | number | Yes   | Minimum number of days in the first week of a year.|
952
953**Example**
954  ```js
955  let calendar = I18n.getCalendar("zh-Hans");
956  calendar.setMinimalDaysInFirstWeek(3);
957  let minimalDaysInFirstWeek = calendar.getMinimalDaysInFirstWeek(); // minimalDaysInFirstWeek = 3
958  ```
959
960
961### get<sup>8+</sup>
962
963get(field: string): number
964
965Obtains the value of the specified field in the **Calendar** object.
966
967**System capability**: SystemCapability.Global.I18n
968
969**Parameters**
970
971| Name  | Type    | Mandatory  | Description                                      |
972| ----- | ------ | ---- | ---------------------------------------- |
973| 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**.|
974
975**Return value**
976
977| Type    | Description                                      |
978| ------ | ---------------------------------------- |
979| 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**.|
980
981**Example**
982  ```js
983  let calendar = I18n.getCalendar("zh-Hans");
984  calendar.set(2021, 10, 1, 8, 0, 0); // set time to 2021.10.1 08:00:00
985  let hourOfDay = calendar.get("hour_of_day"); // hourOfDay = 8
986  ```
987
988
989### getDisplayName<sup>8+</sup>
990
991getDisplayName(locale: string): string
992
993Obtains the **Calendar** object name displayed for the specified locale.
994
995**System capability**: SystemCapability.Global.I18n
996
997**Parameters**
998
999| Name   | Type    | Mandatory  | Description                                      |
1000| ------ | ------ | ---- | ---------------------------------------- |
1001| 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**.|
1002
1003**Return value**
1004
1005| Type    | Description                 |
1006| ------ | ------------------- |
1007| string | **Calendar** object name displayed for the specified locale.|
1008
1009**Example**
1010  ```js
1011  let calendar = I18n.getCalendar("en-US", "buddhist");
1012  let calendarName = calendar.getDisplayName("zh"); // calendarName = "Buddhist Calendar"
1013  ```
1014
1015
1016### isWeekend<sup>8+</sup>
1017
1018isWeekend(date?: Date): boolean
1019
1020Checks whether the specified date in this **Calendar** object is a weekend.
1021
1022**System capability**: SystemCapability.Global.I18n
1023
1024**Parameters**
1025
1026| Name | Type  | Mandatory  | Description                                      |
1027| ---- | ---- | ---- | ---------------------------------------- |
1028| date | Date | No   | Specified date in this **Calendar** object. If the **date** parameter is not specified, the system checks whether the current date is a weekend.|
1029
1030**Return value**
1031
1032| Type     | Description                                 |
1033| ------- | ----------------------------------- |
1034| boolean | Returns **true** if the date is a weekend; returns **false** if the date is a weekday.|
1035
1036**Example**
1037  ```js
1038  let calendar = I18n.getCalendar("zh-Hans");
1039  calendar.set(2021, 11, 11, 8, 0, 0); // set time to 2021.11.11 08:00:00
1040  calendar.isWeekend(); // false
1041  let date = new Date(2011, 11, 6, 9, 0, 0);
1042  calendar.isWeekend(date); // true
1043  ```
1044
1045
1046## PhoneNumberFormat<sup>8+</sup>
1047
1048
1049### constructor<sup>8+</sup>
1050
1051constructor(country: string, options?: PhoneNumberFormatOptions)
1052
1053Creates a **PhoneNumberFormat** object.
1054
1055**System capability**: SystemCapability.Global.I18n
1056
1057**Parameters**
1058
1059| Name    | Type                                      | Mandatory  | Description              |
1060| ------- | ---------------------------------------- | ---- | ---------------- |
1061| country | string                                   | Yes   | Country or region to which the phone number to be formatted belongs.|
1062| options | [PhoneNumberFormatOptions](#phonenumberformatoptions9) | No   | Options of the **PhoneNumberFormat** object. |
1063
1064**Example**
1065  ```js
1066  let phoneNumberFormat= new I18n.PhoneNumberFormat("CN", {"type": "E164"});
1067  ```
1068
1069
1070### isValidNumber<sup>8+</sup>
1071
1072isValidNumber(number: string): boolean
1073
1074Checks whether the format of the specified phone number is valid.
1075
1076**System capability**: SystemCapability.Global.I18n
1077
1078**Parameters**
1079
1080| Name   | Type    | Mandatory  | Description       |
1081| ------ | ------ | ---- | --------- |
1082| number | string | Yes   | Phone number to be checked.|
1083
1084**Return value**
1085
1086| Type     | Description                                   |
1087| ------- | ------------------------------------- |
1088| boolean | Returns **true** if the phone number format is valid; returns **false** otherwise.|
1089
1090**Example**
1091  ```js
1092  let phonenumberfmt = new I18n.PhoneNumberFormat("CN");
1093  let isValidNumber = phonenumberfmt.isValidNumber("15812312312"); // isValidNumber = true
1094  ```
1095
1096
1097### format<sup>8+</sup>
1098
1099format(number: string): string
1100
1101Formats a phone number.
1102
1103**System capability**: SystemCapability.Global.I18n
1104
1105**Parameters**
1106
1107| Name   | Type    | Mandatory  | Description        |
1108| ------ | ------ | ---- | ---------- |
1109| number | string | Yes   | Phone number to be formatted.|
1110
1111**Return value**
1112
1113| Type    | Description        |
1114| ------ | ---------- |
1115| string | Formatted phone number.|
1116
1117**Example**
1118  ```js
1119  let phonenumberfmt = new I18n.PhoneNumberFormat("CN");
1120  let formattedPhoneNumber = phonenumberfmt.format("15812312312"); // formattedPhoneNumber = "158 1231 2312"
1121  ```
1122
1123
1124### getLocationName<sup>9+</sup>
1125
1126getLocationName(number: string, locale: string): string
1127
1128Obtains the home location of a phone number.
1129
1130**System capability**: SystemCapability.Global.I18n
1131
1132**Parameters**
1133
1134| Name   | Type    | Mandatory  | Description  |
1135| ------ | ------ | ---- | ---- |
1136| number | string | Yes   | Phone number.|
1137| locale | string | Yes   | Locale ID.|
1138
1139**Return value**
1140
1141| Type    | Description      |
1142| ------ | -------- |
1143| string | Home location of the phone number.|
1144
1145**Example**
1146  ```js
1147  let phonenumberfmt = new I18n.PhoneNumberFormat("CN");
1148  let locationName = phonenumberfmt.getLocationName("15812312345", "zh-CN"); // locationName = "Zhanjiang, Guangdong Province"
1149  ```
1150
1151
1152## PhoneNumberFormatOptions<sup>9+</sup>
1153
1154Defines the options for this PhoneNumberFormat object.
1155
1156**System capability**: SystemCapability.Global.I18n
1157
1158| Name  | Type    | Readable  | Writable  | Description                                      |
1159| ---- | ------ | ---- | ---- | ---------------------------------------- |
1160| type | string | Yes   | Yes   | Format type of a phone number. The available options are as follows: E164,&nbsp;INTERNATIONAL,&nbsp;NATIONAL, and&nbsp;RFC3966.|
1161
1162
1163## UnitInfo<sup>8+</sup>
1164
1165Defines the measurement unit information.
1166
1167**System capability**: SystemCapability.Global.I18n
1168
1169| Name           | Type    | Readable  | Writable  | Description                                      |
1170| ------------- | ------ | ---- | ---- | ---------------------------------------- |
1171| unit          | string | Yes   | Yes   | Name of the measurement unit, for example, **meter**, **inch**, or **cup**.|
1172| measureSystem | string | Yes   | Yes   | Measurement system. The value can be **SI**,&nbsp;**US**, or&nbsp;**UK**.|
1173
1174
1175## getInstance<sup>8+</sup>
1176
1177getInstance(locale?:string): IndexUtil
1178
1179Creates an **IndexUtil** object.
1180
1181**System capability**: SystemCapability.Global.I18n
1182
1183**Parameters**
1184
1185| Name   | Type    | Mandatory  | Description                          |
1186| ------ | ------ | ---- | ---------------------------- |
1187| locale | string | No   | A string containing locale information, including the language, optional script, and region.|
1188
1189**Return value**
1190
1191| Type                      | Description                   |
1192| ------------------------ | --------------------- |
1193| [IndexUtil](#indexutil8) | **IndexUtil** object mapping to the specified locale.|
1194
1195**Example**
1196  ```js
1197  let indexUtil = I18n.getInstance("zh-CN");
1198  ```
1199
1200
1201## IndexUtil<sup>8+</sup>
1202
1203
1204### getIndexList<sup>8+</sup>
1205
1206getIndexList(): Array&lt;string&gt;
1207
1208Obtains the index list for this **locale** object.
1209
1210**System capability**: SystemCapability.Global.I18n
1211
1212**Return value**
1213
1214| Type                 | Description                |
1215| ------------------- | ------------------ |
1216| Array&lt;string&gt; | Index list for this **locale** object.|
1217
1218**Example**
1219  ```js
1220  let indexUtil = I18n.getInstance("zh-CN");
1221  // indexList = [ "...", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N",
1222  //              "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "..." ]
1223  let indexList = indexUtil.getIndexList();
1224  ```
1225
1226
1227### addLocale<sup>8+</sup>
1228
1229addLocale(locale: string): void
1230
1231Adds the index of the new **locale** object to the index list.
1232
1233**System capability**: SystemCapability.Global.I18n
1234
1235**Parameters**
1236
1237| Name   | Type    | Mandatory  | Description                          |
1238| ------ | ------ | ---- | ---------------------------- |
1239| locale | string | Yes   | A string containing locale information, including the language, optional script, and region.|
1240
1241**Example**
1242  ```js
1243  let indexUtil = I18n.getInstance("zh-CN");
1244  indexUtil.addLocale("en-US");
1245  ```
1246
1247
1248### getIndex<sup>8+</sup>
1249
1250getIndex(text: string): string
1251
1252Obtains the index of a text object.
1253
1254**System capability**: SystemCapability.Global.I18n
1255
1256**Parameters**
1257
1258| Name | Type    | Mandatory  | Description          |
1259| ---- | ------ | ---- | ------------ |
1260| text | string | Yes   | **text** object whose index is to be obtained.|
1261
1262**Return value**
1263
1264| Type    | Description         |
1265| ------ | ----------- |
1266| string | Index of the **text** object.|
1267
1268**Example**
1269  ```js
1270  let indexUtil = I18n.getInstance("zh-CN");
1271  let index = indexUtil.getIndex("hi");  // index = "H"
1272  ```
1273
1274
1275## I18n.getLineInstance<sup>8+</sup>
1276
1277getLineInstance(locale: string): BreakIterator
1278
1279Obtains a [BreakIterator](#breakiterator8) object for text segmentation.
1280
1281**System capability**: SystemCapability.Global.I18n
1282
1283**Parameters**
1284
1285| Name   | Type    | Mandatory  | Description                                      |
1286| ------ | ------ | ---- | ---------------------------------------- |
1287| 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.|
1288
1289**Return value**
1290
1291| Type                              | Description         |
1292| -------------------------------- | ----------- |
1293| [BreakIterator](#breakiterator8) | [BreakIterator](#breakiterator8) object used for text segmentation.|
1294
1295**Example**
1296  ```js
1297  let iterator = I18n.getLineInstance("en");
1298  ```
1299
1300
1301## BreakIterator<sup>8+</sup>
1302
1303
1304### setLineBreakText<sup>8+</sup>
1305
1306setLineBreakText(text: string): void
1307
1308Sets the text to be processed by the [BreakIterator](#breakiterator8) object.
1309
1310**System capability**: SystemCapability.Global.I18n
1311
1312**Parameters**
1313
1314| Name | Type    | Mandatory  | Description                     |
1315| ---- | ------ | ---- | ----------------------- |
1316| text | string | Yes   | Text to be processed by the **BreakIterator** object.|
1317
1318**Example**
1319  ```js
1320  let iterator = I18n.getLineInstance("en");
1321  iterator.setLineBreakText("Apple is my favorite fruit ."); // Set a short sentence as the text to be processed by the BreakIterator object.
1322  ```
1323
1324
1325### getLineBreakText<sup>8+</sup>
1326
1327getLineBreakText(): string
1328
1329Obtains the text being processed by the [BreakIterator](#breakiterator8) object.
1330
1331**System capability**: SystemCapability.Global.I18n
1332
1333**Return value**
1334
1335| Type    | Description                    |
1336| ------ | ---------------------- |
1337| string | Text being processed by the **BreakIterator** object.|
1338
1339**Example**
1340  ```js
1341  let iterator = I18n.getLineInstance("en");
1342  iterator.setLineBreakText("Apple is my favorite fruit.");
1343  let breakText = iterator.getLineBreakText(); // breakText = "Apple is my favorite fruit."
1344  ```
1345
1346
1347### current<sup>8+</sup>
1348
1349current(): number
1350
1351Obtains the position of the [BreakIterator](#breakiterator8) object in the text being processed.
1352
1353**System capability**: SystemCapability.Global.I18n
1354
1355**Return value**
1356
1357| Type    | Description                         |
1358| ------ | --------------------------- |
1359| number | Position of the **BreakIterator** object in the text being processed.|
1360
1361**Example**
1362  ```js
1363  let iterator = I18n.getLineInstance("en");
1364  iterator.setLineBreakText("Apple is my favorite fruit.");
1365  let currentPos = iterator.current(); // currentPos = 0
1366  ```
1367
1368
1369### first<sup>8+</sup>
1370
1371first(): number
1372
1373Puts the [BreakIterator](#breakiterator8) object to the first text boundary, which is always at the beginning of the processed text.
1374
1375**System capability**: SystemCapability.Global.I18n
1376
1377**Return value**
1378
1379| Type    | Description               |
1380| ------ | ----------------- |
1381| number | Offset to the first text boundary of the processed text.|
1382
1383**Example**
1384  ```js
1385  let iterator = I18n.getLineInstance("en");
1386  iterator.setLineBreakText("Apple is my favorite fruit.");
1387  let firstPos = iterator.first(); // firstPos = 0
1388  ```
1389
1390
1391### last<sup>8+</sup>
1392
1393last(): number
1394
1395Puts the [BreakIterator](#breakiterator8) object to the last text boundary, which is always the next position after the end of the processed text.
1396
1397**System capability**: SystemCapability.Global.I18n
1398
1399**Return value**
1400
1401| Type    | Description                |
1402| ------ | ------------------ |
1403| number | Offset to the last text boundary of the processed text.|
1404
1405**Example**
1406  ```js
1407  let iterator = I18n.getLineInstance("en");
1408  iterator.setLineBreakText("Apple is my favorite fruit.");
1409  let lastPos = iterator.last(); // lastPos = 27
1410  ```
1411
1412
1413### next<sup>8+</sup>
1414
1415next(index?: number): number
1416
1417Moves 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**.
1418
1419**System capability**: SystemCapability.Global.I18n
1420
1421**Parameters**
1422
1423| Name  | Type    | Mandatory  | Description                                      |
1424| ----- | ------ | ---- | ---------------------------------------- |
1425| 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**.|
1426
1427**Return value**
1428
1429| Type    | Description                                      |
1430| ------ | ---------------------------------------- |
1431| 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.|
1432
1433**Example**
1434  ```js
1435  let iterator = I18n.getLineInstance("en");
1436  iterator.setLineBreakText("Apple is my favorite fruit.");
1437  let pos = iterator.first(); // pos = 0
1438  pos = iterator.next(); // pos = 6
1439  pos = iterator.next(10); // pos = -1
1440  ```
1441
1442
1443### previous<sup>8+</sup>
1444
1445previous(): number
1446
1447Moves the [BreakIterator](#breakiterator8) object to the previous text boundary.
1448
1449**System capability**: SystemCapability.Global.I18n
1450
1451**Return value**
1452
1453| Type    | Description                                      |
1454| ------ | ---------------------------------------- |
1455| 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.|
1456
1457**Example**
1458  ```js
1459  let iterator = I18n.getLineInstance("en");
1460  iterator.setLineBreakText("Apple is my favorite fruit.");
1461  let pos = iterator.first(); // pos = 0
1462  pos = iterator.next(3); // pos = 12
1463  pos = iterator.previous(); // pos = 9
1464  ```
1465
1466
1467### following<sup>8+</sup>
1468
1469following(offset: number): number
1470
1471Moves 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.
1472
1473**System capability**: SystemCapability.Global.I18n
1474
1475**Parameters**
1476
1477| Name   | Type    | Mandatory  | Description                                      |
1478| ------ | ------ | ---- | ---------------------------------------- |
1479| offset | number | Yes   | Offset to the position before the text boundary to which the [BreakIterator](#breakiterator8) object is moved.|
1480
1481**Return value**
1482
1483| Type    | Description                                      |
1484| ------ | ---------------------------------------- |
1485| number | The value **-1** is returned if the text boundary to which the [BreakIterator](#breakiterator8) object is moved is outside of the processed text.|
1486
1487**Example**
1488  ```js
1489  let iterator = I18n.getLineInstance("en");
1490  iterator.setLineBreakText("Apple is my favorite fruit.");
1491  let pos = iterator.following(0); // pos = 6
1492  pos = iterator.following(100); // pos = -1
1493  pos = iterator.current(); // pos = 27
1494  ```
1495
1496
1497### isBoundary<sup>8+</sup>
1498
1499isBoundary(offset: number): boolean
1500
1501Checks 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).
1502
1503**System capability**: SystemCapability.Global.I18n
1504
1505**Parameters**
1506
1507| Name   | Type    | Mandatory  | Description         |
1508| ------ | ------ | ---- | ----------- |
1509| offset | number | Yes   | Position to check.|
1510
1511**Return value**
1512
1513| Type     | Description                             |
1514| ------- | ------------------------------- |
1515| boolean | Returns **true** if the position specified by the offset is a text boundary; returns **false** otherwise.|
1516
1517**Example**
1518  ```js
1519  let iterator = I18n.getLineInstance("en");
1520  iterator.setLineBreakText("Apple is my favorite fruit.");
1521  let isBoundary = iterator.isBoundary(0); // isBoundary = true;
1522  isBoundary = iterator.isBoundary(5); // isBoundary = false;
1523  ```
1524
1525
1526## I18n.getTimeZone<sup>7+</sup>
1527
1528getTimeZone(zoneID?: string): TimeZone
1529
1530Obtains the **TimeZone** object corresponding to the specified time zone ID.
1531
1532**System capability**: SystemCapability.Global.I18n
1533
1534**Parameters**
1535
1536| Name   | Type    | Mandatory  | Description   |
1537| ------ | ------ | ---- | ----- |
1538| zondID | string | No   | Time zone ID.|
1539
1540**Return value**
1541
1542| Type      | Description          |
1543| -------- | ------------ |
1544| TimeZone | **TimeZone** object corresponding to the time zone ID.|
1545
1546**Example**
1547  ```js
1548  let timezone = I18n.getTimeZone();
1549  ```
1550
1551
1552## TimeZone
1553
1554
1555### getID
1556
1557getID(): string
1558
1559Obtains the ID of the specified **TimeZone** object.
1560
1561**System capability**: SystemCapability.Global.I18n
1562
1563**Return value**
1564
1565| Type    | Description          |
1566| ------ | ------------ |
1567| string | Time zone ID corresponding to the **TimeZone** object.|
1568
1569**Example**
1570  ```js
1571  let timezone = I18n.getTimeZone();
1572  let timezoneID = timezone.getID(); // timezoneID = "Asia/Shanghai"
1573  ```
1574
1575
1576### getDisplayName
1577
1578getDisplayName(locale?: string, isDST?: boolean): string
1579
1580Obtains the localized representation of the time zone.
1581
1582**System capability**: SystemCapability.Global.I18n
1583
1584**Parameters**
1585
1586| Name   | Type     | Mandatory  | Description                  |
1587| ------ | ------- | ---- | -------------------- |
1588| locale | string  | No   | Locale ID.               |
1589| isDST  | boolean | No   | Whether to consider DST when obtaining the representation of the **TimeZone** object.|
1590
1591**Return value**
1592
1593| Type    | Description           |
1594| ------ | ------------- |
1595| string | Representation of the **TimeZone** object in the specified locale.|
1596
1597**Example**
1598  ```js
1599  let timezone = I18n.getTimeZone();
1600  let timezoneName = timezone.getDisplayName("zh-CN", false); // timezoneName = "China Standard Time"
1601  ```
1602
1603
1604### getRawOffset
1605
1606getRawOffset(): number
1607
1608Obtains the offset between the time zone represented by a **TimeZone** object and the UTC time zone.
1609
1610**System capability**: SystemCapability.Global.I18n
1611
1612**Return value**
1613
1614| Type    | Description                 |
1615| ------ | ------------------- |
1616| number | Offset between the time zone represented by the **TimeZone** object and the UTC time zone.|
1617
1618**Example**
1619  ```js
1620  let timezone = I18n.getTimeZone();
1621  let offset = timezone.getRawOffset(); // offset = 28800000
1622  ```
1623
1624
1625### getOffset
1626
1627getOffset(date?: number): number
1628
1629Obtains the offset between the time zone represented by a **TimeZone** object and the UTC time zone at a certain time point.
1630
1631**System capability**: SystemCapability.Global.I18n
1632
1633**Return value**
1634
1635| Type    | Description                     |
1636| ------ | ----------------------- |
1637| number | Offset between the time zone represented by the **TimeZone** object and the UTC time zone at a certain time point.|
1638
1639**Example**
1640  ```js
1641  let timezone = I18n.getTimeZone();
1642  let offset = timezone.getOffset(1234567890); // offset = 28800000
1643  ```
1644
1645
1646### getAvailableIDs<sup>9+</sup>
1647
1648static getAvailableIDs(): Array&lt;string&gt;
1649
1650Obtains the list of time zone IDs supported by the system.
1651
1652**System capability**: SystemCapability.Global.I18n
1653
1654**Return value**
1655
1656| Type                 | Description         |
1657| ------------------- | ----------- |
1658| Array&lt;string&gt; | List of time zone IDs supported by the system.|
1659
1660**Example**
1661  ```ts
1662  // ids = ["America/Adak", "America/Anchorage", "America/Bogota", "America/Denver", "America/Los_Angeles", "America/Montevideo", "America/Santiago", "America/Sao_Paulo", "Asia/Ashgabat", "Asia/Hovd", "Asia/Jerusalem", "Asia/Magadan", "Asia/Omsk", "Asia/Shanghai", "Asia/Tokyo", "Asia/Yerevan", "Atlantic/Cape_Verde", "Australia/Lord_Howe", "Europe/Dublin", "Europe/London", "Europe/Moscow", "Pacific/Auckland", "Pacific/Easter", "Pacific/Pago-Pago"], 24 time zones supported in total
1663  let ids = I18n.TimeZone.getAvailableIDs();
1664  ```
1665
1666
1667### getAvailableZoneCityIDs<sup>9+</sup>
1668
1669static getAvailableZoneCityIDs(): Array&lt;string&gt;
1670
1671Obtains the list of time zone city IDs supported by the system.
1672
1673**System capability**: SystemCapability.Global.I18n
1674
1675**Return value**
1676
1677| Type                 | Description           |
1678| ------------------- | ------------- |
1679| Array&lt;string&gt; | List of time zone city IDs supported by the system.|
1680
1681**Example**
1682  ```ts
1683  // cityIDs = ["Auckland", "Magadan", "Lord Howe Island", "Tokyo", "Shanghai", "Hovd", "Omsk", "Ashgabat", "Yerevan", "Moscow", "Tel Aviv", "Dublin", "London", "Praia", "Montevideo", "Brasília", "Santiago", "Bogotá", "Easter Island", "Salt Lake City", "Los Angeles", "Anchorage", "Adak", "Pago Pago"], 24 time zone cities supported in total
1684  let cityIDs = I18n.TimeZone.getAvailableZoneCityIDs();
1685  ```
1686
1687
1688### getCityDisplayName<sup>9+</sup>
1689
1690static getCityDisplayName(cityID: string, locale: string): string
1691
1692Obtains the localized display of a time zone city in the specified locale.
1693
1694**System capability**: SystemCapability.Global.I18n
1695
1696**Parameters**
1697
1698| Name   | Type    | Mandatory  | Description    |
1699| ------ | ------ | ---- | ------ |
1700| cityID | string | Yes   | Time zone city ID.|
1701| locale | string | Yes   | Locale ID.  |
1702
1703**Return value**
1704
1705| Type    | Description                |
1706| ------ | ------------------ |
1707| string | Localized display of the time zone city in the specified locale.|
1708
1709**Example**
1710  ```ts
1711  let displayName = I18n.TimeZone.getCityDisplayName("Shanghai", "zh-CN"); // displayName = "Shanghai (China)"
1712  ```
1713
1714
1715### getTimezoneFromCity<sup>9+</sup>
1716
1717static getTimezoneFromCity(cityID: string): TimeZone
1718
1719Obtains the **TimeZone** object corresponding to the specified time zone city ID.
1720
1721**System capability**: SystemCapability.Global.I18n
1722
1723**Parameters**
1724
1725| Name   | Type    | Mandatory  | Description    |
1726| ------ | ------ | ---- | ------ |
1727| cityID | string | Yes   | Time zone city ID.|
1728
1729**Return value**
1730
1731| Type      | Description         |
1732| -------- | ----------- |
1733| TimeZone | **TimeZone** object corresponding to the specified time zone city ID.|
1734
1735**Example**
1736  ```ts
1737  let timezone = I18n.TimeZone.getTimezoneFromCity("Shanghai");
1738  ```
1739
1740
1741## Transliterator<sup>9+</sup>
1742
1743
1744### getAvailableIDs<sup>9+</sup>
1745
1746static getAvailableIDs(): string[]
1747
1748Obtains a list of IDs supported by the **Transliterator** object.
1749
1750**System capability**: SystemCapability.Global.I18n
1751
1752**Return value**
1753
1754| Type      | Description        |
1755| -------- | ---------- |
1756| string[] | List of IDs supported by the **Transliterator** object.|
1757
1758**Example**
1759  ```ts
1760  // ids = ["ASCII-Latin", "Accents-Any", "Amharic-Latin/BGN", ...], 671 IDs supported in total
1761  // Each ID consists of two parts separated by a hyphen (-). The format is source-destination.
1762  let ids = I18n.Transliterator.getAvailableIDs();
1763  ```
1764
1765
1766### getInstance<sup>9+</sup>
1767
1768static getInstance(id: string): Transliterator
1769
1770Creates a **Transliterator** object.
1771
1772**System capability**: SystemCapability.Global.I18n
1773
1774**Parameters**
1775
1776| Name | Type    | Mandatory  | Description      |
1777| ---- | ------ | ---- | -------- |
1778| id   | string | Yes   | ID supported by the **Transliterator** object.|
1779
1780**Return value**
1781
1782| Type                                | Description   |
1783| ---------------------------------- | ----- |
1784| [Transliterator](#transliterator9) | **Transliterator** object.|
1785
1786**Example**
1787  ```ts
1788  let transliterator = I18n.Transliterator.getInstance("Any-Latn");
1789  ```
1790
1791
1792### transform<sup>9+</sup>
1793
1794transform(text: string): string
1795
1796Converts the input string from the source format to the target format.
1797
1798**System capability**: SystemCapability.Global.I18n
1799
1800**Parameters**
1801
1802| Name | Type    | Mandatory  | Description    |
1803| ---- | ------ | ---- | ------ |
1804| text | string | Yes   | Input string.|
1805
1806**Return value**
1807
1808| Type    | Description      |
1809| ------ | -------- |
1810| string | Target string.|
1811
1812**Example**
1813  ```ts
1814  let transliterator = I18n.Transliterator.getInstance("Any-Latn");
1815  let res = transliterator.transform("China"); // res = "zhōng guó"
1816  ```
1817
1818
1819## Unicode<sup>9+</sup>
1820
1821
1822### isDigit<sup>9+</sup>
1823
1824static isDigit(char: string): boolean
1825
1826Checks whether the input character string is composed of digits.
1827
1828**System capability**: SystemCapability.Global.I18n
1829
1830**Parameters**
1831
1832| Name | Type    | Mandatory  | Description   |
1833| ---- | ------ | ---- | ----- |
1834| char | string | Yes   | Input character.|
1835
1836**Return value**
1837
1838| Type     | Description                                  |
1839| ------- | ------------------------------------ |
1840| boolean | Returns **true** if the input character is a digit; returns **false** otherwise.|
1841
1842**Example**
1843  ```js
1844  let isdigit = I18n.Unicode.isDigit("1");  // isdigit = true
1845  ```
1846
1847
1848### isSpaceChar<sup>9+</sup>
1849
1850static isSpaceChar(char: string): boolean
1851
1852Checks whether the input character is a space.
1853
1854**System capability**: SystemCapability.Global.I18n
1855
1856**Parameters**
1857
1858| Name | Type    | Mandatory  | Description   |
1859| ---- | ------ | ---- | ----- |
1860| char | string | Yes   | Input character.|
1861
1862**Return value**
1863
1864| Type     | Description                                    |
1865| ------- | -------------------------------------- |
1866| boolean | Returns **true** if the input character is a space; returns **false** otherwise.|
1867
1868**Example**
1869  ```js
1870  let isspacechar = I18n.Unicode.isSpaceChar("a");  // isspacechar = false
1871  ```
1872
1873
1874### isWhitespace<sup>9+</sup>
1875
1876static isWhitespace(char: string): boolean
1877
1878Checks whether the input character is a white space.
1879
1880**System capability**: SystemCapability.Global.I18n
1881
1882**Parameters**
1883
1884| Name | Type    | Mandatory  | Description   |
1885| ---- | ------ | ---- | ----- |
1886| char | string | Yes   | Input character.|
1887
1888**Return value**
1889
1890| Type     | Description                                    |
1891| ------- | -------------------------------------- |
1892| boolean | Returns **true** if the input character is a white space; returns **false** otherwise.|
1893
1894**Example**
1895  ```js
1896  let iswhitespace = I18n.Unicode.isWhitespace("a");  // iswhitespace = false
1897  ```
1898
1899
1900### isRTL<sup>9+</sup>
1901
1902static isRTL(char: string): boolean
1903
1904Checks whether the input character is of the right to left (RTL) language.
1905
1906**System capability**: SystemCapability.Global.I18n
1907
1908**Parameters**
1909
1910| Name | Type    | Mandatory  | Description   |
1911| ---- | ------ | ---- | ----- |
1912| char | string | Yes   | Input character.|
1913
1914**Return value**
1915
1916| Type     | Description                                      |
1917| ------- | ---------------------------------------- |
1918| boolean | Returns **true** if the input character is of the RTL language; returns **false** otherwise.|
1919
1920**Example**
1921  ```js
1922  let isrtl = I18n.Unicode.isRTL("a");  // isrtl = false
1923  ```
1924
1925
1926### isIdeograph<sup>9+</sup>
1927
1928static isIdeograph(char: string): boolean
1929
1930Checks whether the input character is an ideographic character.
1931
1932**System capability**: SystemCapability.Global.I18n
1933
1934**Parameters**
1935
1936| Name | Type    | Mandatory  | Description   |
1937| ---- | ------ | ---- | ----- |
1938| char | string | Yes   | Input character.|
1939
1940**Return value**
1941
1942| Type     | Description                                      |
1943| ------- | ---------------------------------------- |
1944| boolean | Returns **true** if the input character is an ideographic character; returns **false** otherwise.|
1945
1946**Example**
1947  ```js
1948  let isideograph = I18n.Unicode.isIdeograph("a");  // isideograph = false
1949  ```
1950
1951
1952### isLetter<sup>9+</sup>
1953
1954static isLetter(char: string): boolean
1955
1956Checks whether the input character is a letter.
1957
1958**System capability**: SystemCapability.Global.I18n
1959
1960**Parameters**
1961
1962| Name | Type    | Mandatory  | Description   |
1963| ---- | ------ | ---- | ----- |
1964| char | string | Yes   | Input character.|
1965
1966**Return value**
1967
1968| Type     | Description                                  |
1969| ------- | ------------------------------------ |
1970| boolean | Returns **true** if the input character is a letter; returns **false** otherwise.|
1971
1972**Example**
1973  ```js
1974  let isletter = I18n.Unicode.isLetter("a");  // isletter = true
1975  ```
1976
1977
1978### isLowerCase<sup>9+</sup>
1979
1980static isLowerCase(char: string): boolean
1981
1982Checks whether the input character is a lowercase letter.
1983
1984**System capability**: SystemCapability.Global.I18n
1985
1986**Parameters**
1987
1988| Name | Type    | Mandatory  | Description   |
1989| ---- | ------ | ---- | ----- |
1990| char | string | Yes   | Input character.|
1991
1992**Return value**
1993
1994| Type     | Description                                      |
1995| ------- | ---------------------------------------- |
1996| boolean | Returns **true** if the input character is a lowercase letter; returns **false** otherwise.|
1997
1998**Example**
1999  ```js
2000  let islowercase = I18n.Unicode.isLowerCase("a");  // islowercase = true
2001  ```
2002
2003
2004### isUpperCase<sup>9+</sup>
2005
2006static isUpperCase(char: string): boolean
2007
2008Checks whether the input character is an uppercase letter.
2009
2010**System capability**: SystemCapability.Global.I18n
2011
2012**Parameters**
2013
2014| Name | Type    | Mandatory  | Description   |
2015| ---- | ------ | ---- | ----- |
2016| char | string | Yes   | Input character.|
2017
2018**Return value**
2019
2020| Type     | Description                                      |
2021| ------- | ---------------------------------------- |
2022| boolean | Returns **true** if the input character is an uppercase letter; returns **false** otherwise.|
2023
2024**Example**
2025  ```js
2026  let isuppercase = I18n.Unicode.isUpperCase("a");  // isuppercase = false
2027  ```
2028
2029
2030### getType<sup>9+</sup>
2031
2032static getType(char: string): string
2033
2034Obtains the type of the input character string.
2035
2036**System capability**: SystemCapability.Global.I18n
2037
2038**Parameters**
2039
2040| Name | Type    | Mandatory  | Description   |
2041| ---- | ------ | ---- | ----- |
2042| char | string | Yes   | Input character.|
2043
2044**Return value**
2045
2046| Type    | Description         |
2047| ------ | ----------- |
2048| string | Type of the input character.|
2049
2050**Example**
2051  ```js
2052  let type = I18n.Unicode.getType("a"); // type = "U_LOWERCASE_LETTER"
2053  ```
2054
2055
2056## I18NUtil<sup>9+</sup>
2057
2058
2059### unitConvert<sup>9+</sup>
2060
2061static unitConvert(fromUnit: UnitInfo, toUnit: UnitInfo, value: number, locale: string, style?: string): string
2062
2063Converts one measurement unit into another and formats the unit based on the specified locale and style.
2064
2065**System capability**: SystemCapability.Global.I18n
2066
2067**Parameters**
2068
2069| Name     | Type                    | Mandatory  | Description                                      |
2070| -------- | ---------------------- | ---- | ---------------------------------------- |
2071| fromUnit | [UnitInfo](#unitinfo8) | Yes   | Measurement unit to be converted.                                |
2072| toUnit   | [UnitInfo](#unitinfo8) | Yes   | Measurement unit to be converted to.                                |
2073| value    | number                 | Yes   | Value of the measurement unit to be converted.                            |
2074| locale   | string                 | Yes   | Locale used for formatting, for example, **zh-Hans-CN**.               |
2075| style    | string                 | No   | Style used for formatting. The value can be **long**, **short**, or **narrow**.|
2076
2077**Return value**
2078
2079| Type    | Description                     |
2080| ------ | ----------------------- |
2081| string | Character string obtained after formatting based on the measurement unit specified by **toUnit**.|
2082
2083**Example**
2084  ```js
2085  let res = I18n.I18NUtil.unitConvert({unit: "cup", measureSystem: "US"}, {unit: "liter", measureSystem: "SI"}, 1000, "en-US", "long"); // res = 236.588 liters
2086  ```
2087
2088
2089### getDateOrder<sup>9+</sup>
2090
2091static getDateOrder(locale: string): string
2092
2093Obtains the sequence of the year, month, and day in the specified locale.
2094
2095**System capability**: SystemCapability.Global.I18n
2096
2097**Parameters**
2098
2099| Name   | Type    | Mandatory  | Description                       |
2100| ------ | ------ | ---- | ------------------------- |
2101| locale | string | Yes   | Locale used for formatting, for example, **zh-Hans-CN**.|
2102
2103**Return value**
2104
2105| Type    | Description                 |
2106| ------ | ------------------- |
2107| string | Sequence of the year, month, and day.|
2108
2109**Example**
2110  ```js
2111  let order = I18n.I18NUtil.getDateOrder("zh-CN");  // order = "y-L-d"
2112  ```
2113
2114
2115## I18n.getDisplayCountry<sup>(deprecated)</sup>
2116
2117getDisplayCountry(country: string, locale: string, sentenceCase?: boolean): string
2118
2119Obtains the localized script for the specified country.
2120
2121This API is deprecated since API version 9. You are advised to use [System.getDisplayCountry](#getdisplaycountry9) instead.
2122
2123**System capability**: SystemCapability.Global.I18n
2124
2125**Parameters**
2126
2127| Name         | Type     | Mandatory  | Description              |
2128| ------------ | ------- | ---- | ---------------- |
2129| country      | string  | Yes   | Specified country.           |
2130| locale       | string  | Yes   | Locale ID.    |
2131| sentenceCase | boolean | No   | Whether to use sentence case for the localized script.|
2132
2133**Return value**
2134
2135| Type    | Description           |
2136| ------ | ------------- |
2137| string | Localized script for the specified country.|
2138
2139**Example**
2140  ```js
2141  let countryName = I18n.getDisplayCountry("zh-CN", "en-GB", true); // countryName = true
2142  countryName = I18n.getDisplayCountry("zh-CN", "en-GB"); // countryName = true
2143  ```
2144
2145
2146## I18n.getDisplayLanguage<sup>(deprecated)</sup>
2147
2148getDisplayLanguage(language: string, locale: string, sentenceCase?: boolean): string
2149
2150Obtains the localized script for the specified language.
2151
2152This API is deprecated since API version 9. You are advised to use [System.getDisplayLanguage](#getdisplaylanguage9) instead.
2153
2154**System capability**: SystemCapability.Global.I18n
2155
2156**Parameters**
2157
2158| Name         | Type     | Mandatory  | Description              |
2159| ------------ | ------- | ---- | ---------------- |
2160| language     | string  | Yes   | Specified language.           |
2161| locale       | string  | Yes   | Locale ID.    |
2162| sentenceCase | boolean | No   | Whether to use sentence case for the localized script.|
2163
2164**Return value**
2165
2166| Type    | Description           |
2167| ------ | ------------- |
2168| string | Localized script for the specified language.|
2169
2170**Example**
2171  ```js
2172  let languageName = I18n.getDisplayLanguage("zh", "en-GB", true); // languageName = "Chinese"
2173  languageName = I18n.getDisplayLanguage("zh", "en-GB"); // languageName = "Chinese"
2174  ```
2175
2176
2177## I18n.getSystemLanguage<sup>(deprecated)</sup>
2178
2179getSystemLanguage(): string
2180
2181Obtains the system language.
2182
2183This API is deprecated since API version 9. You are advised to use [System.getSystemLanguage](#getsystemlanguage9) instead.
2184
2185**System capability**: SystemCapability.Global.I18n
2186
2187**Return value**
2188
2189| Type    | Description     |
2190| ------ | ------- |
2191| string | System language ID.|
2192
2193**Example**
2194  ```js
2195  let systemLanguage = I18n.getSystemLanguage(); // Obtain the current system language.
2196  ```
2197
2198
2199## I18n.getSystemRegion<sup>(deprecated)</sup>
2200
2201getSystemRegion(): string
2202
2203Obtains the system region.
2204
2205This API is deprecated since API version 9. You are advised to use [System.getSystemRegion](#getsystemregion9) instead.
2206
2207**System capability**: SystemCapability.Global.I18n
2208
2209**Return value**
2210
2211| Type    | Description     |
2212| ------ | ------- |
2213| string | System region ID.|
2214
2215**Example**
2216  ```js
2217  let region = I18n.getSystemRegion(); // Obtain the current system region.
2218  ```
2219
2220
2221## I18n.getSystemLocale<sup>(deprecated)</sup>
2222
2223getSystemLocale(): string
2224
2225Obtains the system locale.
2226
2227This API is deprecated since API version 9. You are advised to use [System.getSystemLocale](#getsystemlocale9) instead.
2228
2229**System capability**: SystemCapability.Global.I18n
2230
2231**Return value**
2232
2233| Type    | Description     |
2234| ------ | ------- |
2235| string | System locale ID.|
2236
2237**Example**
2238  ```js
2239  let locale = I18n.getSystemLocale (); // Obtain the system locale.
2240  ```
2241
2242
2243## I18n.is24HourClock<sup>(deprecated)</sup>
2244
2245is24HourClock(): boolean
2246
2247Checks whether the 24-hour clock is used.
2248
2249This API is deprecated since API version 9. You are advised to use [System.is24HourClock](#is24hourclock9) instead.
2250
2251**System capability**: SystemCapability.Global.I18n
2252
2253**Return value**
2254
2255| Type     | Description                                      |
2256| ------- | ---------------------------------------- |
2257| boolean | Returns **true** if the 24-hour clock is used; returns **false** otherwise.|
2258
2259**Example**
2260  ```js
2261  let is24HourClock = I18n.is24HourClock();
2262  ```
2263
2264
2265## I18n.set24HourClock<sup>(deprecated)</sup>
2266
2267set24HourClock(option: boolean): boolean
2268
2269Sets the 24-hour clock.
2270
2271This API is deprecated since API version 9. You are advised to use [System.set24HourClock](#set24hourclock9) instead.
2272
2273**Permission required**: ohos.permission.UPDATE_CONFIGURATION
2274
2275**System capability**: SystemCapability.Global.I18n
2276
2277**Parameters**
2278
2279| Name   | Type     | Mandatory  | Description                                      |
2280| ------ | ------- | ---- | ---------------------------------------- |
2281| 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.|
2282
2283**Return value**
2284
2285| Type     | Description                           |
2286| ------- | ----------------------------- |
2287| boolean | Returns **true** if the 24-hour clock is enabled; returns **false** otherwise.|
2288
2289**Example**
2290  ```js
2291  // Set the system time to the 24-hour clock.
2292  let success = I18n.set24HourClock(true);
2293  ```
2294
2295
2296## I18n.addPreferredLanguage<sup>(deprecated)</sup>
2297
2298addPreferredLanguage(language: string, index?: number): boolean
2299
2300Adds a preferred language to the specified position on the preferred language list.
2301
2302This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [System.addPreferredLanguage](#addpreferredlanguage9) instead.
2303
2304**Permission required**: ohos.permission.UPDATE_CONFIGURATION
2305
2306**System capability**: SystemCapability.Global.I18n
2307
2308**Parameters**
2309
2310| Name     | Type    | Mandatory  | Description        |
2311| -------- | ------ | ---- | ---------- |
2312| language | string | Yes   | Preferred language to add. |
2313| index    | number | No   | Position to which the preferred language is added.|
2314
2315**Return value**
2316
2317| Type     | Description                           |
2318| ------- | ----------------------------- |
2319| boolean | Returns **true** if the preferred language is successfully added; returns **false** otherwise.|
2320
2321**Example**
2322  ```js
2323  // Add zh-CN to the preferred language list.
2324  let language = 'zh-CN';
2325  let index = 0;
2326  let success = I18n.addPreferredLanguage(language, index);
2327  ```
2328
2329
2330## I18n.removePreferredLanguage<sup>(deprecated)</sup>
2331
2332removePreferredLanguage(index: number): boolean
2333
2334Deletes a preferred language from the specified position on the preferred language list.
2335
2336This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [System.removePreferredLanguage](#removepreferredlanguage9) instead.
2337
2338**Permission required**: ohos.permission.UPDATE_CONFIGURATION
2339
2340**System capability**: SystemCapability.Global.I18n
2341
2342**Parameters**
2343
2344| Name  | Type    | Mandatory  | Description                   |
2345| ----- | ------ | ---- | --------------------- |
2346| index | number | Yes   | Position of the preferred language to delete.|
2347
2348**Return value**
2349
2350| Type     | Description                           |
2351| ------- | ----------------------------- |
2352| boolean | Returns **true** if the preferred language is deleted; returns **false** otherwise.|
2353
2354**Example**
2355  ```js
2356  // Delete the first preferred language from the preferred language list.
2357  let index = 0;
2358  let success = I18n.removePreferredLanguage(index);
2359  ```
2360
2361
2362## I18n.getPreferredLanguageList<sup>(deprecated)</sup>
2363
2364getPreferredLanguageList(): Array&lt;string&gt;
2365
2366Obtains the list of preferred languages.
2367
2368This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [System.getPreferredLanguageList](#getpreferredlanguagelist9) instead.
2369
2370**System capability**: SystemCapability.Global.I18n
2371
2372**Return value**
2373
2374| Type                 | Description       |
2375| ------------------- | --------- |
2376| Array&lt;string&gt; | List of preferred languages.|
2377
2378**Example**
2379  ```js
2380  let preferredLanguageList = I18n.getPreferredLanguageList(); // Obtain the preferred language list.
2381  ```
2382
2383
2384## I18n.getFirstPreferredLanguage<sup>(deprecated)</sup>
2385
2386getFirstPreferredLanguage(): string
2387
2388Obtains the first language in the preferred language list.
2389
2390This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [System.getFirstPreferredLanguage](#getfirstpreferredlanguage9) instead.
2391
2392**System capability**: SystemCapability.Global.I18n
2393
2394**Return value**
2395
2396| Type    | Description            |
2397| ------ | -------------- |
2398| string | First language in the preferred language list.|
2399
2400**Example**
2401  ```js
2402  let firstPreferredLanguage = I18n.getFirstPreferredLanguage();
2403  ```
2404
2405
2406## Util<sup>(deprecated)</sup>
2407
2408
2409### unitConvert<sup>(deprecated)</sup>
2410
2411static unitConvert(fromUnit: UnitInfo, toUnit: UnitInfo, value: number, locale: string, style?: string): string
2412
2413Converts one measurement unit into another and formats the unit based on the specified locale and style.
2414
2415This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [unitConvert](#unitconvert9) instead.
2416
2417**System capability**: SystemCapability.Global.I18n
2418
2419**Parameters**
2420
2421| Name     | Type                    | Mandatory  | Description                                      |
2422| -------- | ---------------------- | ---- | ---------------------------------------- |
2423| fromUnit | [UnitInfo](#unitinfo8) | Yes   | Measurement unit to be converted.                                |
2424| toUnit   | [UnitInfo](#unitinfo8) | Yes   | Measurement unit to be converted to.                                |
2425| value    | number                 | Yes   | Value of the measurement unit to be converted.                            |
2426| locale   | string                 | Yes   | Locale used for formatting, for example, **zh-Hans-CN**.               |
2427| style    | string                 | No   | Style used for formatting. The value can be **long**, **short**, or **narrow**.|
2428
2429**Return value**
2430
2431| Type    | Description                     |
2432| ------ | ----------------------- |
2433| string | Character string obtained after formatting based on the measurement unit specified by **toUnit**.|
2434
2435
2436## Character<sup>(deprecated)</sup>
2437
2438
2439### isDigit<sup>(deprecated)</sup>
2440
2441static isDigit(char: string): boolean
2442
2443Checks whether the input character string is composed of digits.
2444
2445This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [isDigit](#isdigit9) instead.
2446
2447**System capability**: SystemCapability.Global.I18n
2448
2449**Parameters**
2450
2451| Name | Type    | Mandatory  | Description   |
2452| ---- | ------ | ---- | ----- |
2453| char | string | Yes   | Input character.|
2454
2455**Return value**
2456
2457| Type     | Description                                  |
2458| ------- | ------------------------------------ |
2459| boolean | Returns **true** if the input character is a digit; returns **false** otherwise.|
2460
2461
2462### isSpaceChar<sup>(deprecated)</sup>
2463
2464static isSpaceChar(char: string): boolean
2465
2466Checks whether the input character is a space.
2467
2468This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [isSpaceChar](#isspacechar9) instead.
2469
2470**System capability**: SystemCapability.Global.I18n
2471
2472**Parameters**
2473
2474| Name | Type    | Mandatory  | Description   |
2475| ---- | ------ | ---- | ----- |
2476| char | string | Yes   | Input character.|
2477
2478**Return value**
2479
2480| Type     | Description                                    |
2481| ------- | -------------------------------------- |
2482| boolean | Returns **true** if the input character is a space; returns **false** otherwise.|
2483
2484
2485### isWhitespace<sup>(deprecated)</sup>
2486
2487static isWhitespace(char: string): boolean
2488
2489Checks whether the input character is a white space.
2490
2491This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [isWhitespace](#iswhitespace9) instead.
2492
2493**System capability**: SystemCapability.Global.I18n
2494
2495**Parameters**
2496
2497| Name | Type    | Mandatory  | Description   |
2498| ---- | ------ | ---- | ----- |
2499| char | string | Yes   | Input character.|
2500
2501**Return value**
2502
2503| Type     | Description                                    |
2504| ------- | -------------------------------------- |
2505| boolean | Returns **true** if the input character is a white space; returns **false** otherwise.|
2506
2507
2508### isRTL<sup>(deprecated)</sup>
2509
2510static isRTL(char: string): boolean
2511
2512Checks whether the input character is of the right to left (RTL) language.
2513
2514This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [isRTL](#isrtl9) instead.
2515
2516**System capability**: SystemCapability.Global.I18n
2517
2518**Parameters**
2519
2520| Name | Type    | Mandatory  | Description   |
2521| ---- | ------ | ---- | ----- |
2522| char | string | Yes   | Input character.|
2523
2524**Return value**
2525
2526| Type     | Description                                      |
2527| ------- | ---------------------------------------- |
2528| boolean | Returns **true** if the input character is of the RTL language; returns **false** otherwise.|
2529
2530
2531### isIdeograph<sup>(deprecated)</sup>
2532
2533static isIdeograph(char: string): boolean
2534
2535Checks whether the input character is an ideographic character.
2536
2537This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [isIdeograph](#isideograph9) instead.
2538
2539**System capability**: SystemCapability.Global.I18n
2540
2541**Parameters**
2542
2543| Name | Type    | Mandatory  | Description   |
2544| ---- | ------ | ---- | ----- |
2545| char | string | Yes   | Input character.|
2546
2547**Return value**
2548
2549| Type     | Description                                      |
2550| ------- | ---------------------------------------- |
2551| boolean | Returns **true** if the input character is an ideographic character; returns **false** otherwise.|
2552
2553
2554### isLetter<sup>(deprecated)</sup>
2555
2556static isLetter(char: string): boolean
2557
2558Checks whether the input character is a letter.
2559
2560This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [isLetter](#isletter9) instead.
2561
2562**System capability**: SystemCapability.Global.I18n
2563
2564**Parameters**
2565
2566| Name | Type    | Mandatory  | Description   |
2567| ---- | ------ | ---- | ----- |
2568| char | string | Yes   | Input character.|
2569
2570**Return value**
2571
2572| Type     | Description                                  |
2573| ------- | ------------------------------------ |
2574| boolean | Returns **true** if the input character is a letter; returns **false** otherwise.|
2575
2576
2577### isLowerCase<sup>(deprecated)</sup>
2578
2579static isLowerCase(char: string): boolean
2580
2581Checks whether the input character is a lowercase letter.
2582
2583This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [isLowerCase](#islowercase9) instead.
2584
2585**System capability**: SystemCapability.Global.I18n
2586
2587**Parameters**
2588
2589| Name | Type    | Mandatory  | Description   |
2590| ---- | ------ | ---- | ----- |
2591| char | string | Yes   | Input character.|
2592
2593**Return value**
2594
2595| Type     | Description                                      |
2596| ------- | ---------------------------------------- |
2597| boolean | Returns **true** if the input character is a lowercase letter; returns **false** otherwise.|
2598
2599
2600### isUpperCase<sup>(deprecated)</sup>
2601
2602static isUpperCase(char: string): boolean
2603
2604Checks whether the input character is an uppercase letter.
2605
2606This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [isUpperCase](#isuppercase9) instead.
2607
2608**System capability**: SystemCapability.Global.I18n
2609
2610**Parameters**
2611
2612| Name | Type    | Mandatory  | Description   |
2613| ---- | ------ | ---- | ----- |
2614| char | string | Yes   | Input character.|
2615
2616**Return value**
2617
2618| Type     | Description                                      |
2619| ------- | ---------------------------------------- |
2620| boolean | Returns **true** if the input character is an uppercase letter; returns **false** otherwise.|
2621
2622
2623### getType<sup>(deprecated)</sup>
2624
2625static getType(char: string): string
2626
2627Obtains the type of the input character string.
2628
2629This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [getType](#gettype9) instead.
2630
2631**System capability**: SystemCapability.Global.I18n
2632
2633**Parameters**
2634
2635| Name | Type    | Mandatory  | Description   |
2636| ---- | ------ | ---- | ----- |
2637| char | string | Yes   | Input character.|
2638
2639**Return value**
2640
2641| Type    | Description         |
2642| ------ | ----------- |
2643| string | Type of the input character.|
2644