• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Internationalization – I18N
2
3This 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.
4
5The [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.
6
7> **NOTE**<br>
8> 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.
9
10
11
12## Modules to Import
13
14```
15import i18n from '@ohos.i18n';
16```
17
18
19## i18n.getDisplayLanguage
20
21getDisplayLanguage(language: string, locale: string, sentenceCase?: boolean): string
22
23Obtains the localized script for the specified language.
24
25**System capability**: SystemCapability.Global.I18n
26
27**Parameters**
28| Name         | Type    | Mandatory | Description                              |
29| ------------ | ------- | --------- | ---------------------------------------- |
30| language     | string  | Yes       | Specified language.                      |
31| locale       | string  | Yes       | Locale ID.                               |
32| sentenceCase | boolean | No        | Whether to use sentence case for the localized script. |
33
34**Return Value**
35| Type   | Description                              |
36| ------ | ---------------------------------------- |
37| string | Localized script for the specified language. |
38
39**Example**
40  ```
41  i18n.getDisplayLanguage("zh", "en-GB", true);
42  i18n.getDisplayLanguage("zh", "en-GB");
43  ```
44
45
46## i18n.getDisplayCountry
47
48getDisplayCountry(country: string, locale: string, sentenceCase?: boolean): string
49
50Obtains the localized script for the specified country.
51
52**System capability**: SystemCapability.Global.I18n
53
54**Parameters**
55| Name         | Type    | Mandatory | Description                              |
56| ------------ | ------- | --------- | ---------------------------------------- |
57| country      | string  | Yes       | Specified country.                       |
58| locale       | string  | Yes       | Locale ID.                               |
59| sentenceCase | boolean | No        | Whether to use sentence case for the localized script. |
60
61**Return Value**
62| Type   | Description                              |
63| ------ | ---------------------------------------- |
64| string | Localized script for the specified country. |
65
66**Example**
67  ```
68  i18n.getDisplayCountry("zh-CN", "en-GB", true);
69  i18n.getDisplayCountry("zh-CN", "en-GB");
70  ```
71
72
73## i18n.isRTL<sup>7+</sup>
74
75isRTL(locale: string): boolean
76
77Checks whether the localized script for the specified language is displayed from right to left.
78
79**System capability**: SystemCapability.Global.I18n
80
81**Parameters**
82| Name   | Type   | Description |
83| ------ | ------ | ----------- |
84| locale | string | Locale ID.  |
85
86**Return Value**
87| Type    | Description                              |
88| ------- | ---------------------------------------- |
89| boolean | Returns **true** if the localized script is displayed from right to left; returns **false** otherwise. |
90
91**Example**
92  ```
93  i18n.isRTL("zh-CN");// Since Chinese is not written from right to left, false is returned.
94  i18n.isRTL("ar-EG");// Since Arabic is written from right to left, true is returned.
95  ```
96
97
98## i18n.getSystemLanguage
99
100getSystemLanguage(): string
101
102Obtains the system language.
103
104**System capability**: SystemCapability.Global.I18n
105
106**Return Value**
107| Type   | Description         |
108| ------ | ------------------- |
109| string | System language ID. |
110
111**Example**
112  ```
113  i18n.getSystemLanguage();
114  ```
115
116
117## i18n.setSystemLanguage
118
119setSystemLanguage(language: string): boolean
120
121Sets the system language. Currently, this API does not support real-time updating of the system language.
122
123**System API**: This is a system API.
124
125**Required permission**: ohos.permission.UPDATE_CONFIGURATION
126
127**System capability**: SystemCapability.Global.I18n
128
129**System API**: This is a system API and cannot be called by third-party applications.
130
131**Parameters**
132| Name     | Type   | Description  |
133| -------- | ------ | ------------ |
134| language | string | Language ID. |
135
136**Return Value**
137| Type    | Description                              |
138| ------- | ---------------------------------------- |
139| boolean | Returns **true** if the operation is successful; returns **false** otherwise. |
140
141**Example**
142  ```
143  i18n.setSystemLanguage('zh');
144  ```
145
146
147## i18n.getSystemLanguages
148
149getSystemLanguages(): Array&lt;string&gt;
150
151Obtains the list of system languages.
152
153**System API**: This is a system API.
154
155**System capability**: SystemCapability.Global.I18n
156
157**Return Value**
158| Type                | Description                          |
159| ------------------- | ------------------------------------ |
160| Array&lt;string&gt; | List of the IDs of system languages. |
161
162**Example**
163  ```
164  i18n.getSystemLanguages();
165  ```
166
167
168## i18n.getSystemCountries
169
170getSystemCountries(language: string): Array&lt;string&gt;
171
172Obtains the list of countries and regions supported for the specified language.
173
174**System API**: This is a system API.
175
176**System capability**: SystemCapability.Global.I18n
177
178**Parameters**
179| Name     | Type   | Description  |
180| -------- | ------ | ------------ |
181| language | string | Language ID. |
182
183**Return Value**
184| Type                | Description                              |
185| ------------------- | ---------------------------------------- |
186| Array&lt;string&gt; | List of the IDs of the countries and regions supported for the specified language. |
187
188**Example**
189  ```
190  i18n.getSystemCountries('zh');
191  ```
192
193
194## i18n.getSystemRegion
195
196getSystemRegion(): string
197
198Obtains the system region.
199
200**System capability**: SystemCapability.Global.I18n
201
202**Return Value**
203| Type   | Description       |
204| ------ | ----------------- |
205| string | System region ID. |
206
207**Example**
208  ```
209  i18n.getSystemRegion();
210  ```
211
212
213## i18n.setSystemRegion
214
215setSystemRegion(region: string): boolean
216
217Sets the system region.
218
219**System API**: This is a system API.
220
221**Required permission**: ohos.permission.UPDATE_CONFIGURATION
222
223**System capability**: SystemCapability.Global.I18n
224
225**Parameters**
226| Name   | Type   | Description |
227| ------ | ------ | ----------- |
228| region | string | Region ID.  |
229
230**Return Value**
231| Type    | Description                              |
232| ------- | ---------------------------------------- |
233| boolean | Returns **true** if the operation is successful; returns **false** otherwise. |
234
235**Example**
236  ```
237  i18n.setSystemRegion('CN');
238  ```
239
240
241## i18n.getSystemLocale
242
243getSystemLocale(): string
244
245Obtains the system locale.
246
247**System capability**: SystemCapability.Global.I18n
248
249**Return Value**
250| Type   | Description       |
251| ------ | ----------------- |
252| string | System locale ID. |
253
254**Example**
255  ```
256  i18n.getSystemLocale();
257  ```
258
259
260## i18n.setSystemLocale
261
262setSystemLocale(locale: string): boolean
263
264Sets the system locale.
265
266**System API**: This is a system API.
267
268**Required permission**: ohos.permission.UPDATE_CONFIGURATION
269
270**System capability**: SystemCapability.Global.I18n
271
272**Parameters**
273| Name   | Type   | Description                              |
274| ------ | ------ | ---------------------------------------- |
275| locale | string | System locale ID, for example, **zh-CN**. |
276
277**Return Value**
278| Type    | Description                              |
279| ------- | ---------------------------------------- |
280| boolean | Returns **true** if the operation is successful; returns **false** otherwise. |
281
282**Example**
283  ```
284  i18n.setSystemLocale('zh-CN');
285  ```
286
287
288## i18n.isSuggested
289
290isSuggested(language: string, region?: string): boolean
291
292Checks whether the system language matches the specified region.
293
294**System API**: This is a system API.
295
296**System capability**: SystemCapability.Global.I18n
297
298**Parameters**
299| Name     | Type   | Mandatory | Description                             |
300| -------- | ------ | --------- | --------------------------------------- |
301| language | string | Yes       | Valid language ID, for example, **zh**. |
302| region   | string | No        | Valid region ID, for example, **CN**.   |
303
304**Return Value**
305| Type    | Description                              |
306| ------- | ---------------------------------------- |
307| boolean | Returns **true** if the system language matches the specified region; returns **false** otherwise. |
308
309**Example**
310  ```
311  i18n.isSuggested('zh', 'CN');
312  ```
313
314
315## i18n.getCalendar<sup>8+</sup>
316
317getCalendar(locale: string, type? : string): Calendar
318
319Obtains a **Calendar** object.
320
321**System capability**: SystemCapability.Global.I18n
322
323**Parameters**
324| Name   | Type   | Mandatory | Description                              |
325| ------ | ------ | --------- | ---------------------------------------- |
326| locale | string | Yes       | Valid locale value, for example, **zh-Hans-CN**. |
327| 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. |
328
329**Return Value**
330| Type                   | Description          |
331| ---------------------- | -------------------- |
332| [Calendar](#calendar8) | **Calendar** object. |
333
334**Example**
335  ```
336  i18n.getCalendar("zh-Hans", "gregory");
337  ```
338
339
340## Calendar<sup>8+</sup>
341
342
343### setTime<sup>8+</sup>
344
345setTime(date: Date): void
346
347Sets the date for this **Calendar** object.
348
349**System capability**: SystemCapability.Global.I18n
350
351**Parameters**
352| Name | Type | Mandatory | Description                              |
353| ---- | ---- | --------- | ---------------------------------------- |
354| date | Date | Yes       | Date to be set for the **Calendar** object. |
355
356**Example**
357  ```
358  var calendar = i18n.getCalendar("en-US", "gregory");
359  var date = new Date(2021, 10, 7, 8, 0, 0, 0);
360  calendar.setTime(date);
361  ```
362
363
364### setTime<sup>8+</sup>
365
366setTime(time: number): void
367
368Sets 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).
369
370**System capability**: SystemCapability.Global.I18n
371
372**Parameters**
373| Name | Type   | Mandatory | Description                              |
374| ---- | ------ | --------- | ---------------------------------------- |
375| time | number | Yes       | Number of milliseconds that have elapsed since the Unix epoch. |
376
377**Example**
378  ```
379  var calendar = I18n.getCalendar("en-US", "gregory");
380  calendar.setTime(10540800000);
381  ```
382
383
384### set<sup>8+</sup>
385
386set(year: number, month: number, date:number, hour?: number, minute?: number, second?: number): void
387
388Sets the year, month, day, hour, minute, and second for this **Calendar** object.
389
390**System capability**: SystemCapability.Global.I18n
391
392**Parameters**
393| Name   | Type   | Mandatory | Description    |
394| ------ | ------ | --------- | -------------- |
395| year   | number | Yes       | Year to set.   |
396| month  | number | Yes       | Month to set.  |
397| date   | number | Yes       | Day to set.    |
398| hour   | number | No        | Hour to set.   |
399| minute | number | No        | Minute to set. |
400| second | number | No        | Second to set. |
401
402**Example**
403  ```
404  var calendar = i18n.getCalendar("zh-Hans");
405  calendar.set(2021, 10, 1, 8, 0, 0); // Set time to 2021.10.1 08:00:00
406  ```
407
408
409### setTimeZone<sup>8+</sup>
410
411setTimeZone(timezone: string): void
412
413Sets the time zone of this **Calendar** object.
414
415**System capability**: SystemCapability.Global.I18n
416
417**Parameters**
418| Name     | Type   | Mandatory | Description                              |
419| -------- | ------ | --------- | ---------------------------------------- |
420| timezone | string | Yes       | Time zone, for example, **Asia/Shanghai**. |
421
422**Example**
423  ```
424  var calendar = i18n.getCalendar("zh-Hans");
425  calendar.setTimeZone("Asia/Shanghai");
426  ```
427
428
429### getTimeZone<sup>8+</sup>
430
431getTimeZone(): string
432
433Obtains the time zone of this **Calendar** object.
434
435**System capability**: SystemCapability.Global.I18n
436
437**Return Value**
438| Type   | Description                           |
439| ------ | ------------------------------------- |
440| string | Time zone of the **Calendar** object. |
441
442**Example**
443  ```
444  var calendar = i18n.getCalendar("zh-Hans");
445  calendar.setTimeZone("Asia/Shanghai");
446  calendar.getTimeZone(); // Asia/Shanghai"
447  ```
448
449
450### getFirstDayOfWeek<sup>8+</sup>
451
452getFirstDayOfWeek(): number
453
454Obtains the start day of a week for this **Calendar** object.
455
456**System capability**: SystemCapability.Global.I18n
457
458**Return Value**
459| Type   | Description                              |
460| ------ | ---------------------------------------- |
461| number | Start day of a week. The value **1** indicates Sunday, and the value **7** indicates Saturday. |
462
463**Example**
464  ```
465  var calendar = i18n.getCalendar("en-US", "gregory");
466  calendar.getFirstDayOfWeek();
467  ```
468
469
470### setFirstDayOfWeek<sup>8+</sup>
471
472setFirstDayOfWeek(value: number): void
473
474Sets the start day of a week for this **Calendar** object.
475
476**System capability**: SystemCapability.Global.I18n
477
478**Parameters**
479| Name  | Type   | Mandatory | Description                              |
480| ----- | ------ | --------- | ---------------------------------------- |
481| value | number | No        | Start day of a week. The value **1** indicates Sunday, and the value **7** indicates Saturday. |
482
483**Example**
484  ```
485  var calendar = i18n.getCalendar("zh-Hans");
486  calendar.setFirstDayOfWeek(0);
487  ```
488
489
490### getMinimalDaysInFirstWeek<sup>8+</sup>
491
492getMinimalDaysInFirstWeek(): number
493
494Obtains the minimum number of days in the first week of a year.
495
496**System capability**: SystemCapability.Global.I18n
497
498**Return Value**
499| Type   | Description                              |
500| ------ | ---------------------------------------- |
501| number | Minimum number of days in the first week of a year. |
502
503**Example**
504  ```
505  var calendar = i18n.getCalendar("zh-Hans");
506  calendar.getMinimalDaysInFirstWeek();
507  ```
508
509
510### setMinimalDaysInFirstWeek<sup>8+</sup>
511
512setMinimalDaysInFirstWeek(value: number): void
513
514Sets the minimum number of days in the first week of a year.
515
516**System capability**: SystemCapability.Global.I18n
517
518**Parameters**
519| Name  | Type   | Mandatory | Description                              |
520| ----- | ------ | --------- | ---------------------------------------- |
521| value | number | No        | Minimum number of days in the first week of a year. |
522
523**Example**
524  ```
525  var calendar = i18n.getCalendar("zh-Hans");
526  calendar.setMinimalDaysInFirstWeek(3);
527  ```
528
529
530### get<sup>8+</sup>
531
532get(field: string): number
533
534Obtains the value of the specified field in the **Calendar** object.
535
536**System capability**: SystemCapability.Global.I18n
537
538**Parameters**
539| Name  | Type   | Mandatory | Description                              |
540| ----- | ------ | --------- | ---------------------------------------- |
541| 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**. |
542
543**Return Value**
544| Type   | Description                              |
545| ------ | ---------------------------------------- |
546| 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**. |
547
548**Example**
549  ```
550  var calendar = i18n.getCalendar("zh-Hans");
551  calendar.set(2021, 10, 1, 8, 0, 0); // Set time to 2021.10.1 08:00:00
552  calendar.get("hour_of_day"); // 8
553  ```
554
555
556### getDisplayName<sup>8+</sup>
557
558getDisplayName(locale: string): string
559
560Obtains the name of the **Calendar** object displayed for the specified locale.
561
562**System capability**: SystemCapability.Global.I18n
563
564**Parameters**
565| Name   | Type   | Mandatory | Description                              |
566| ------ | ------ | --------- | ---------------------------------------- |
567| 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**. |
568
569**Return Value**
570| Type   | Description                              |
571| ------ | ---------------------------------------- |
572| string | Name of the **Calendar** object displayed for the specified locale. |
573
574**Example**
575  ```
576  var calendar = i18n.getCalendar("en-US", "buddhist");
577  calendar.getDisplayName("zh"); // Obtain the name of the Buddhist calendar in zh.
578  ```
579
580
581### isWeekend<sup>8+</sup>
582
583isWeekend(date?: Date): boolean
584
585Checks whether the specified date in this **Calendar** object is a weekend.
586
587**System capability**: SystemCapability.Global.I18n
588
589**Parameters**
590| Name | Type | Mandatory | Description                              |
591| ---- | ---- | --------- | ---------------------------------------- |
592| 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. |
593
594**Return Value**
595| Type    | Description                              |
596| ------- | ---------------------------------------- |
597| boolean | Returns **true** if the date is a weekend; returns **false** if the date is a weekday. |
598
599**Example**
600  ```
601  var calendar = i18n.getCalendar("zh-Hans");
602  calendar.set(2021, 11, 11, 8, 0, 0); // Set time to 2021.11.11 08:00:00
603  calendar.isWeekend(); // false
604  var date = new Date(2011, 11, 6, 9, 0, 0);
605  calendar.isWeekend(date); // true
606  ```
607
608
609## PhoneNumberFormat<sup>8+</sup>
610
611
612### constructor<sup>8+</sup>
613
614constructor(country: string, options?: PhoneNumberFormatOptions)
615
616Creates a **PhoneNumberFormat** object.
617
618**System capability**: SystemCapability.Global.I18n
619
620Parameters
621| Name    | Type                                     | Mandatory | Description                              |
622| ------- | ---------------------------------------- | --------- | ---------------------------------------- |
623| country | string                                   | Yes       | Country or region to which the phone number to be formatted belongs. |
624| options | [PhoneNumberFormatOptions](#phonenumberformatoptions8) | No        | Options of the **PhoneNumberFormat** object. |
625
626**Example**
627  ```
628  var phoneNumberFormat= new i18n.PhoneNumberFormat("CN", {"type": "E164"});
629  ```
630
631
632### isValidNumber<sup>8+</sup>
633
634isValidNumber(number: string): boolean
635
636Checks whether the format of the specified phone number is valid.
637
638**System capability**: SystemCapability.Global.I18n
639
640**Parameters**
641| Name   | Type   | Mandatory | Description                 |
642| ------ | ------ | --------- | --------------------------- |
643| number | string | Yes       | Phone number to be checked. |
644
645**Return Value**
646| Type    | Description                              |
647| ------- | ---------------------------------------- |
648| boolean | Returns **true** if the phone number format is valid; returns **false** otherwise. |
649
650**Example**
651  ```
652  var phonenumberfmt = new i18n.PhoneNumberFormat("CN");
653  phonenumberfmt.isValidNumber("15812312312");
654  ```
655
656
657### format<sup>8+</sup>
658
659format(number: string): string
660
661Formats a phone number.
662
663**System capability**: SystemCapability.Global.I18n
664
665**Parameters**
666| Name   | Type   | Mandatory | Description                   |
667| ------ | ------ | --------- | ----------------------------- |
668| number | string | Yes       | Phone number to be formatted. |
669
670**Return Value**
671| Type   | Description             |
672| ------ | ----------------------- |
673| string | Formatted phone number. |
674
675**Example**
676  ```
677  var phonenumberfmt = new i18n.PhoneNumberFormat("CN");
678  phonenumberfmt.format("15812312312");
679  ```
680
681### getLocationName<sup>9+</sup>
682
683getLocationName(number: string, locale: string): string
684
685Obtains the home location of a phone number.
686
687**System capability**: SystemCapability.Global.I18n
688
689**Parameters**
690| Name   | Type   | Mandatory | Description   |
691| ------ | ------ | --------- | ------------- |
692| number | string | Yes       | Phone number. |
693| locale | string | Yes       | Locale ID.    |
694
695**Return value**
696| Type   | Description                        |
697| ------ | ---------------------------------- |
698| string | Home location of the phone number. |
699
700**Example**
701  ```js
702  var phonenumberfmt = new i18n.PhoneNumberFormat("CN");
703  phonenumberfmt.isValidNumber("15812312312");
704  ```
705
706
707## PhoneNumberFormatOptions<sup>8+</sup>
708
709Defines the options for this PhoneNumberFormat object.
710
711**System capability**: SystemCapability.Global.I18n
712
713| Name | Type   | Readable | Writable | Description                              |
714| ---- | ------ | -------- | -------- | ---------------------------------------- |
715| type | string | Yes      | Yes      | Format type of a phone number. The value can be **E164**, **INTERNATIONAL**, **NATIONAL**, or **RFC3966**. |
716
717
718## UnitInfo<sup>8+</sup>
719
720Defines the measurement unit information.
721
722**System capability**: SystemCapability.Global.I18n
723
724| Name          | Type   | Readable | Writable | Description                              |
725| ------------- | ------ | -------- | -------- | ---------------------------------------- |
726| unit          | string | Yes      | Yes      | Name of the measurement unit, for example, **meter**, **inch**, or **cup**. |
727| measureSystem | string | Yes      | Yes      | Measurement system. The value can be **SI**, **US**, or **UK**. |
728
729
730## Util<sup>8+</sup>
731
732
733### unitConvert<sup>8+</sup>
734
735static unitConvert(fromUnit: UnitInfo, toUnit: UnitInfo, value: number, locale: string, style?: string): string
736
737Converts one measurement unit into another and formats the unit based on the specified locale and style.
738
739**System capability**: SystemCapability.Global.I18n
740
741**Parameters**
742| Name     | Type                   | Mandatory | Description                              |
743| -------- | ---------------------- | --------- | ---------------------------------------- |
744| fromUnit | [UnitInfo](#unitinfo8) | Yes       | Measurement unit to be converted.        |
745| toUnit   | [UnitInfo](#unitinfo8) | Yes       | Measurement unit to be converted to.     |
746| value    | number                 | Yes       | Value of the measurement unit to be converted. |
747| locale   | string                 | Yes       | Locale used for formatting, for example, **zh-Hans-CN**. |
748| style    | string                 | No        | Style used for formatting. The value can be **long**, **short**, or **medium**. |
749
750**Return Value**
751| Type   | Description                              |
752| ------ | ---------------------------------------- |
753| string | Character string obtained after formatting based on the measurement unit specified by **toUnit**. |
754
755**Example**
756  ```
757  i18n.Util.unitConvert({unit: "cup", measureSystem: "US"}, {unit: "liter", measureSystem: "SI"}, 1000, "en-US", "long");
758  ```
759
760### getDateOrder<sup>9+</sup>
761
762static getDateOrder(locale: string): string
763
764Obtains the sequence of the year, month, and day in the specified locale.
765
766**System capability**: SystemCapability.Global.I18n
767
768**Parameters**
769| Name   | Type   | Mandatory | Description                              |
770| ------ | ------ | --------- | ---------------------------------------- |
771| locale | string | Yes       | Locale used for formatting, for example, **zh-Hans-CN**. |
772
773**Return value**
774| Type   | Description                           |
775| ------ | ------------------------------------- |
776| string | Sequence of the year, month, and day. |
777
778**Example**
779  ```
780  i18n.Util.getDateOrder("zh-CN");
781  ```
782
783## getInstance<sup>8+</sup>
784
785getInstance(locale?:string): IndexUtil
786
787Creates an **IndexUtil** object.
788
789**System capability**: SystemCapability.Global.I18n
790
791**Parameters**
792| Name   | Type   | Mandatory | Description                              |
793| ------ | ------ | --------- | ---------------------------------------- |
794| locale | string | No        | A string containing locale information, including the language, optional script, and region. |
795
796**Return Value**
797| Type                     | Description                              |
798| ------------------------ | ---------------------------------------- |
799| [IndexUtil](#indexutil8) | **IndexUtil** object mapping to the specified locale. |
800
801**Example**
802  ```
803  var indexUtil= i18n.getInstance("zh-CN");
804  ```
805
806
807## IndexUtil<sup>8+</sup>
808
809
810### getIndexList<sup>8+</sup>
811
812getIndexList(): Array&lt;string&gt;
813
814Obtains the index list for this **locale** object.
815
816**System capability**: SystemCapability.Global.I18n
817
818**Return Value**
819| Type                | Description                            |
820| ------------------- | -------------------------------------- |
821| Array&lt;string&gt; | Index list for this **locale** object. |
822
823**Example**
824  ```
825  var indexUtil = i18n.getInstance("zh-CN");
826  var indexList = indexUtil.getIndexList();
827  ```
828
829
830### addLocale<sup>8+</sup>
831
832addLocale(locale: string): void
833
834Adds the index of the new **locale** object to the index list.
835
836**System capability**: SystemCapability.Global.I18n
837
838**Parameters**
839| Name   | Type   | Mandatory | Description                              |
840| ------ | ------ | --------- | ---------------------------------------- |
841| locale | string | Yes       | A string containing locale information, including the language, optional script, and region. |
842
843**Example**
844  ```
845  var indexUtil = i18n.getInstance("zh-CN");
846  indexUtil.addLocale("en-US");
847  ```
848
849
850### getIndex<sup>8+</sup>
851
852getIndex(text: string): string
853
854Obtains the index of a text object.
855
856**System capability**: SystemCapability.Global.I18n
857
858**Parameters**
859| Name | Type   | Mandatory | Description                              |
860| ---- | ------ | --------- | ---------------------------------------- |
861| text | string | Yes       | **text** object whose index is to be obtained. |
862
863**Return Value**
864| Type   | Description                   |
865| ------ | ----------------------------- |
866| string | Index of the **text** object. |
867
868**Example**
869  ```
870  var indexUtil= i18n.getInstance("zh-CN");
871  indexUtil.getIndex("hi"); // Return hi.
872  ```
873
874
875## Character<sup>8+</sup>
876
877
878### isDigit<sup>8+</sup>
879
880static isDigit(char: string): boolean
881
882Checks whether the input character string is composed of digits.
883
884**System capability**: SystemCapability.Global.I18n
885
886**Parameters**
887| Name | Type   | Mandatory | Description      |
888| ---- | ------ | --------- | ---------------- |
889| char | string | Yes       | Input character. |
890
891**Return Value**
892| Type    | Description                              |
893| ------- | ---------------------------------------- |
894| boolean | Returns **true** if the input character is a digit; returns **false** otherwise. |
895
896**Example**
897  ```
898  var isdigit = i18n.Character.isDigit("1"); // Return true.
899  ```
900
901
902### isSpaceChar<sup>8+</sup>
903
904static isSpaceChar(char: string): boolean
905
906Checks whether the input character is a space.
907
908**System capability**: SystemCapability.Global.I18n
909
910**Parameters**
911| Name | Type   | Mandatory | Description      |
912| ---- | ------ | --------- | ---------------- |
913| char | string | Yes       | Input character. |
914
915**Return Value**
916| Type    | Description                              |
917| ------- | ---------------------------------------- |
918| boolean | Returns **true** if the input character is a space; returns **false** otherwise. |
919
920**Example**
921  ```
922  var isspacechar = i18n.Character.isSpaceChar("a"); // Return false.
923  ```
924
925
926### isWhitespace<sup>8+</sup>
927
928static isWhitespace(char: string): boolean
929
930Checks whether the input character is a white space.
931
932**System capability**: SystemCapability.Global.I18n
933
934**Parameters**
935| Name | Type   | Mandatory | Description      |
936| ---- | ------ | --------- | ---------------- |
937| char | string | Yes       | Input character. |
938
939**Return Value**
940| Type    | Description                              |
941| ------- | ---------------------------------------- |
942| boolean | Returns **true** if the input character is a white space; returns **false** otherwise. |
943
944**Example**
945  ```
946  var iswhitespace = i18n.Character.isWhitespace("a"); // Return false.
947  ```
948
949
950### isRTL<sup>8+</sup>
951
952static isRTL(char: string): boolean
953
954Checks whether the input character is of the right to left (RTL) language.
955
956**System capability**: SystemCapability.Global.I18n
957
958**Parameters**
959| Name | Type   | Mandatory | Description      |
960| ---- | ------ | --------- | ---------------- |
961| char | string | Yes       | Input character. |
962
963**Return Value**
964| Type    | Description                              |
965| ------- | ---------------------------------------- |
966| boolean | Returns **true** if the input character is of the RTL language; returns **false** otherwise. |
967
968**Example**
969  ```
970  var isrtl = i18n.Character.isRTL("a"); // Return false.
971  ```
972
973
974### isIdeograph<sup>8+</sup>
975
976static isIdeograph(char: string): boolean
977
978Checks whether the input character is an ideographic character.
979
980**System capability**: SystemCapability.Global.I18n
981
982**Parameters**
983| Name | Type   | Mandatory | Description      |
984| ---- | ------ | --------- | ---------------- |
985| char | string | Yes       | Input character. |
986
987**Return Value**
988| Type    | Description                              |
989| ------- | ---------------------------------------- |
990| boolean | Returns **true** if the input character is an ideographic character; returns **false** otherwise. |
991
992**Example**
993  ```
994  var isideograph = i18n.Character.isIdeograph("a"); // Return false.
995  ```
996
997
998### isLetter<sup>8+</sup>
999
1000static isLetter(char: string): boolean
1001
1002Checks whether the input character is a letter.
1003
1004**System capability**: SystemCapability.Global.I18n
1005
1006**Parameters**
1007| Name | Type   | Mandatory | Description      |
1008| ---- | ------ | --------- | ---------------- |
1009| char | string | Yes       | Input character. |
1010
1011**Return Value**
1012| Type    | Description                              |
1013| ------- | ---------------------------------------- |
1014| boolean | Returns **true** if the input character is a letter; returns **false** otherwise. |
1015
1016**Example**
1017  ```
1018  var isletter = i18n.Character.isLetter("a"); // Return true.
1019  ```
1020
1021
1022### isLowerCase<sup>8+</sup>
1023
1024static isLowerCase(char: string): boolean
1025
1026Checks whether the input character is a lowercase letter.
1027
1028**System capability**: SystemCapability.Global.I18n
1029
1030**Parameters**
1031| Name | Type   | Mandatory | Description      |
1032| ---- | ------ | --------- | ---------------- |
1033| char | string | Yes       | Input character. |
1034
1035**Return Value**
1036| Type    | Description                              |
1037| ------- | ---------------------------------------- |
1038| boolean | Returns **true** if the input character is a lowercase letter; returns **false** otherwise. |
1039
1040**Example**
1041  ```
1042  var islowercase = i18n.Character.isLowerCase("a"); // Return true.
1043  ```
1044
1045
1046### isUpperCase<sup>8+</sup>
1047
1048static isUpperCase(char: string): boolean
1049
1050Checks whether the input character is an uppercase letter.
1051
1052**System capability**: SystemCapability.Global.I18n
1053
1054**Parameters**
1055| Name | Type   | Mandatory | Description      |
1056| ---- | ------ | --------- | ---------------- |
1057| char | string | Yes       | Input character. |
1058
1059**Return Value**
1060| Type    | Description                              |
1061| ------- | ---------------------------------------- |
1062| boolean | Returns **true** if the input character is an uppercase letter; returns **false** otherwise. |
1063
1064**Example**
1065  ```
1066  var isuppercase = i18n.Character.isUpperCase("a"); // Return false.
1067  ```
1068
1069
1070### getType<sup>8+</sup>
1071
1072static getType(char: string): string
1073
1074Obtains the type of the input character string.
1075
1076**System capability**: SystemCapability.Global.I18n
1077
1078**Parameters**
1079| Name | Type   | Mandatory | Description      |
1080| ---- | ------ | --------- | ---------------- |
1081| char | string | Yes       | Input character. |
1082
1083**Return Value**
1084| Type   | Description                  |
1085| ------ | ---------------------------- |
1086| string | Type of the input character. |
1087
1088**Example**
1089  ```
1090  var type = i18n.Character.getType("a");
1091  ```
1092
1093
1094## i18n.getLineInstance<sup>8+</sup>
1095
1096getLineInstance(locale: string): BreakIterator
1097
1098Obtains a [BreakIterator](#breakiterator8) object for text segmentation.
1099
1100**System capability**: SystemCapability.Global.I18n
1101
1102**Parameters**
1103| Name   | Type   | Mandatory | Description                              |
1104| ------ | ------ | --------- | ---------------------------------------- |
1105| 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. |
1106
1107**Return Value**
1108| Type                             | Description                              |
1109| -------------------------------- | ---------------------------------------- |
1110| [BreakIterator](#breakiterator8) | [BreakIterator](#breakiterator8) object used for text segmentation. |
1111
1112**Example**
1113  ```
1114  var iterator = i18n.getLineInstance("en");
1115  ```
1116
1117
1118## BreakIterator<sup>8+</sup>
1119
1120
1121### setLineBreakText<sup>8+</sup>
1122
1123setLineBreakText(text: string): void
1124
1125Sets the text to be processed by the [BreakIterator](#breakiterator8) object.
1126
1127**System capability**: SystemCapability.Global.I18n
1128
1129**Parameters**
1130| Name | Type   | Mandatory | Description                              |
1131| ---- | ------ | --------- | ---------------------------------------- |
1132| text | string | Yes       | Text to be processed by the **BreakIterator** object. |
1133
1134**Example**
1135  ```
1136  var iterator = i18n.getLineInstance("en");
1137  iterator.setLineBreakText("Apple is my favorite fruit.");
1138  ```
1139
1140
1141### getLineBreakText<sup>8+</sup>
1142
1143getLineBreakText(): string
1144
1145Obtains the text being processed by the [BreakIterator](#breakiterator8) object.
1146
1147**System capability**: SystemCapability.Global.I18n
1148
1149**Return Value**
1150| Type   | Description                              |
1151| ------ | ---------------------------------------- |
1152| string | Text being processed by the **BreakIterator** object. |
1153
1154**Example**
1155  ```
1156  var iterator = i18n.getLineInstance("en");
1157  iterator.setLineBreakText("Apple is my favorite fruit.");
1158  iterator.getLineBreakText(); // Apple is my favorite fruit.
1159  ```
1160
1161
1162### current<sup>8+</sup>
1163
1164current(): number
1165
1166Obtains the position of the [BreakIterator](#breakiterator8) object in the text being processed.
1167
1168**System capability**: SystemCapability.Global.I18n
1169
1170**Return Value**
1171| Type   | Description                              |
1172| ------ | ---------------------------------------- |
1173| number | Position of the **BreakIterator** object in the text being processed. |
1174
1175**Example**
1176  ```
1177  var iterator = i18n.getLineInstance("en");
1178  iterator.setLineBreakText("Apple is my favorite fruit.");
1179  iterator.current(); // 0
1180  ```
1181
1182
1183### first<sup>8+</sup>
1184
1185first(): number
1186
1187Puts the [BreakIterator](#breakiterator8) object to the first text boundary, which is always at the beginning of the processed text.
1188
1189**System capability**: SystemCapability.Global.I18n
1190
1191**Return Value**
1192| Type   | Description                              |
1193| ------ | ---------------------------------------- |
1194| number | Offset to the first text boundary of the processed text. |
1195
1196**Example**
1197  ```
1198  var iterator = i18n.getLineInstance("en");
1199  iterator.setLineBreakText("Apple is my favorite fruit.");
1200  iterator.first(); // 0
1201  ```
1202
1203
1204### last<sup>8+</sup>
1205
1206last(): number
1207
1208Puts the [BreakIterator](#breakiterator8) object to the last text boundary, which is always the next position after the end of the processed text.
1209
1210**System capability**: SystemCapability.Global.I18n
1211
1212**Return Value**
1213| Type   | Description                              |
1214| ------ | ---------------------------------------- |
1215| number | Offset of the last text boundary of the processed text. |
1216
1217**Example**
1218  ```
1219  var iterator = i18n.getLineInstance("en");
1220  iterator.setLineBreakText("Apple is my favorite fruit.");
1221  iterator.last(); // 27
1222  ```
1223
1224
1225### next<sup>8+</sup>
1226
1227next(index?: number): number
1228
1229Moves 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**.
1230
1231**System capability**: SystemCapability.Global.I18n
1232
1233**Parameters**
1234| Name  | Type   | Mandatory | Description                              |
1235| ----- | ------ | --------- | ---------------------------------------- |
1236| 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**. |
1237
1238**Return Value**
1239| Type   | Description                              |
1240| ------ | ---------------------------------------- |
1241| 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. |
1242
1243**Example**
1244  ```
1245  var iterator = i18n.getLineInstance("en");
1246  iterator.setLineBreakText("Apple is my favorite fruit.");
1247  iterator.first(); // 0
1248  iterator.next(); // 6
1249  iterator.next(10); // -1
1250  ```
1251
1252
1253### previous<sup>8+</sup>
1254
1255previous(): number
1256
1257Moves the [BreakIterator](#breakiterator8) object to the previous text boundary.
1258
1259**System capability**: SystemCapability.Global.I18n
1260
1261**Return Value**
1262| Type   | Description                              |
1263| ------ | ---------------------------------------- |
1264| 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. |
1265
1266**Example**
1267  ```
1268  var iterator = i18n.getLineInstance("en");
1269  iterator.setLineBreakText("Apple is my favorite fruit.");
1270  iterator.first(); // 0
1271  iterator.next(3); // 12
1272  iterator.previous(); // 9
1273  ```
1274
1275
1276### following<sup>8+</sup>
1277
1278following(offset: number): number
1279
1280Moves 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.
1281
1282**System capability**: SystemCapability.Global.I18n
1283
1284**Parameters**
1285| Name   | Type   | Mandatory | Description                              |
1286| ------ | ------ | --------- | ---------------------------------------- |
1287| offset | number | Yes       | Offset to the position before the text boundary to which the [BreakIterator](#breakiterator8) object is moved. |
1288
1289**Return Value**
1290| Type   | Description                              |
1291| ------ | ---------------------------------------- |
1292| number | The value **-1** is returned if the text boundary to which the [BreakIterator](#breakiterator8) object is moved is outside of the processed text. |
1293
1294**Example**
1295  ```
1296  var iterator = i18n.getLineInstance("en");
1297  iterator.setLineBreakText("Apple is my favorite fruit.");
1298  iterator.following(0); // 6
1299  iterator.following(100); // -1
1300  iterator.current(); // 27
1301  ```
1302
1303
1304### isBoundary<sup>8+</sup>
1305
1306isBoundary(offset: number): boolean
1307
1308Checks 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).
1309
1310**System capability**: SystemCapability.Global.I18n
1311
1312**Parameters**
1313| Name   | Type   | Mandatory | Description        |
1314| ------ | ------ | --------- | ------------------ |
1315| offset | number | Yes       | Position to check. |
1316
1317**Return Value**
1318| Type    | Description                              |
1319| ------- | ---------------------------------------- |
1320| boolean | Returns **true** if the position specified by the offset is a text boundary; returns **false** otherwise. |
1321
1322**Example**
1323  ```
1324  var iterator = i18n.getLineInstance("en");
1325  iterator.setLineBreakText("Apple is my favorite fruit.");
1326  iterator.isBoundary(0); // true;
1327  iterator.isBoundary(5); // false;
1328  ```
1329
1330
1331## i18n.is24HourClock<sup>7+</sup>
1332
1333is24HourClock(): boolean
1334
1335Checks whether the 24-hour clock is used.
1336
1337**System capability**: SystemCapability.Global.I18n
1338
1339**Return Value**
1340| Type    | Description                              |
1341| ------- | ---------------------------------------- |
1342| boolean | Returns **true** if the 24-hour clock is used; returns **false** otherwise. |
1343
1344**Example**
1345  ```
1346  var is24HourClock = i18n.is24HourClock();
1347  ```
1348
1349
1350## i18n.set24HourClock<sup>7+</sup>
1351
1352set24HourClock(option: boolean): boolean
1353
1354Sets the 24-hour clock.
1355
1356**Required permission**: ohos.permission.UPDATE_CONFIGURATION
1357
1358**System capability**: SystemCapability.Global.I18n
1359
1360**Parameters**
1361| Name   | Type    | Mandatory | Description                              |
1362| ------ | ------- | --------- | ---------------------------------------- |
1363| 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. |
1364
1365**Return Value**
1366| Type    | Description                              |
1367| ------- | ---------------------------------------- |
1368| boolean | Returns **true** if the 24-hour clock is enabled; returns **false** otherwise. |
1369
1370**Example**
1371  ```
1372  // Set the system time to the 24-hour clock.
1373  var success = i18n.set24HourClock(true);
1374  ```
1375
1376
1377## i18n.addPreferredLanguage<sup>8+</sup>
1378
1379addPreferredLanguage(language: string, index?: number): boolean
1380
1381Adds a preferred language to the specified position on the preferred language list.
1382
1383**Required permission**: ohos.permission.UPDATE_CONFIGURATION
1384
1385**System capability**: SystemCapability.Global.I18n
1386
1387**Parameters**
1388| Name     | Type   | Mandatory | Description                              |
1389| -------- | ------ | --------- | ---------------------------------------- |
1390| language | string | Yes       | Preferred language to add.               |
1391| index    | number | No        | Position to which the preferred language is added. |
1392
1393**Return Value**
1394| Type    | Description                              |
1395| ------- | ---------------------------------------- |
1396| boolean | Returns **true** if the preferred language is successfully added; returns **false** otherwise. |
1397
1398**Example**
1399  ```
1400  // Add zh-CN to the preferred language list.
1401  var language = 'zh-CN';
1402  var index = 0;
1403  var success = i18n.addPreferredLanguage(language, index);
1404  ```
1405
1406
1407## i18n.removePreferredLanguage<sup>8+</sup>
1408
1409removePreferredLanguage(index: number): boolean
1410
1411Deletes a preferred language from the specified position on the preferred language list.
1412
1413**Required permission**: ohos.permission.UPDATE_CONFIGURATION
1414
1415**System capability**: SystemCapability.Global.I18n
1416
1417**Parameters**
1418| Name  | Type   | Mandatory | Description                              |
1419| ----- | ------ | --------- | ---------------------------------------- |
1420| index | number | Yes       | Position of the preferred language to delete. |
1421
1422**Return Value**
1423| Type    | Description                              |
1424| ------- | ---------------------------------------- |
1425| boolean | Returns **true** if the preferred language is deleted; returns **false** otherwise. |
1426
1427**Example**
1428  ```
1429  // Delete the first preferred language from the preferred language list.
1430  var index = 0;
1431  var success = i18n.removePreferredLanguage(index);
1432  ```
1433
1434
1435## i18n.getPreferredLanguageList<sup>8+</sup>
1436
1437getPreferredLanguageList(): Array&lt;string&gt;
1438
1439Obtains the list of preferred languages.
1440
1441**System capability**: SystemCapability.Global.I18n
1442
1443**Return Value**
1444| Type                | Description                  |
1445| ------------------- | ---------------------------- |
1446| Array&lt;string&gt; | List of preferred languages. |
1447
1448**Example**
1449  ```
1450  var preferredLanguageList = i18n.getPreferredLanguageList();
1451  ```
1452
1453
1454## i18n.getFirstPreferredLanguage<sup>8+</sup>
1455
1456getFirstPreferredLanguage(): string
1457
1458Obtains the first language in the preferred language list.
1459
1460**System capability**: SystemCapability.Global.I18n
1461
1462**Return Value**
1463| Type   | Description                              |
1464| ------ | ---------------------------------------- |
1465| string | First language in the preferred language list. |
1466
1467**Example**
1468  ```
1469  var firstPreferredLanguage = i18n.getFirstPreferredLanguage();
1470  ```
1471
1472
1473## i18n.getTimeZone<sup>7+</sup>
1474
1475getTimeZone(zoneID?: string): TimeZone
1476
1477Obtains the **TimeZone** object corresponding to the specified time zone ID.
1478
1479**System capability**: SystemCapability.Global.I18n
1480
1481**Parameters**
1482| Name   | Type   | Mandatory | Description   |
1483| ------ | ------ | --------- | ------------- |
1484| zondID | string | No        | Time zone ID. |
1485
1486**Return Value**
1487| Type     | Description                              |
1488| -------- | ---------------------------------------- |
1489| TimeZone | **TimeZone** object corresponding to the time zone ID. |
1490
1491**Example**
1492  ```
1493  var timezone = i18n.getTimeZone();
1494  ```
1495
1496
1497## TimeZone
1498
1499
1500### getID
1501
1502getID(): string
1503
1504Obtains the ID of the specified **TimeZone** object.
1505
1506**System capability**: SystemCapability.Global.I18n
1507
1508**Return Value**
1509| Type   | Description                              |
1510| ------ | ---------------------------------------- |
1511| string | Time zone ID corresponding to the **TimeZone** object. |
1512
1513**Example**
1514  ```
1515  var timezone = i18n.getTimeZone();
1516  timezone.getID();
1517  ```
1518
1519
1520### getDisplayName
1521
1522getDisplayName(locale?: string, isDST?: boolean): string
1523
1524Obtains the representation of a **TimeZone** object in the specified locale.
1525
1526**System capability**: SystemCapability.Global.I18n
1527
1528**Parameters**
1529| Name   | Type    | Mandatory | Description                              |
1530| ------ | ------- | --------- | ---------------------------------------- |
1531| locale | string  | No        | System locale ID.                        |
1532| isDST  | boolean | No        | Whether to consider DST when obtaining the representation of the **TimeZone** object. |
1533
1534**Return Value**
1535| Type   | Description                              |
1536| ------ | ---------------------------------------- |
1537| string | Representation of the **TimeZone** object in the specified locale. |
1538
1539**Example**
1540  ```
1541  var timezone = i18n.getTimeZone();
1542  timezone.getDisplayName("zh-CN", false);
1543  ```
1544
1545
1546### getRawOffset
1547
1548getRawOffset(): number
1549
1550Obtains the offset between the time zone represented by a **TimeZone** object and the UTC time zone.
1551
1552**System capability**: SystemCapability.Global.I18n
1553
1554**Return Value**
1555| Type   | Description                              |
1556| ------ | ---------------------------------------- |
1557| number | Offset between the time zone represented by the **TimeZone** object and the UTC time zone. |
1558
1559**Example**
1560  ```
1561  var timezone = i18n.getTimeZone();
1562  timezone.getRawOffset();
1563  ```
1564
1565
1566### getOffset
1567
1568getOffset(date?: number): number
1569
1570Obtains the offset between the time zone represented by a **TimeZone** object and the UTC time zone at a certain time point.
1571
1572**System capability**: SystemCapability.Global.I18n
1573
1574**Return Value**
1575| Type   | Description                              |
1576| ------ | ---------------------------------------- |
1577| number | Offset between the time zone represented by the **TimeZone** object and the UTC time zone at a certain time point. |
1578
1579**Example**
1580  ```
1581  var timezone = i18n.getTimeZone();
1582  timezone.getOffset(1234567890);
1583  ```
1584
1585### getAvailableIDs<sup>9+</sup>
1586
1587static getAvailableIDs(): Array&lt;string&gt;
1588
1589Obtains the list of time zone IDs supported by the system.
1590
1591**System capability**: SystemCapability.Global.I18n
1592
1593**Return value**
1594| Type                | Description                              |
1595| ------------------- | ---------------------------------------- |
1596| Array&lt;string&gt; | List of time zone IDs supported by the system. |
1597
1598**Example**
1599  ```ts
1600  var ids = i18n.TimeZone.getAvailableIDs();
1601  ```
1602
1603
1604### getAvailableZoneCityIDs<sup>9+</sup>
1605
1606static getAvailableZoneCityIDs(): Array&lt;string&gt;
1607
1608Obtains the list of time zone city IDs supported by the system.
1609
1610**System capability**: SystemCapability.Global.I18n
1611
1612**Return value**
1613| Type                | Description                              |
1614| ------------------- | ---------------------------------------- |
1615| Array&lt;string&gt; | List of time zone city IDs supported by the system. |
1616
1617**Example**
1618  ```ts
1619  var cityIDs = i18n.TimeZone.getAvailableZoneCityIDs();
1620  ```
1621
1622
1623### getCityDisplayName<sup>9+</sup>
1624
1625static getCityDisplayName(cityID: string, locale: string): string
1626
1627Obtains the localized display of a time zone city in the specified locale.
1628
1629**System capability**: SystemCapability.Global.I18n
1630
1631**Parameters**
1632| Name   | Type   | Mandatory | Description        |
1633| ------ | ------ | --------- | ------------------ |
1634| cityID | string | Yes       | Time zone city ID. |
1635| locale | string | Yes       | Locale ID.         |
1636
1637**Return value**
1638| Type   | Description                              |
1639| ------ | ---------------------------------------- |
1640| string | Localized display of the time zone city in the specified locale. |
1641
1642**Example**
1643  ```ts
1644  var displayName = i18n.TimeZone.getCityDisplayName("Shanghai", "zh-CN");
1645  ```
1646
1647
1648### getTimezoneFromCity<sup>9+</sup>
1649
1650static getTimezoneFromCity(cityID: string): TimeZone
1651
1652Obtains the **TimeZone** object corresponding to the specified time zone city ID.
1653
1654**System capability**: SystemCapability.Global.I18n
1655
1656**Parameters**
1657| Name   | Type   | Mandatory | Description        |
1658| ------ | ------ | --------- | ------------------ |
1659| cityID | string | Yes       | Time zone city ID. |
1660
1661**Return value**
1662| Type     | Description                              |
1663| -------- | ---------------------------------------- |
1664| TimeZone | **TimeZone** object corresponding to the specified time zone city ID. |
1665
1666**Example**
1667  ```ts
1668  var timezone = i18n.TimeZone.getTimezoneFromCity("Shanghai");
1669  ```
1670
1671
1672## i18n.setUsingLocalDigit<sup>9+</sup>
1673
1674setUsingLocalDigit(flag: boolean): boolean
1675
1676Sets whether to turn on the local digit switch.
1677
1678This is a system API.
1679
1680**Permission required**: ohos.permission.UPDATE_CONFIGURATION
1681
1682**System capability**: SystemCapability.Global.I18n
1683
1684**Parameters**
1685| Name | Type    | Mandatory | Description                              |
1686| ---- | ------- | --------- | ---------------------------------------- |
1687| 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. |
1688
1689**Return value**
1690| Type    | Description                              |
1691| ------- | ---------------------------------------- |
1692| 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. |
1693
1694**Example**
1695  ```ts
1696  var status = i18n.setUsingLocalDigit(true);
1697  ```
1698
1699
1700## i18n.getUsingLocalDigit<sup>9+</sup>
1701
1702getUsingLocalDigit(): boolean
1703
1704Checks whether the local digit switch is turned on.
1705
1706**System capability**: SystemCapability.Global.I18n
1707
1708**Return value**
1709| Type    | Description                              |
1710| ------- | ---------------------------------------- |
1711| 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. |
1712
1713**Example**
1714  ```ts
1715  var status = i18n.getUsingLocalDigit();
1716  ```
1717
1718
1719## Transliterator<sup>9+</sup>
1720
1721
1722### getAvailableIDs<sup>9+</sup>
1723
1724static getAvailableIDs(): string[]
1725
1726Obtains a list of IDs supported by the **Transliterator** object.
1727
1728**System capability**: SystemCapability.Global.I18n
1729
1730**Return value**
1731| Type     | Description                              |
1732| -------- | ---------------------------------------- |
1733| string[] | List of IDs supported by the **Transliterator** object. |
1734
1735**Example**
1736  ```ts
1737  i18n.Transliterator.getAvailableIDs();
1738  ```
1739
1740
1741### getInstance<sup>9+</sup>
1742
1743static getInstance(id: string): Transliterator
1744
1745Creates a **Transliterator** object.
1746
1747**System capability**: SystemCapability.Global.I18n
1748
1749**Parameters**
1750| Name | Type   | Mandatory | Description                              |
1751| ---- | ------ | --------- | ---------------------------------------- |
1752| id   | string | Yes       | ID supported by the **Transliterator** object. |
1753
1754**Return value**
1755| Type                               | Description                |
1756| ---------------------------------- | -------------------------- |
1757| [Transliterator](#transliterator9) | **Transliterator** object. |
1758
1759**Example**
1760  ```ts
1761  var transliterator = i18n.Transliterator.getInstance("Any-Latn");
1762  ```
1763
1764
1765### transform<sup>9+</sup>
1766
1767transform(text: string): string
1768
1769Converts the input string from the source format to the target format.
1770
1771**System capability**: SystemCapability.Global.I18n
1772
1773**Parameters**
1774| Name | Type   | Mandatory | Description   |
1775| ---- | ------ | --------- | ------------- |
1776| text | string | Yes       | Input string. |
1777
1778**Return value**
1779| Type   | Description    |
1780| ------ | -------------- |
1781| string | Target string. |
1782
1783**Example**
1784  ```ts
1785  var transliterator = i18n.Transliterator.getInstance("Any-Latn");
1786  transliterator.transform ("China");
1787  ```
1788