• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.i18n (Internationalization)
2
3This module provides system-related or enhanced [i18n](../../internationalization/i18n-l10n.md) capabilities, such as locale management, phone number formatting, and calendar, through supplementary I18N APIs that are not defined in [ECMA 402](https://dev.ecma-international.org/publications-and-standards/standards/ecma-402/). The [intl](js-apis-intl.md) module provides basic i18n capabilities through the standard i18n APIs defined in ECMA 402. It works with the **i18n** module to provide a complete suite of i18n capabilities.
4
5>  **NOTE**
6>
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>  - The APIs of this module conform to the [Common Locale Data Repository (CLDR)](https://cldr.unicode.org) internationalization database. The processing result may change with CLDR evolution. API version 12 corresponds to [CLDR 42](https://cldr.unicode.org/index/downloads/cldr-42). For details about data changes, visit the official website.
10>
11>  - Since API version 11, some APIs of this module are supported in ArkTS widgets.
12
13
14## Modules to Import
15
16```ts
17import { i18n } from '@kit.LocalizationKit';
18```
19
20## System<sup>9+</sup>
21
22### getDisplayCountry<sup>9+</sup>
23
24static getDisplayCountry(country: string, locale: string, sentenceCase?: boolean): string
25
26Obtains the country/region display name in the specified language.
27
28**Atomic service API**: This API can be used in atomic services since API version 12.
29
30**System capability**: SystemCapability.Global.I18n
31
32**Parameters**
33
34| Name         | Type     | Mandatory  | Description              |
35| ------------ | ------- | ---- | ---------------- |
36| country      | string  | Yes   | Valid country/region code.           |
37| locale       | string  | Yes   | [System locale](../../internationalization/i18n-locale-culture.md#how-it-works), which consists of the language, script, and country/region.    |
38| sentenceCase | boolean | No   | Whether to use sentence case to display the text. The value **true** means to display the text in title case format, and the value **false** means to display the text in the default case format of the locale. The default value is **true**.|
39
40**Return value**
41
42| Type    | Description           |
43| ------ | ------------- |
44| string | Country/region display name in the specified language.|
45
46**Error codes**
47
48For details about the error codes, see [ohos.i18n Error Codes](errorcode-i18n.md) and [Universal Error Codes](../errorcode-universal.md).
49
50| ID | Error Message                  |
51| ------ | ---------------------- |
52| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
53| 890001 | Invalid parameter. Possible causes: Parameter verification failed. |
54
55> **Description**
56>
57> The error message of 890001 is subject to the actual error.
58
59**Example**
60  ```ts
61  import { BusinessError } from '@kit.BasicServicesKit';
62
63  try {
64    let displayCountry: string = i18n.System.getDisplayCountry('CN', 'en-GB'); // displayCountry = 'China'
65  } catch (error) {
66    let err: BusinessError = error as BusinessError;
67    console.error(`call System.getDisplayCountry failed, error code: ${err.code}, message: ${err.message}.`);
68  }
69  ```
70
71### getDisplayLanguage<sup>9+</sup>
72
73static getDisplayLanguage(language: string, locale: string, sentenceCase?: boolean): string
74
75Obtains the language display name in the specified language.
76
77**Atomic service API**: This API can be used in atomic services since API version 11.
78
79**System capability**: SystemCapability.Global.I18n
80
81**Parameters**
82
83| Name         | Type     | Mandatory  | Description              |
84| ------------ | ------- | ---- | ---------------- |
85| language     | string  | Yes   | Valid language ID.           |
86| locale       | string  | Yes   | [System locale](../../internationalization/i18n-locale-culture.md#how-it-works), which consists of the language, script, and country/region.    |
87| sentenceCase | boolean | No   | Whether to use sentence case to display the text. The value **true** means to display the text in title case format, and the value **false** means to display the text in the default case format of the locale. The default value is **true**.|
88
89**Return value**
90
91| Type    | Description           |
92| ------ | ------------- |
93| string | Language display name in the specified language.|
94
95**Error codes**
96
97For details about the error codes, see [ohos.i18n Error Codes](errorcode-i18n.md) and [Universal Error Codes](../errorcode-universal.md).
98
99| ID | Error Message                  |
100| ------ | ---------------------- |
101| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
102| 890001 | Invalid parameter. Possible causes: Parameter verification failed. |
103
104**Example**
105  ```ts
106  import { BusinessError } from '@kit.BasicServicesKit';
107
108  try {
109    // Obtain the display name of Chinese in English.
110    let displayLanguage: string = i18n.System.getDisplayLanguage('zh', 'en-GB'); // displayLanguage = 'Chinese'
111  } catch (error) {
112    let err: BusinessError = error as BusinessError;
113    console.error(`call System.getDisplayLanguage failed, error code: ${err.code}, message: ${err.message}.`);
114  }
115  ```
116
117### getSystemLanguages<sup>9+</sup>
118
119static getSystemLanguages(): Array&lt;string&gt;
120
121Obtains the list of system languages.
122
123Since API version 11, this API is supported in ArkTS widgets.
124
125**Atomic service API**: This API can be used in atomic services since API version 12.
126
127**System capability**: SystemCapability.Global.I18n
128
129**Return value**
130
131| Type                 | Description          |
132| ------------------- | ------------ |
133| Array&lt;string&gt; | List of system languages.|
134
135**Example**
136  ```ts
137  // systemLanguages = [ 'ug', 'bo', 'zh-Hant', 'en-Latn-US', 'zh-Hans' ]
138  let systemLanguages: Array<string> = i18n.System.getSystemLanguages();
139  ```
140
141### getSystemCountries<sup>9+</sup>
142
143static getSystemCountries(language: string): Array&lt;string&gt;
144
145Obtains the list of countries/regions supported for the specified language.
146
147**Atomic service API**: This API can be used in atomic services since API version 12.
148
149**System capability**: SystemCapability.Global.I18n
150
151**Parameters**
152
153| Name     | Type    | Mandatory  | Description   |
154| -------- | ------ | ---- | ----- |
155| language | string | Yes   | Valid language ID.|
156
157**Return value**
158
159| Type                 | Description          |
160| ------------------- | ------------ |
161| Array&lt;string&gt; | List of countries/regions supported for the specified language.|
162
163**Error codes**
164
165For details about the error codes, see [ohos.i18n Error Codes](errorcode-i18n.md) and [Universal Error Codes](../errorcode-universal.md).
166
167| ID | Error Message                  |
168| ------ | ---------------------- |
169| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
170| 890001 | Invalid parameter. Possible causes: Parameter verification failed. |
171
172> **Description**
173>
174> The error message of 890001 is subject to the actual error.
175
176**Example**
177  ```ts
178  import { BusinessError } from '@kit.BasicServicesKit';
179
180  try {
181    // systemCountries = [ 'ZW', 'YT', 'YE', ..., 'ER', 'CN', 'DE' ]
182    let systemCountries: Array<string> = i18n.System.getSystemCountries('zh');
183  } catch (error) {
184    let err: BusinessError = error as BusinessError;
185    console.error(`call System.getSystemCountries failed, error code: ${err.code}, message: ${err.message}.`);
186  }
187  ```
188
189### isSuggested<sup>9+</sup>
190
191static isSuggested(language: string, region?: string): boolean
192
193Checks whether a language is a suggested language in the specified region. It can be used for region-based language recommendation or language-based region recommendation.
194
195**Atomic service API**: This API can be used in atomic services since API version 12.
196
197**System capability**: SystemCapability.Global.I18n
198
199**Parameters**
200
201| Name     | Type    | Mandatory  | Description           |
202| -------- | ------ | ---- | ------------- |
203| language | string | Yes   | Valid language ID, for example, **zh**.|
204| region   | string | No   | Valid region ID, for example, **CN**.<br>The default value is the country/region of the SIM card. |
205
206**Return value**
207
208| Type     | Description                                      |
209| ------- | ---------------------------------------- |
210| boolean | Whether a language is a suggested language. The value **true** indicates that the language is a suggested language of the region, the the value false indicates the opposite.|
211
212**Error codes**
213
214For details about the error codes, see [ohos.i18n Error Codes](errorcode-i18n.md) and [Universal Error Codes](../errorcode-universal.md).
215
216| ID | Error Message                  |
217| ------ | ---------------------- |
218| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
219| 890001 | Invalid parameter. Possible causes: Parameter verification failed. |
220
221
222> **Description**
223>
224> The error message of 890001 is subject to the actual error.
225
226**Example**
227  ```ts
228  import { BusinessError } from '@kit.BasicServicesKit';
229
230  try {
231    let isSuggestedCountry: boolean = i18n.System.isSuggested('zh', 'CN'); // isSuggestedCountry = true
232    isSuggestedCountry = i18n.System.isSuggested('en'); // Check whether a language is a suggested language for the current system region.
233  } catch (error) {
234    let err: BusinessError = error as BusinessError;
235    console.error(`call System.isSuggested failed, error code: ${err.code}, message: ${err.message}.`);
236  }
237  ```
238
239### getSystemLanguage<sup>9+</sup>
240
241static getSystemLanguage(): string
242
243Obtains the current system language.
244
245**Atomic service API**: This API can be used in atomic services since API version 11.
246
247**Widget capability**: Since API version 11, this feature is supported in ArkTS widgets.
248
249**System capability**: SystemCapability.Global.I18n
250
251**Return value**
252
253| Type    | Description     |
254| ------ | ------- |
255| string | Language ID.|
256
257**Example**
258  ```ts
259  let systemLanguage: string = i18n.System.getSystemLanguage(); // If the system language is simplified Chinese, then systemLanguage is 'zh-Hans'.
260  ```
261
262### getSystemRegion<sup>9+</sup>
263
264static getSystemRegion(): string
265
266Obtains the current system country/region.
267
268**Atomic service API**: This API can be used in atomic services since API version 12.
269
270**System capability**: SystemCapability.Global.I18n
271
272**Return value**
273
274| Type    | Description     |
275| ------ | ------- |
276| string | Country/region ID.|
277
278**Example**
279  ```ts
280  let systemRegion: string = i18n.System.getSystemRegion(); // If the system region is China, then systemRegion is CN.
281  ```
282
283### getSystemLocale<sup>9+</sup>
284
285static getSystemLocale(): string
286
287Obtains the current system locale.
288
289**Atomic service API**: This API can be used in atomic services since API version 11.
290
291**System capability**: SystemCapability.Global.I18n
292
293**Return value**
294
295| Type    | Description     |
296| ------ | ------- |
297| string | Locale ID.|
298
299**Example**
300  ```ts
301  let systemLocale: string = i18n.System.getSystemLocale(); // If the system language is simplified Chinese and the system region is China, then systemLocale is zh-Hans-CN.
302  ```
303
304### is24HourClock<sup>9+</sup>
305
306static is24HourClock(): boolean
307
308Checks whether the 24-hour clock is used.
309
310**Widget capability**: Since API version 11, this feature is supported in ArkTS widgets.
311
312**Atomic service API**: This API can be used in atomic services since API version 12.
313
314**System capability**: SystemCapability.Global.I18n
315
316**Return value**
317
318| Type     | Description                                      |
319| ------- | ---------------------------------------- |
320| boolean | Whether the 24-hour clock is used. The value **true** indicates that the 24-hour clock is used, the the value **false** means the opposite.|
321
322**Example**
323  ```ts
324  let is24HourClock: boolean = i18n.System.is24HourClock(); // If the 24-hour clock is used, then is24HourClock is true.
325  ```
326
327
328### getPreferredLanguageList<sup>9+</sup>
329
330static getPreferredLanguageList(): Array&lt;string&gt;
331
332Obtains the list of preferred languages.
333
334**Atomic service API**: This API can be used in atomic services since API version 12.
335
336**System capability**: SystemCapability.Global.I18n
337
338**Return value**
339
340| Type                 | Description       |
341| ------------------- | --------- |
342| Array&lt;string&gt; | List of preferred languages.|
343
344**Example**
345  ```ts
346  let preferredLanguageList: Array<string> = i18n.System.getPreferredLanguageList();
347  ```
348
349### getFirstPreferredLanguage<sup>9+</sup>
350
351static getFirstPreferredLanguage(): string
352
353Obtains the first language in the preferred language list.
354
355**Atomic service API**: This API can be used in atomic services since API version 12.
356
357**System capability**: SystemCapability.Global.I18n
358
359**Return value**
360
361| Type    | Description            |
362| ------ | -------------- |
363| string | First language in the preferred language list.|
364
365**Example**
366  ```ts
367  let firstPreferredLanguage: string = i18n.System.getFirstPreferredLanguage();
368  ```
369
370### setAppPreferredLanguage<sup>11+</sup>
371
372static setAppPreferredLanguage(language: string): void
373
374Sets the preferred language of the application. Resources are loaded in the preferred language when the application is launched. If the preferred language is set to **default**, the application's language will be the same as the system language, and the setting will take effect upon cold starting of the application.
375
376**Atomic service API**: This API can be used in atomic services since API version 12.
377
378**System capability**: SystemCapability.Global.I18n
379
380**Parameters**
381
382| Name     | Type    | Mandatory  | Description   |
383| -------- | ------ | ---- | ----- |
384| language | string | Yes   | Valid language ID or **default**.|
385
386**Error codes**
387
388For details about the error codes, see [ohos.i18n Error Codes](errorcode-i18n.md) and [Universal Error Codes](../errorcode-universal.md).
389
390| ID | Error Message                  |
391| ------ | ---------------------- |
392| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
393| 890001 | Invalid parameter. Possible causes: Parameter verification failed. |
394
395**Example**
396  ```ts
397  import { BusinessError } from '@kit.BasicServicesKit';
398
399  try {
400    i18n.System.setAppPreferredLanguage('zh');
401  } catch (error) {
402    let err: BusinessError = error as BusinessError;
403    console.error(`call System.setAppPreferredLanguage failed, error code: ${err.code}, message: ${err.message}.`);
404  }
405  ```
406
407### getAppPreferredLanguage<sup>9+</sup>
408
409static getAppPreferredLanguage(): string
410
411Obtains the preferred language of an application.
412
413**Atomic service API**: This API can be used in atomic services since API version 12.
414
415**System capability**: SystemCapability.Global.I18n
416
417**Return value**
418
419| Type    | Description      |
420| ------ | -------- |
421| string | Preferred language of the application.|
422
423**Example**
424  ```ts
425  let appPreferredLanguage: string = i18n.System.getAppPreferredLanguage();
426  ```
427
428
429### getUsingLocalDigit<sup>9+</sup>
430
431static getUsingLocalDigit(): boolean
432
433Checks whether use of local digits is enabled.
434
435**Atomic service API**: This API can be used in atomic services since API version 12.
436
437**System capability**: SystemCapability.Global.I18n
438
439**Return value**
440
441| Type     | Description                                      |
442| ------- | ---------------------------------------- |
443| boolean | Whether use of local digits is enabled. The value **true** indicates that use of local digits is enabled, and the value **false** indicates the opposite.|
444
445**Example**
446  ```ts
447  let usingLocalDigit: boolean = i18n.System.getUsingLocalDigit();
448  ```
449
450### getSimplifiedLanguage<sup>15+</sup>
451
452static getSimplifiedLanguage(language?: string): string
453
454Obtains the simplified representation of a language. For example, the simplified representation of **en-Latn-US** is **en**, and that of **en-Latn-GB** is **en-GB**.
455
456**Atomic service API**: This API can be used in atomic services since API version 15.
457
458**System capability**: SystemCapability.Global.I18n
459
460**Parameters**
461
462| Name     | Type    | Mandatory  | Description           |
463| -------- | ------ | ---- | ------------- |
464| language | string | No   | Valid language ID. The default value is the system language.|
465
466**Return value**
467
468| Type     | Description                                      |
469| ------- | ---------------------------------------- |
470| string | If **language** is not passed, the application checks for dialects supported by the system based on the system language and locale. If such a dialect is found, the simplified representation of the dialect is returned. Otherwise, the simplified representation of the system language is returned.<br>If **language** is passed, the simplified representation of the specified language is returned.|
471
472**Error codes**
473
474For details about the error codes, see [ohos.i18n Error Codes](errorcode-i18n.md) and [Universal Error Codes](../errorcode-universal.md).
475
476| ID | Error Message                  |
477| ------ | ---------------------- |
478| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
479| 890001 | Invalid parameter. Possible causes: Parameter verification failed. |
480
481**Example**
482  ```ts
483  import { BusinessError } from '@kit.BasicServicesKit';
484
485  try {
486    // simplifiedLanguage = 'zh'
487    let simplifiedLanguage: string = i18n.System.getSimplifiedLanguage('zh-Hans-CN');
488    // Obtain the simplified representation of the current system language.
489    let simplifiedSystemLanguage: string = i18n.System.getSimplifiedLanguage();
490  } catch (error) {
491    let err: BusinessError = error as BusinessError;
492    console.error(`call System.getSimplifiedLanguage failed, error code: ${err.code}, message: ${err.message}.`);
493  }
494  ```
495
496### getTemperatureType<sup>18+</sup>
497
498static getTemperatureType(): TemperatureType
499
500Obtains the temperature unit of the system.
501
502**Atomic service API**: This API can be used in atomic services since API version 18.
503
504**System capability**: SystemCapability.Global.I18n
505
506**Return value**
507
508| Type    | Description           |
509| ------ | ------------- |
510| [TemperatureType](#temperaturetype18) | Temperature unit.|
511
512**Example**
513  ```ts
514  let temperatureType: i18n.TemperatureType = i18n.System.getTemperatureType();
515  ```
516
517### getTemperatureName<sup>18+</sup>
518
519static getTemperatureName(type: TemperatureType): string
520
521Obtains the name of a temperature unit.
522
523**Atomic service API**: This API can be used in atomic services since API version 18.
524
525**System capability**: SystemCapability.Global.I18n
526
527**Parameters**
528
529| Name     | Type    | Mandatory  | Description           |
530| -------- | ------ | ---- | ------------- |
531| type| [TemperatureType](#temperaturetype18) | Yes   | Temperature unit.|
532
533**Return value**
534
535| Type     | Description                                      |
536| ------- | ---------------------------------------- |
537| string | Name of the temperature unit, which can be **celsius**, **fahrenheit**, and **kelvin**.|
538
539**Error codes**
540
541For details about the error codes, see [i18n Error Codes](errorcode-i18n.md).
542
543| ID | Error Message                  |
544| ------ | ---------------------- |
545| 890001 | Invalid parameter. Possible causes: Parameter verification failed. |
546
547
548> **Description**
549>
550> The error message of 890001 is subject to the actual error.
551
552**Example**
553  ```ts
554  import { BusinessError } from '@kit.BasicServicesKit';
555
556  try {
557    // temperatureName = 'celsius'
558    let temperatureName: string = i18n.System.getTemperatureName(i18n.TemperatureType.CELSIUS);
559  } catch (error) {
560    let err: BusinessError = error as BusinessError;
561    console.error(`call System.getTemperatureName failed, error code: ${err.code}, message: ${err.message}.`);
562  }
563  ```
564
565### getFirstDayOfWeek<sup>18+</sup>
566
567static getFirstDayOfWeek(): WeekDay
568
569Obtains the first day of a week in the system settings.
570
571**Atomic service API**: This API can be used in atomic services since API version 18.
572
573**System capability**: SystemCapability.Global.I18n
574
575**Return value**
576
577| Type    | Description           |
578| ------ | ------------- |
579| [WeekDay](#weekday18) | Start day of a week.|
580
581**Example**
582  ```ts
583  let firstDayOfWeek: i18n.WeekDay = i18n.System.getFirstDayOfWeek();
584  ```
585
586## TemperatureType<sup>18+</sup>
587
588Enumerates temperature units.
589
590**Atomic service API**: This API can be used in atomic services since API version 18.
591
592**System capability**: SystemCapability.Global.I18n
593
594| Name| Value| Description|
595| -------- | -------- | -------- |
596| CELSIUS | 1 | Celsius.|
597| FAHRENHEIT | 2 | Fahrenheit.|
598| KELVIN | 3 | Kelvin.|
599
600## WeekDay<sup>18+</sup>
601
602Enumerates the first day of a week. The value ranges from Monday to Sunday.
603
604**Atomic service API**: This API can be used in atomic services since API version 18.
605
606**System capability**: SystemCapability.Global.I18n
607
608| Name| Value| Description|
609| -------- | -------- | -------- |
610| MON | 1 | Monday.|
611| TUE | 2 | Tuesday.|
612| WED | 3 | Wednesday.|
613| THU | 4 | Thursday.|
614| FRI | 5 | Friday.|
615| SAT | 6 | Saturday.|
616| SUN | 7 | Sunday.|
617
618
619## i18n.isRTL
620
621isRTL(locale: string): boolean
622
623Checks whether a language is an RTL language. For an RTL language, [UI mirroring](../../internationalization/i18n-ui-design.md#ui-mirroring) is required.
624
625**Atomic service API**: This API can be used in atomic services since API version 12.
626
627**System capability**: SystemCapability.Global.I18n
628
629**Parameters**
630
631| Name   | Type    | Mandatory  | Description     |
632| ------ | ------ | ---- | ------- |
633| locale | string | Yes   | [System locale](../../internationalization/i18n-locale-culture.md#how-it-works), which consists of the language, script, and country/region. |
634
635**Return value**
636
637| Type     | Description                                      |
638| ------- | ---------------------------------------- |
639| boolean | Whether a language is an RTL language. The value **true** indicates that the language is an RTL language, and the value **false** indicates the opposite.|
640
641**Example**
642  ```ts
643  let isZhRTL: boolean = i18n.isRTL('zh-CN'); // Since Chinese is not written from right to left, false is returned.
644  let isArRTL: boolean = i18n.isRTL('ar-EG'); // Since Arabic is written from right to left, true is returned.
645  ```
646
647## i18n.getCalendar<sup>8+</sup>
648
649getCalendar(locale: string, type? : string): Calendar
650
651Obtains the **Calendar** object for the specified locale and calendar type.
652
653**Atomic service API**: This API can be used in atomic services since API version 12.
654
655**System capability**: SystemCapability.Global.I18n
656
657**Parameters**
658
659| Name   | Type    | Mandatory  | Description                                      |
660| ------ | ------ | ---- | ---------------------------------------- |
661| locale | string | Yes   | [Locale ID](../../internationalization/i18n-locale-culture.md#how-it-works), which consists of the language, script, and country/region, for example, **zh-Hans-CN**.                |
662| type   | string | No   | Calendar. The value can be buddhist,&nbsp;chinese,&nbsp;coptic,&nbsp;ethiopic,&nbsp;hebrew,&nbsp;gregory,&nbsp;indian,&nbsp;islamic_civil,&nbsp;islamic_tbla,&nbsp;islamic_umalqura,&nbsp;japanese,&nbsp; or persian.<br>The default value is the default calendar of the locale. For details about the meanings and application scenarios of different values, see [Calendar Setting ](../../internationalization/i18n-calendar.md).|
663
664**Return value**
665
666| Type                    | Description   |
667| ---------------------- | ----- |
668| [Calendar](#calendar8) | **Calendar** object.|
669
670**Example**
671  ```ts
672  let calendar: i18n.Calendar = i18n.getCalendar('zh-Hans', 'chinese'); // Obtain the Calendar object for the Chinese lunar calendar.
673  ```
674
675## EntityRecognizer<sup>11+</sup>
676
677### constructor<sup>11+</sup>
678
679constructor(locale?: string)
680
681Creates an **entityRecognizer** object. This object is used to recognize entities in the text for the specified locale.
682
683**Atomic service API**: This API can be used in atomic services since API version 12.
684
685**System capability**: SystemCapability.Global.I18n
686
687**Parameters**
688
689| Name | Type  | Mandatory  | Description               |
690| ---- | ---- | ---- | ----------------- |
691| locale | string | No   | [Locale ID](../../internationalization/i18n-locale-culture.md#how-it-works), which consists of the language, script, and country/region, for example, **zh-Hans-CN**.<br>The default value is the current system locale.|
692
693**Error codes**
694
695For details about the error codes, see [ohos.i18n Error Codes](errorcode-i18n.md) and [Universal Error Codes](../errorcode-universal.md).
696
697| ID | Error Message                  |
698| ------ | ---------------------- |
699| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
700| 890001 | Invalid parameter. Possible causes: Parameter verification failed. |
701
702**Example**
703  ```ts
704  import { BusinessError } from '@kit.BasicServicesKit';
705
706  try {
707    let entityRecognizer: i18n.EntityRecognizer = new i18n.EntityRecognizer('zh-CN');
708  } catch (error) {
709    let err: BusinessError = error as BusinessError;
710    console.error(`call new i18n.EntityRecognizer failed, error code: ${err.code}, message: ${err.message}.`);
711  }
712  ```
713
714### findEntityInfo<sup>11+</sup>
715
716findEntityInfo(text: string): Array&lt;EntityInfoItem&gt;
717
718Obtains entity information in the **text** object.
719
720**Atomic service API**: This API can be used in atomic services since API version 12.
721
722**System capability**: SystemCapability.Global.I18n
723
724**Parameters**
725
726| Name | Type  | Mandatory  | Description               |
727| ---- | ---- | ---- | ----------------- |
728| text | string | Yes   | **text** object.|
729
730**Return value**
731
732| Type  | Description               |
733| ---- | ----------------- |
734| Array&lt;[EntityInfoItem](#entityinfoitem11)&gt; | List of entities in the text.|
735
736**Error codes**
737
738For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
739
740| ID | Error Message                  |
741| ------ | ---------------------- |
742| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
743
744**Example**
745  ```ts
746  import { BusinessError } from '@kit.BasicServicesKit';
747
748  try {
749    let entityRecognizer: i18n.EntityRecognizer = new i18n.EntityRecognizer('zh-CN');
750    let phoneNumberText: string = 'If you have any questions, call us by phone 12345678.';
751    // phoneNumberEntity[0].type = 'phone_number', phoneNumberEntity[0].begin = 8, phoneNumberEntity[0].end = 19
752    let phoneNumberEntity: Array<i18n.EntityInfoItem> = entityRecognizer.findEntityInfo(phoneNumberText);
753    let dateText: string = 'Let's have dinner on December 1, 2023.';
754    // dateEntity[0].type = 'date', dateEntity[0].begin = 2, dateEntity[0].end = 12
755    let dateEntity: Array<i18n.EntityInfoItem> = entityRecognizer.findEntityInfo(dateText);
756  } catch (error) {
757    let err: BusinessError = error as BusinessError;
758    console.error(`call EntityRecognizer.findEntityInfo failed, error code: ${err.code}, message: ${err.message}.`);
759  }
760  ```
761
762## EntityInfoItem<sup>11+</sup>
763
764Defines a list of entities.
765
766**Atomic service API**: This API can be used in atomic services since API version 12.
767
768**System capability**: SystemCapability.Global.I18n
769
770| Name | Type  | Read-Only  | Optional  | Description               |
771| ---- | ---- | ---- | ---- | ----------------- |
772| type | string | No   | No   | Entity type. The value can be **phone_number** or **date**. **phone_number** indicates that the entity is a phone number, and **date** indicates that the entity is a date.|
773| begin | number | No   | No   | Start position of the entity in the input string.|
774| end | number | No   | No   | End position of the entity the input string.|
775
776## Calendar<sup>8+</sup>
777
778### setTime<sup>8+</sup>
779
780setTime(date: Date): void
781
782Sets the date and time for a **Calendar** object.
783
784**Atomic service API**: This API can be used in atomic services since API version 12.
785
786**System capability**: SystemCapability.Global.I18n
787
788**Parameters**
789
790| Name | Type  | Mandatory  | Description               |
791| ---- | ---- | ---- | ----------------- |
792| date | Date | Yes   | Date and time. Note: The month starts from **0**. For example, **0** indicates January.|
793
794**Example**
795  ```ts
796  let calendar: i18n.Calendar = i18n.getCalendar('en-US', 'gregory');
797  let date: Date = new Date(2021, 10, 7, 8, 0, 0); // The date and time is 2021.11.07 08:00:00.
798  calendar.setTime(date);
799  ```
800
801
802### setTime<sup>8+</sup>
803
804setTime(time: number): void
805
806Sets the date and time for a **Calendar** object.
807
808**Atomic service API**: This API can be used in atomic services since API version 12.
809
810**System capability**: SystemCapability.Global.I18n
811
812**Parameters**
813
814| Name | Type    | Mandatory  | Description                                      |
815| ---- | ------ | ---- | ---------------------------------------- |
816| time | number | Yes   | Unix timestamp, which indicates the number of milliseconds that have elapsed since the Unix epoch.|
817
818**Example**
819  ```ts
820  let calendar: i18n.Calendar = i18n.getCalendar('en-US', 'gregory');
821  calendar.setTime(10540800000);
822  ```
823
824### set<sup>8+</sup>
825
826set(year: number, month: number, date:number, hour?: number, minute?: number, second?: number): void
827
828Sets the year, month, day, hour, minute, and second for this **Calendar** object.
829
830**Atomic service API**: This API can be used in atomic services since API version 12.
831
832**System capability**: SystemCapability.Global.I18n
833
834**Parameters**
835
836| Name   | Type    | Mandatory  | Description    |
837| ------ | ------ | ---- | ------ |
838| year   | number | Yes   | Year to set. |
839| month  | number | Yes   | Month to set. Note: The month starts from **0**. For example, **0** indicates January. |
840| date   | number | Yes   | Day to set. |
841| hour   | number | No   | Hour to set. The default value is the current system time.|
842| minute | number | No   | Minute to set. The default value is the current system time.|
843| second | number | No   | Second to set. The default value is the current system time.|
844
845**Example**
846  ```ts
847  let calendar: i18n.Calendar = i18n.getCalendar('zh-Hans');
848  calendar.set(2021, 10, 1, 8, 0, 0); // Set the date and time to 2021.11.1 08:00:00.
849  ```
850
851### setTimeZone<sup>8+</sup>
852
853setTimeZone(timezone: string): void
854
855Sets the time zone of this **Calendar** object.
856
857**Atomic service API**: This API can be used in atomic services since API version 12.
858
859**System capability**: SystemCapability.Global.I18n
860
861**Parameters**
862
863| Name     | Type    | Mandatory  | Description                       |
864| -------- | ------ | ---- | ------------------------- |
865| timezone | string | Yes   | Valid time zone ID, for example, Asia/Shanghai.|
866
867**Example**
868  ```ts
869  let calendar: i18n.Calendar = i18n.getCalendar('zh-Hans');
870  calendar.setTimeZone('Asia/Shanghai');
871  ```
872
873
874### getTimeZone<sup>8+</sup>
875
876getTimeZone(): string
877
878Obtains the time zone ID of this **Calendar** object.
879
880**Atomic service API**: This API can be used in atomic services since API version 12.
881
882**System capability**: SystemCapability.Global.I18n
883
884**Return value**
885
886| Type    | Description        |
887| ------ | ---------- |
888| string | Time zone ID.|
889
890**Example**
891  ```ts
892  let calendar: i18n.Calendar = i18n.getCalendar('zh-Hans');
893  calendar.setTimeZone('Asia/Shanghai');
894  let timezone: string = calendar.getTimeZone(); // timezone = 'Asia/Shanghai'
895  ```
896
897
898### getFirstDayOfWeek<sup>8+</sup>
899
900getFirstDayOfWeek(): number
901
902Obtains the first day of a week for this **Calendar** object.
903
904**Atomic service API**: This API can be used in atomic services since API version 12.
905
906**System capability**: SystemCapability.Global.I18n
907
908**Return value**
909
910| Type    | Description                   |
911| ------ | --------------------- |
912| number | First day of a week. The value **1** indicates Sunday, and the value **7** indicates Saturday.|
913
914**Example**
915  ```ts
916  let calendar: i18n.Calendar = i18n.getCalendar('en-US', 'gregory');
917  let firstDayOfWeek: number = calendar.getFirstDayOfWeek(); // firstDayOfWeek = 1
918  ```
919
920
921### setFirstDayOfWeek<sup>8+</sup>
922
923setFirstDayOfWeek(value: number): void
924
925Sets the first day of a week for this **Calendar** object.
926
927**Atomic service API**: This API can be used in atomic services since API version 12.
928
929**System capability**: SystemCapability.Global.I18n
930
931**Parameters**
932
933| Name  | Type    | Mandatory  | Description                   |
934| ----- | ------ | ---- | --------------------- |
935| value | number | Yes   | Start day of a week. The value **1** indicates Sunday, and the value **7** indicates Saturday.|
936
937**Example**
938  ```ts
939  let calendar: i18n.Calendar = i18n.getCalendar('zh-Hans');
940  calendar.setFirstDayOfWeek(3);
941  let firstDayOfWeek: number = calendar.getFirstDayOfWeek(); // firstDayOfWeek = 3
942  ```
943
944### getMinimalDaysInFirstWeek<sup>8+</sup>
945
946getMinimalDaysInFirstWeek(): number
947
948Obtains the minimum number of days in the first week for this **Calendar** object.
949
950**Atomic service API**: This API can be used in atomic services since API version 12.
951
952**System capability**: SystemCapability.Global.I18n
953
954**Return value**
955
956| Type    | Description          |
957| ------ | ------------ |
958| number | Minimum number of days in the first week of a year.|
959
960**Example**
961  ```ts
962  let calendar: i18n.Calendar = i18n.getCalendar('zh-Hans');
963  let minimalDaysInFirstWeek: number = calendar.getMinimalDaysInFirstWeek(); // minimalDaysInFirstWeek = 1
964  ```
965
966
967### setMinimalDaysInFirstWeek<sup>8+</sup>
968
969setMinimalDaysInFirstWeek(value: number): void
970
971Sets the minimum number of days in the first week for this **Calendar** object.
972
973**Atomic service API**: This API can be used in atomic services since API version 12.
974
975**System capability**: SystemCapability.Global.I18n
976
977**Parameters**
978
979| Name  | Type    | Mandatory  | Description          |
980| ----- | ------ | ---- | ------------ |
981| value | number | Yes   | Minimum number of days in the first week of a year.|
982
983**Example**
984  ```ts
985  let calendar: i18n.Calendar = i18n.getCalendar('zh-Hans');
986  calendar.setMinimalDaysInFirstWeek(3);
987  let minimalDaysInFirstWeek: number = calendar.getMinimalDaysInFirstWeek(); // minimalDaysInFirstWeek = 3
988  ```
989
990
991### get<sup>8+</sup>
992
993get(field: string): number
994
995Obtains the values of the calendar attributes in this **Calendar** object.
996
997**Atomic service API**: This API can be used in atomic services since API version 12.
998
999**System capability**: SystemCapability.Global.I18n
1000
1001**Parameters**
1002
1003| Name  | Type    | Mandatory  | Description                                      |
1004| ----- | ------ | ---- | ---------------------------------------- |
1005| field | string | Yes   | Calendar attributes. The following table lists the supported attribute values.|
1006
1007
1008| Name  | Description                                      |
1009| ----- | ---------------------------------------- |
1010| era | Era, for example, AD or BC.|
1011| year | Year.|
1012| month | Month. Note: The month starts from **0**. For example, **0** indicates January.|
1013| date | Date.|
1014| hour | Wall-clock hour.|
1015| hour_of_day | Hour of day.|
1016| minute | Minute.|
1017| second | Second.|
1018| millisecond | Millisecond.|
1019| week_of_year | Week of year. Note that the algorithm for calculating the first week of a year varies according to regions. For example, the first seven days in a year are the first week.|
1020| year_woy | Year used with the week of year field. |
1021| week_of_month | Week of month.|
1022| day_of_week_in_month | Day of week in month.|
1023| day_of_year | Day of year.|
1024| day_of_week | Day of week.|
1025| milliseconds_in_day | Milliseconds in day.|
1026| zone_offset | Fixed time zone offset in milliseconds (excluding DST).|
1027| dst_offset | DST offset in milliseconds.|
1028| dow_local | Localized day of week.|
1029| extended_year | Extended year, which can be a negative number.|
1030| julian_day | Julian day.|
1031| is_leap_month | Whether a month is a leap month.|
1032
1033**Return value**
1034
1035| Type    | Description                                      |
1036| ------ | ---------------------------------------- |
1037| number | Value of the calendar attribute. For example, if the year of the internal date of the current **Calendar** object is 1990, **get('year')** returns **1990**.|
1038
1039**Example**
1040  ```ts
1041  let calendar: i18n.Calendar = i18n.getCalendar('zh-Hans');
1042  calendar.set(2021, 10, 1, 8, 0, 0); // Set the date and time to 2021.11.1 08:00:00.
1043  let hourOfDay: number = calendar.get('hour_of_day'); // hourOfDay = 8
1044  ```
1045
1046
1047### getDisplayName<sup>8+</sup>
1048
1049getDisplayName(locale: string): string
1050
1051Obtains calendar display name in the specified language.
1052
1053**Atomic service API**: This API can be used in atomic services since API version 12.
1054
1055**System capability**: SystemCapability.Global.I18n
1056
1057**Parameters**
1058
1059| Name   | Type    | Mandatory  | Description                                      |
1060| ------ | ------ | ---- | ---------------------------------------- |
1061| locale | string | Yes   | [System locale](../../internationalization/i18n-locale-culture.md#how-it-works), which consists of the language, script, and country/region.|
1062
1063**Return value**
1064
1065| Type    | Description                 |
1066| ------ | ------------------- |
1067| string | Calendar display name in the specified language. For example, **buddhist** is displayed as **Buddhist Calendar** if the locale is **en-US**.|
1068
1069**Example**
1070  ```ts
1071  let calendar: i18n.Calendar = i18n.getCalendar('en-US', 'buddhist');
1072  let calendarName: string = calendar.getDisplayName('zh'); // calendarName = 'Buddhist'
1073  ```
1074
1075
1076### isWeekend<sup>8+</sup>
1077
1078isWeekend(date?: Date): boolean
1079
1080Checks whether a given date is a weekend in this **Calendar** object.
1081
1082**Atomic service API**: This API can be used in atomic services since API version 12.
1083
1084**System capability**: SystemCapability.Global.I18n
1085
1086**Parameters**
1087
1088| Name | Type  | Mandatory  | Description                                      |
1089| ---- | ---- | ---- | ---------------------------------------- |
1090| date | Date | No   | Date and time. Note: The month starts from **0**. For example, **0** indicates January.<br>The default value is current date of the **Calendar** object.|
1091
1092**Return value**
1093
1094| Type     | Description                                 |
1095| ------- | ----------------------------------- |
1096| boolean | The value **true** indicates that the specified date is a weekend, and the value **false** indicates the opposite.|
1097
1098**Example**
1099  ```ts
1100  let calendar: i18n.Calendar = i18n.getCalendar('zh-Hans');
1101  calendar.set(2021, 11, 11, 8, 0, 0); // Set the time to 2021.12.11 08:00:00.
1102  let isWeekend: boolean = calendar.isWeekend(); // isWeekend = true
1103  let date: Date = new Date(2011, 11, 6, 9, 0, 0); // The date and time is 2011-12-06 09:00:00.
1104  isWeekend = calendar.isWeekend(date); // isWeekend = false
1105  ```
1106
1107
1108### add<sup>11+</sup>
1109
1110add(field: string, amount: number): void
1111
1112Performs addition or subtraction on the calendar attributes of this **Calendar** object.
1113
1114**Atomic service API**: This API can be used in atomic services since API version 12.
1115
1116**System capability**: SystemCapability.Global.I18n
1117
1118**Parameters**
1119
1120| Name | Type  | Mandatory  | Description                                      |
1121| ---- | ---- | ---- | ---------------------------------------- |
1122| field | string | Yes   | Calendar attribute. The value can be any of the following: **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**.<br>For details about the values, see [get](#get8).|
1123| amount | number | Yes   | Addition or subtraction amount.|
1124
1125**Error codes**
1126
1127For details about the error codes, see [ohos.i18n Error Codes](errorcode-i18n.md) and [Universal Error Codes](../errorcode-universal.md).
1128
1129| ID | Error Message                  |
1130| ------ | ---------------------- |
1131| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
1132| 890001 | Invalid parameter. Possible causes: Parameter verification failed. |
1133
1134**Example**
1135  ```ts
1136  import { BusinessError } from '@kit.BasicServicesKit';
1137
1138  try {
1139    let calendar: i18n.Calendar = i18n.getCalendar('zh-Hans');
1140    calendar.set(2021, 11, 11, 8, 0, 0); // Set the date and time to 2021.12.11 08:00:00.
1141    calendar.add('year', 8); // 2021 + 8
1142    let year: number = calendar.get('year'); // year = 2029
1143  } catch (error) {
1144    let err: BusinessError = error as BusinessError;
1145    console.error(`call Calendar.add failed, error code: ${err.code}, message: ${err.message}.`);
1146  }
1147  ```
1148
1149
1150### getTimeInMillis<sup>11+</sup>
1151
1152getTimeInMillis(): number
1153
1154Obtains the timestamp of this **Calendar** object.
1155
1156**Atomic service API**: This API can be used in atomic services since API version 12.
1157
1158**System capability**: SystemCapability.Global.I18n
1159
1160**Return value**
1161
1162| Type     | Description                                 |
1163| ------- | ----------------------------------- |
1164| number | Unix timestamp, which indicates the number of milliseconds that have elapsed since the Unix epoch.|
1165
1166**Example**
1167  ```ts
1168  let calendar: i18n.Calendar = i18n.getCalendar('zh-Hans');
1169  calendar.setTime(5000);
1170  let millisecond: number = calendar.getTimeInMillis(); // millisecond = 5000
1171  ```
1172
1173
1174### compareDays<sup>11+</sup>
1175
1176compareDays(date: Date): number
1177
1178Compares the current date of this **Calendar** object with the specified date for the difference in the number of days.
1179
1180**Atomic service API**: This API can be used in atomic services since API version 12.
1181
1182**System capability**: SystemCapability.Global.I18n
1183
1184**Parameters**
1185
1186| Name | Type  | Mandatory  | Description                                      |
1187| ---- | ---- | ---- | ---------------------------------------- |
1188| date | Date | Yes   | Date and time. Note: The month starts from **0**. For example, **0** indicates January.|
1189
1190**Return value**
1191
1192| Type     | Description                                 |
1193| ------- | ----------------------------------- |
1194| number | Difference in the number of days. A positive number indicates that the calendar date is earlier, and a negative number indicates the opposite.<br>The value is accurate to milliseconds. If the value is less than one day, it is considered as one day.|
1195
1196**Error codes**
1197
1198For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1199
1200| ID | Error Message                  |
1201| ------ | ---------------------- |
1202| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
1203
1204**Example**
1205  ```ts
1206  import { BusinessError } from '@kit.BasicServicesKit';
1207
1208  try {
1209    let calendar: i18n.Calendar = i18n.getCalendar('zh-Hans');
1210    calendar.setTime(5000);
1211    let date: Date = new Date(6000);
1212    let diff: number = calendar.compareDays(date); // diff = 1
1213  } catch (error) {
1214    let err: BusinessError = error as BusinessError;
1215    console.error(`call Calendar.compareDays failed, error code: ${err.code}, message: ${err.message}.`);
1216  }
1217  ```
1218
1219## PhoneNumberFormat<sup>8+</sup>
1220
1221
1222### constructor<sup>8+</sup>
1223
1224constructor(country: string, options?: PhoneNumberFormatOptions)
1225
1226Creates a **PhoneNumberFormat** object.
1227
1228**Atomic service API**: This API can be used in atomic services since API version 12.
1229
1230**System capability**: SystemCapability.Global.I18n
1231
1232**Parameters**
1233
1234| Name    | Type                                      | Mandatory  | Description              |
1235| ------- | ---------------------------------------- | ---- | ---------------- |
1236| country | string                                   | Yes   | Country/region to which the phone number to be formatted belongs.|
1237| options | [PhoneNumberFormatOptions](#phonenumberformatoptions8) | No   | Options for **PhoneNumberFormat** object initialization. The default value is **NATIONAL**. |
1238
1239**Example**
1240  ```ts
1241  let option: i18n.PhoneNumberFormatOptions = { type: 'E164' };
1242  let phoneNumberFormat: i18n.PhoneNumberFormat = new i18n.PhoneNumberFormat('CN', option);
1243  ```
1244
1245### isValidNumber<sup>8+</sup>
1246
1247isValidNumber(number: string): boolean
1248
1249Checks whether the phone number is valid for the country/region in the **PhoneNumberFormat** object.
1250
1251**Atomic service API**: This API can be used in atomic services since API version 12.
1252
1253**System capability**: SystemCapability.Global.I18n
1254
1255**Parameters**
1256
1257| Name   | Type    | Mandatory  | Description       |
1258| ------ | ------ | ---- | --------- |
1259| number | string | Yes   | Phone number to be checked.|
1260
1261**Return value**
1262
1263| Type     | Description                                   |
1264| ------- | ------------------------------------- |
1265| boolean | Whether the phone number is valid. The value **true** indicates that the phone number is valid, and the value **false** indicates the opposite.|
1266
1267**Example**
1268  ```ts
1269  let formatter: i18n.PhoneNumberFormat = new i18n.PhoneNumberFormat('CN');
1270  let isValidNumber: boolean = formatter.isValidNumber('158****2312'); // isValidNumber = true
1271  ```
1272
1273
1274### format<sup>8+</sup>
1275
1276format(number: string): string
1277
1278Formats a phone number.
1279
1280> **Description**
1281> Formatting dialed phone numbers is supported since API version 12.
1282
1283**Atomic service API**: This API can be used in atomic services since API version 12.
1284
1285**System capability**: SystemCapability.Global.I18n
1286
1287**Parameters**
1288
1289| Name   | Type    | Mandatory  | Description        |
1290| ------ | ------ | ---- | ---------- |
1291| number | string | Yes   | Phone number to be formatted.|
1292
1293**Return value**
1294
1295| Type    | Description        |
1296| ------ | ---------- |
1297| string | Formatted phone number.|
1298
1299**Example**
1300  ```ts
1301  let formatter: i18n.PhoneNumberFormat = new i18n.PhoneNumberFormat('CN');
1302  // formattedPhoneNumber = '158 **** 2312'
1303  let formattedPhoneNumber: string = formatter.format('158****2312');
1304
1305  // Format the phone number being dialed.
1306  let option: i18n.PhoneNumberFormatOptions = { type: 'TYPING' };
1307  let typingFormatter: i18n.PhoneNumberFormat = new i18n.PhoneNumberFormat('CN', option);
1308  let phoneNumber: string = '130493';
1309  let formatResult: string = '';
1310  for (let i = 0; i < phoneNumber.length; i++) {
1311    formatResult += phoneNumber.charAt(i);
1312    formatResult = typingFormatter.format(formatResult); // formatResult = '130 493'
1313  }
1314  ```
1315
1316### getLocationName<sup>9+</sup>
1317
1318getLocationName(number: string, locale: string): string
1319
1320Obtains the home location of a phone number.
1321
1322**Atomic service API**: This API can be used in atomic services since API version 12.
1323
1324**System capability**: SystemCapability.Global.I18n
1325
1326**Parameters**
1327
1328| Name   | Type    | Mandatory  | Description  |
1329| ------ | ------ | ---- | ---- |
1330| number | string | Yes   | Phone number. To obtain the home location of a number in other countries/regions, you need to prefix the number with **00** and the country code.|
1331| locale | string | Yes   | [System locale](../../internationalization/i18n-locale-culture.md#how-it-works), which consists of the language, script, and country/region.|
1332
1333**Return value**
1334
1335| Type    | Description      |
1336| ------ | -------- |
1337| string | Home location of the phone number. If the number is invalid, an empty string is returned.|
1338
1339**Example**
1340  ```ts
1341  let phonenumberFormat: i18n.PhoneNumberFormat = new i18n.PhoneNumberFormat('CN');
1342  let locationName: string = phonenumberFormat.getLocationName('158****2345', 'zh-CN'); // locationName = 'Zhanjiang, Guangdong Province'
1343  let locName: string = phonenumberFormat.getLocationName('0039312****789', 'zh-CN'); // locName = 'Italy'
1344  ```
1345
1346
1347## PhoneNumberFormatOptions<sup>8+</sup>
1348
1349Options for **PhoneNumberFormat** object initialization.
1350
1351**Atomic service API**: This API can be used in atomic services since API version 12.
1352
1353**System capability**: SystemCapability.Global.I18n
1354
1355| Name  | Type    | Read-Only  | Optional  | Description                                      |
1356| ---- | ------ | ---- | ---- | ---------------------------------------- |
1357| type | string | No   | Yes   | Type of the phone number. The value can be **E164**, **INTERNATIONAL**, **NATIONAL**, **RFC3966**, or **TYPING**.<br>- In API version 8, **type** is mandatory.<br>- In API version 9 or later, **type** is optional.<br>- In API version 12 or later, TYPING is supported, which indicates that the dialed number is formatted in real time.|
1358
1359
1360## UnitInfo<sup>8+</sup>
1361
1362Defines the measurement unit information.
1363
1364**Atomic service API**: This API can be used in atomic services since API version 12.
1365
1366**System capability**: SystemCapability.Global.I18n
1367
1368| Name           | Type    | Read-Only  | Optional  | Description                                      |
1369| ------------- | ------ | ---- | ---- | ---------------------------------------- |
1370| unit          | string | No   | No   | Name of the measurement unit, for example, **meter**, **inch**, or **cup**.|
1371| measureSystem | string | No   | No   | Measurement system. The value can be **SI**, **US**, or **UK**.|
1372
1373
1374## i18n.getInstance<sup>8+</sup>
1375
1376getInstance(locale?: string): IndexUtil
1377
1378Creates an **IndexUtil** object.
1379
1380**Atomic service API**: This API can be used in atomic services since API version 12.
1381
1382**System capability**: SystemCapability.Global.I18n
1383
1384**Parameters**
1385
1386| Name   | Type    | Mandatory  | Description                          |
1387| ------ | ------ | ---- | ---------------------------- |
1388| locale | string | No   | [System locale](../../internationalization/i18n-locale-culture.md#how-it-works), which consists of the language, script, and country/region.<br>The default value is the current system locale.|
1389
1390**Return value**
1391
1392| Type                      | Description                   |
1393| ------------------------ | --------------------- |
1394| [IndexUtil](#indexutil8) | **IndexUtil** object created based on the specified locale ID.|
1395
1396**Example**
1397  ```ts
1398  let indexUtil: i18n.IndexUtil = i18n.getInstance('zh-CN');
1399  ```
1400
1401
1402## IndexUtil<sup>8+</sup>
1403
1404
1405### getIndexList<sup>8+</sup>
1406
1407getIndexList(): Array&lt;string&gt;
1408
1409Obtains the index list of the current locale.
1410
1411**Atomic service API**: This API can be used in atomic services since API version 12.
1412
1413**System capability**: SystemCapability.Global.I18n
1414
1415**Return value**
1416
1417| Type                 | Description                |
1418| ------------------- | ------------------ |
1419| Array&lt;string&gt; | Index list of the current locale. The first and last elements are **...**.|
1420
1421**Example**
1422  ```ts
1423  let indexUtil: i18n.IndexUtil = i18n.getInstance('zh-CN');
1424  // indexList = [ '...', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
1425  //              'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '...' ]
1426  let indexList: Array<string> = indexUtil.getIndexList();
1427  ```
1428
1429
1430### addLocale<sup>8+</sup>
1431
1432addLocale(locale: string): void
1433
1434Adds the index list of a new locale to the index list of the current locale to form a composite list.
1435
1436**Atomic service API**: This API can be used in atomic services since API version 12.
1437
1438**System capability**: SystemCapability.Global.I18n
1439
1440**Parameters**
1441
1442| Name   | Type    | Mandatory  | Description                          |
1443| ------ | ------ | ---- | ---------------------------- |
1444| locale | string | Yes   | [System locale](../../internationalization/i18n-locale-culture.md#how-it-works), which consists of the language, script, and country/region.|
1445
1446**Example**
1447  ```ts
1448  let indexUtil: i18n.IndexUtil = i18n.getInstance('zh-CN');
1449  indexUtil.addLocale('en-US');
1450  ```
1451
1452### getIndex<sup>8+</sup>
1453
1454getIndex(text: string): string
1455
1456Obtains the index of the **text** object.
1457
1458**Atomic service API**: This API can be used in atomic services since API version 12.
1459
1460**System capability**: SystemCapability.Global.I18n
1461
1462**Parameters**
1463
1464| Name | Type    | Mandatory  | Description          |
1465| ---- | ------ | ---- | ------------ |
1466| text | string | Yes   | **text** object.|
1467
1468**Return value**
1469
1470| Type    | Description         |
1471| ------ | ----------- |
1472| string | Index of the **text** object. If no proper index is found, an empty string is returned.|
1473
1474**Example**
1475  ```ts
1476  let indexUtil: i18n.IndexUtil = i18n.getInstance('zh-CN');
1477  let index: string = indexUtil.getIndex('hi'); // index = 'H'
1478  ```
1479
1480
1481## i18n.getLineInstance<sup>8+</sup>
1482
1483getLineInstance(locale: string): BreakIterator
1484
1485Obtains a **BreakIterator** object. The **BreakIterator** object maintains an internal break iterator that can be used to access various line break points.
1486
1487**Atomic service API**: This API can be used in atomic services since API version 12.
1488
1489**System capability**: SystemCapability.Global.I18n
1490
1491**Parameters**
1492
1493| Name   | Type    | Mandatory  | Description                                      |
1494| ------ | ------ | ---- | ---------------------------------------- |
1495| locale | string | Yes   | [System locale](../../internationalization/i18n-locale-culture.md#how-it-works), which consists of the language, script, and country/region.<br>The generated [BreakIterator](#breakiterator8) object calculates the positions of line breaks based on the rules of the specified locale.|
1496
1497**Return value**
1498
1499| Type                              | Description         |
1500| -------------------------------- | ----------- |
1501| [BreakIterator](#breakiterator8) | **BreakIterator** object.|
1502
1503**Example**
1504  ```ts
1505  let iterator: i18n.BreakIterator = i18n.getLineInstance('en');
1506  ```
1507
1508
1509## BreakIterator<sup>8+</sup>
1510
1511
1512### setLineBreakText<sup>8+</sup>
1513
1514setLineBreakText(text: string): void
1515
1516Sets the text to be processed by the **BreakIterator** object.
1517
1518**Atomic service API**: This API can be used in atomic services since API version 12.
1519
1520**System capability**: SystemCapability.Global.I18n
1521
1522**Parameters**
1523
1524| Name | Type    | Mandatory  | Description                     |
1525| ---- | ------ | ---- | ----------------------- |
1526| text | string | Yes   | Input text.|
1527
1528**Example**
1529  ```ts
1530  let iterator: i18n.BreakIterator = i18n.getLineInstance('en');
1531  iterator.setLineBreakText('Apple is my favorite fruit.'); // Set the text to be processed.
1532  ```
1533
1534
1535### getLineBreakText<sup>8+</sup>
1536
1537getLineBreakText(): string
1538
1539Obtains the text processed by the **BreakIterator** object.
1540
1541**Atomic service API**: This API can be used in atomic services since API version 12.
1542
1543**System capability**: SystemCapability.Global.I18n
1544
1545**Return value**
1546
1547| Type    | Description                    |
1548| ------ | ---------------------- |
1549| string | Text being processed by the **BreakIterator** object.|
1550
1551**Example**
1552  ```ts
1553  let iterator: i18n.BreakIterator = i18n.getLineInstance('en');
1554  iterator.setLineBreakText('Apple is my favorite fruit.');
1555  let breakText: string = iterator.getLineBreakText(); // breakText = 'Apple is my favorite fruit.'
1556  ```
1557
1558
1559### current<sup>8+</sup>
1560
1561current(): number
1562
1563Obtains the position of the break iterator in the text.
1564
1565**Atomic service API**: This API can be used in atomic services since API version 12.
1566
1567**System capability**: SystemCapability.Global.I18n
1568
1569**Return value**
1570
1571| Type    | Description                         |
1572| ------ | --------------------------- |
1573| number | Position of the break iterator in the text.|
1574
1575**Example**
1576  ```ts
1577  let iterator: i18n.BreakIterator = i18n.getLineInstance('en');
1578  iterator.setLineBreakText('Apple is my favorite fruit.');
1579  let currentPos: number = iterator.current(); // currentPos = 0
1580  ```
1581
1582
1583### first<sup>8+</sup>
1584
1585first(): number
1586
1587Moves the break iterator to the first line break point, which is always at the beginning of the processed text.
1588
1589**Atomic service API**: This API can be used in atomic services since API version 12.
1590
1591**System capability**: SystemCapability.Global.I18n
1592
1593**Return value**
1594
1595| Type    | Description               |
1596| ------ | ----------------- |
1597| number | Offset of the first line break point in the processed text.|
1598
1599**Example**
1600  ```ts
1601  let iterator: i18n.BreakIterator = i18n.getLineInstance('en');
1602  iterator.setLineBreakText('Apple is my favorite fruit.');
1603  let firstPos: number = iterator.first(); // firstPos = 0
1604  ```
1605
1606
1607### last<sup>8+</sup>
1608
1609last(): number
1610
1611Moves the break iterator to the last line break point, which is always the next position after the end of the processed text.
1612
1613**Atomic service API**: This API can be used in atomic services since API version 12.
1614
1615**System capability**: SystemCapability.Global.I18n
1616
1617**Return value**
1618
1619| Type    | Description                |
1620| ------ | ------------------ |
1621| number | Offset of the last line break point in the processed text.|
1622
1623**Example**
1624  ```ts
1625  let iterator: i18n.BreakIterator = i18n.getLineInstance('en');
1626  iterator.setLineBreakText('Apple is my favorite fruit.');
1627  let lastPos: number = iterator.last(); // lastPos = 27
1628  ```
1629
1630
1631### next<sup>8+</sup>
1632
1633next(index?: number): number
1634
1635Moves the break iterator backward by the specified number of line break points.
1636
1637**Atomic service API**: This API can be used in atomic services since API version 12.
1638
1639**System capability**: SystemCapability.Global.I18n
1640
1641**Parameters**
1642
1643| Name  | Type    | Mandatory  | Description                                      |
1644| ----- | ------ | ---- | ---------------------------------------- |
1645| index | number | No   | Number of line break points for moving the break iterator. The value is an integer.<br>A positive number means to move the break iterator backward, and a negative number means to move the break iterator forward.<br>The default value is **1**.|
1646
1647**Return value**
1648
1649| Type    | Description                                      |
1650| ------ | ---------------------------------------- |
1651| number | Position of the break iterator in the text after movement.<br>The value **-1** is returned if the position of the break iterator is outside of the processed text after movement.|
1652
1653**Example**
1654  ```ts
1655  let iterator: i18n.BreakIterator = i18n.getLineInstance('en');
1656  iterator.setLineBreakText('Apple is my favorite fruit.');
1657  let pos: number = iterator.first(); // pos = 0
1658  pos = iterator.next(); // pos = 6
1659  pos = iterator.next(10); // pos = -1
1660  ```
1661
1662
1663### previous<sup>8+</sup>
1664
1665previous(): number
1666
1667Moves the break iterator foreward by one line break point.
1668
1669**Atomic service API**: This API can be used in atomic services since API version 12.
1670
1671**System capability**: SystemCapability.Global.I18n
1672
1673**Return value**
1674
1675| Type    | Description                                      |
1676| ------ | ---------------------------------------- |
1677| number | Position of the break iterator in the text after movement.<br>The value **-1** is returned if the position of the break iterator is outside of the processed text after movement.|
1678
1679**Example**
1680  ```ts
1681  let iterator: i18n.BreakIterator = i18n.getLineInstance('en');
1682  iterator.setLineBreakText('Apple is my favorite fruit.');
1683  let pos: number = iterator.first(); // pos = 0
1684  pos = iterator.next(3); // pos = 12
1685  pos = iterator.previous(); // pos = 9
1686  ```
1687
1688
1689### following<sup>8+</sup>
1690
1691following(offset: number): number
1692
1693Moves the line break iterator to the line break point after the specified position.
1694
1695**Atomic service API**: This API can be used in atomic services since API version 12.
1696
1697**System capability**: SystemCapability.Global.I18n
1698
1699**Parameters**
1700
1701| Name   | Type    | Mandatory  | Description                                      |
1702| ------ | ------ | ---- | ---------------------------------------- |
1703| offset | number | Yes   | Offset of the line break point.|
1704
1705**Return value**
1706
1707| Type    | Description                                      |
1708| ------ | ---------------------------------------- |
1709| number | Position of the break iterator in the text after movement. The value **-1** is returned if the position of the break iterator is outside of the processed text after movement.|
1710
1711**Example**
1712  ```ts
1713  let iterator: i18n.BreakIterator = i18n.getLineInstance('en');
1714  iterator.setLineBreakText('Apple is my favorite fruit.');
1715  let pos: number = iterator.following(0); // pos = 6
1716  pos = iterator.following(100); // pos = -1
1717  pos = iterator.current(); // pos = 27
1718  ```
1719
1720
1721### isBoundary<sup>8+</sup>
1722
1723isBoundary(offset: number): boolean
1724
1725Checks whether the specified position is a line break point.
1726
1727**Atomic service API**: This API can be used in atomic services since API version 12.
1728
1729**System capability**: SystemCapability.Global.I18n
1730
1731**Parameters**
1732
1733| Name   | Type    | Mandatory  | Description         |
1734| ------ | ------ | ---- | ----------- |
1735| offset | number | Yes   | Specified position in the text.|
1736
1737**Return value**
1738
1739| Type     | Description                             |
1740| ------- | ------------------------------- |
1741| boolean | Whether the specified position is a line break point. The value **true** indicates that the specified position is a line break point, and the value **false** indicates the opposite.<br>If **true** is returned, the break iterator is moved to the position specified by **offset**. Otherwise, the break iterator is moved to the text line break point after the position specified by **offset**, which is equivalent to calling **following**.|
1742
1743**Example**
1744  ```ts
1745  let iterator: i18n.BreakIterator = i18n.getLineInstance('en');
1746  iterator.setLineBreakText('Apple is my favorite fruit.');
1747  let isBoundary: boolean = iterator.isBoundary(0); // isBoundary = true;
1748  isBoundary = iterator.isBoundary(5); // isBoundary = false;
1749  ```
1750
1751
1752## i18n.getTimeZone
1753
1754getTimeZone(zoneID?: string): TimeZone
1755
1756Obtains the **TimeZone** object corresponding to the specified time zone ID.
1757
1758**Atomic service API**: This API can be used in atomic services since API version 12.
1759
1760**System capability**: SystemCapability.Global.I18n
1761
1762**Parameters**
1763
1764| Name   | Type    | Mandatory  | Description   |
1765| ------ | ------ | ---- | ----- |
1766| zoneID | string | No   | Time zone ID. The default value is the system time zone.|
1767
1768**Return value**
1769
1770| Type      | Description          |
1771| -------- | ------------ |
1772| [TimeZone](#timezone) | **TimeZone** object corresponding to the time zone ID.|
1773
1774**Example**
1775  ```ts
1776  let timezone: i18n.TimeZone = i18n.getTimeZone('Asia/Shanghai');
1777  ```
1778
1779## TimeZone
1780
1781### getID
1782
1783getID(): string
1784
1785Obtains the ID of the specified **TimeZone** object.
1786
1787**Atomic service API**: This API can be used in atomic services since API version 12.
1788
1789**System capability**: SystemCapability.Global.I18n
1790
1791**Return value**
1792
1793| Type    | Description          |
1794| ------ | ------------ |
1795| string | Time zone ID corresponding to the **TimeZone** object.|
1796
1797**Example**
1798  ```ts
1799  let timezone: i18n.TimeZone = i18n.getTimeZone('Asia/Shanghai');
1800  let timezoneID: string = timezone.getID(); // timezoneID = 'Asia/Shanghai'
1801  ```
1802
1803
1804### getDisplayName
1805
1806getDisplayName(locale?: string, isDST?: boolean): string
1807
1808Obtains time zone display name in the specified language.
1809
1810**Atomic service API**: This API can be used in atomic services since API version 12.
1811
1812**System capability**: SystemCapability.Global.I18n
1813
1814**Parameters**
1815
1816| Name   | Type     | Mandatory  | Description                  |
1817| ------ | ------- | ---- | -------------------- |
1818| locale | string  | No   | [System locale](../../internationalization/i18n-locale-culture.md#how-it-works), which consists of the language, script, and country/region. The default value is the current system locale.               |
1819| isDST  | boolean | No   | Whether DST information is displayed. The value **true** indicates that DST information is displayed, and the value **false** indicates the opposite. The default value is **false**.|
1820
1821**Return value**
1822
1823| Type    | Description           |
1824| ------ | ------------- |
1825| string | Time zone display name in the specified language.|
1826
1827**Example**
1828  ```ts
1829  let timezone: i18n.TimeZone = i18n.getTimeZone('Asia/Shanghai');
1830  let timezoneName: string = timezone.getDisplayName('zh-CN', false); // timezoneName = 'China Standard Time'
1831  ```
1832
1833
1834### getRawOffset
1835
1836getRawOffset(): number
1837
1838Obtains the raw offset of the specified time zone.
1839
1840**Atomic service API**: This API can be used in atomic services since API version 12.
1841
1842**System capability**: SystemCapability.Global.I18n
1843
1844**Return value**
1845
1846| Type    | Description                 |
1847| ------ | ------------------- |
1848| number | Raw offset of the time zone, in milliseconds.|
1849
1850**Example**
1851  ```ts
1852  let timezone: i18n.TimeZone = i18n.getTimeZone('Asia/Shanghai');
1853  let offset: number = timezone.getRawOffset(); // offset = 28800000
1854  ```
1855
1856
1857### getOffset
1858
1859getOffset(date?: number): number
1860
1861Obtains the offset of the specified time zone at the specified time.
1862
1863**Atomic service API**: This API can be used in atomic services since API version 12.
1864
1865**System capability**: SystemCapability.Global.I18n
1866
1867**Parameters**
1868
1869| Name   | Type    | Mandatory  | Description    |
1870| ------ | ------ | ---- | ------ |
1871| date | number | No   | Specified time, in milliseconds. The default value is the system time.|
1872
1873**Return value**
1874
1875| Type    | Description                     |
1876| ------ | ----------------------- |
1877| number | Time zone offset, in milliseconds. When the DST is used, the time zone offset is the raw time zone offset plus the DST offset.|
1878
1879**Example**
1880  ```ts
1881  let timezone: i18n.TimeZone = i18n.getTimeZone('Asia/Shanghai');
1882  let offset: number = timezone.getOffset(1234567890); // offset = 28800000
1883  ```
1884
1885
1886### getAvailableIDs<sup>9+</sup>
1887
1888static getAvailableIDs(): Array&lt;string&gt;
1889
1890Obtains the list of time zone IDs supported by the system.
1891
1892**Atomic service API**: This API can be used in atomic services since API version 12.
1893
1894**System capability**: SystemCapability.Global.I18n
1895
1896**Return value**
1897
1898| Type                 | Description         |
1899| ------------------- | ----------- |
1900| Array&lt;string&gt; | List of time zone IDs supported by the system.|
1901
1902**Example**
1903  ```ts
1904  // 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']
1905  let ids: Array<string> = i18n.TimeZone.getAvailableIDs();
1906  ```
1907
1908
1909### getAvailableZoneCityIDs<sup>9+</sup>
1910
1911static getAvailableZoneCityIDs(): Array&lt;string&gt;
1912
1913Obtains the list of time zone city IDs supported by the system.
1914
1915**Atomic service API**: This API can be used in atomic services since API version 12.
1916
1917**System capability**: SystemCapability.Global.I18n
1918
1919**Return value**
1920
1921| Type                 | Description           |
1922| ------------------- | ------------- |
1923| Array&lt;string&gt; | List of time zone city IDs supported by the system.|
1924
1925**Example**
1926  ```ts
1927  // 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']
1928  let cityIDs: Array<string> = i18n.TimeZone.getAvailableZoneCityIDs();
1929  ```
1930
1931### getCityDisplayName<sup>9+</sup>
1932
1933static getCityDisplayName(cityID: string, locale: string): string
1934
1935Obtains time zone city display name in the specified language.
1936
1937**Atomic service API**: This API can be used in atomic services since API version 12.
1938
1939**System capability**: SystemCapability.Global.I18n
1940
1941**Parameters**
1942
1943| Name   | Type    | Mandatory  | Description    |
1944| ------ | ------ | ---- | ------ |
1945| cityID | string | Yes   | Time zone city ID.|
1946| locale | string | Yes   | [System locale](../../internationalization/i18n-locale-culture.md#how-it-works), which consists of the language, script, and country/region. |
1947
1948**Return value**
1949
1950| Type    | Description                |
1951| ------ | ------------------ |
1952| string | Time zone city display name in the specified language.|
1953
1954**Example**
1955  ```ts
1956  let displayName: string = i18n.TimeZone.getCityDisplayName('Shanghai', 'zh-CN'); // displayName = 'Shanghai (China)'
1957  ```
1958
1959
1960### getTimezoneFromCity<sup>9+</sup>
1961
1962static getTimezoneFromCity(cityID: string): TimeZone
1963
1964Creates a **TimeZone** object corresponding to the specified time zone city.
1965
1966**Atomic service API**: This API can be used in atomic services since API version 12.
1967
1968**System capability**: SystemCapability.Global.I18n
1969
1970**Parameters**
1971
1972| Name   | Type    | Mandatory  | Description    |
1973| ------ | ------ | ---- | ------ |
1974| cityID | string | Yes   | Time zone city ID. The value must be a time zone city ID supported by the system.|
1975
1976**Return value**
1977
1978| Type      | Description         |
1979| -------- | ----------- |
1980| TimeZone | **TimeZone** object corresponding to the specified time zone city ID.|
1981
1982**Example**
1983  ```ts
1984  let timezone: i18n.TimeZone = i18n.TimeZone.getTimezoneFromCity('Shanghai');
1985  ```
1986
1987### getTimezonesByLocation<sup>10+</sup>
1988
1989static getTimezonesByLocation(longitude: number, latitude: number): Array&lt;TimeZone&gt;
1990
1991Creates an array of **TimeZone** objects corresponding to the specified location.
1992
1993**Atomic service API**: This API can be used in atomic services since API version 12.
1994
1995**System capability**: SystemCapability.Global.I18n
1996
1997**Parameters**
1998
1999| Name    | Type    | Mandatory  | Description    |
2000| --------- | ------ | ---- | ------ |
2001| longitude | number | Yes   | Longitude. The value range is [-180, 179.9). A positive value is used for east longitude and a negative value is used for west longitude.|
2002| latitude  | number | Yes   | Latitude. The value range is [-90, 89.9). A positive value is used for north latitude and a negative value is used for south latitude.|
2003
2004**Return value**
2005
2006| Type      | Description         |
2007| -------- | ----------- |
2008| Array&lt;[TimeZone](#timezone)&gt; | **TimeZone** objects corresponding to the specified location.|
2009
2010**Error codes**
2011
2012For details about the error codes, see [ohos.i18n Error Codes](errorcode-i18n.md) and [Universal Error Codes](../errorcode-universal.md).
2013
2014| ID | Error Message                  |
2015| ------ | ---------------------- |
2016| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
2017| 890001 | Invalid parameter. Possible causes: Parameter verification failed. |
2018
2019
2020> **Description**
2021>
2022> The error message of 890001 is subject to the actual error.
2023
2024**Example**
2025  ```ts
2026  import { BusinessError } from '@kit.BasicServicesKit';
2027
2028  try {
2029    let timezoneArray: Array<i18n.TimeZone> = i18n.TimeZone.getTimezonesByLocation(-118.1, 34.0);
2030  } catch (error) {
2031    let err: BusinessError = error as BusinessError;
2032    console.error(`call TimeZone.getTimezonesByLocation failed, error code: ${err.code}, message: ${err.message}.`);
2033  }
2034  ```
2035
2036### getZoneRules<sup>20+</sup>
2037
2038getZoneRules(): ZoneRules
2039
2040Obtains the time zone transition rules. For details about the time zone transition logic, see [DST Transition](../../internationalization/i18n-dst-transition.md).
2041
2042**Atomic service API**: This API can be used in atomic services since API version 20.
2043
2044**System capability**: SystemCapability.Global.I18n
2045
2046**Return value**
2047
2048| Type    | Description                |
2049| ------ | ------------------ |
2050| [ZoneRules](#zonerules20) | Time zone transition rule, including the transition time and the offset before and after the transition.|
2051
2052**Example**
2053```ts
2054import { i18n } from '@kit.LocalizationKit';
2055
2056let tzId: string = 'America/Tijuana';
2057let timeZone: i18n.TimeZone = i18n.getTimeZone(tzId);
2058let zoneRules: i18n.ZoneRules = timeZone.getZoneRules();
2059let date = new Date(2025, 4, 13);
2060let zoneOffsetTransition: i18n.ZoneOffsetTransition =
2061    zoneRules.nextTransition(date.getTime()); // Obtain the ZoneOffsetTransition object for time zone transition after May 13, 2025.
2062zoneOffsetTransition.getMilliseconds(); // Timestamp of the transition point: 1762074000000
2063zoneOffsetTransition.getOffsetAfter(); // Post-transition offset: -28800000
2064zoneOffsetTransition.getOffsetBefore(); // Pre-transition offset: -25200000
2065// Format the timestamp of the transition point.
2066let dateTimeFormat: Intl.DateTimeFormat = new Intl.DateTimeFormat('en-US', {
2067  timeZone: tzId,
2068  dateStyle: 'long',
2069  timeStyle: 'long',
2070  hour12: false
2071});
2072let dateFormat: string =
2073  dateTimeFormat.format(new Date(zoneOffsetTransition.getMilliseconds())); // November 2, 2025, 1:00:00 PST
2074```
2075
2076## ZoneRules<sup>20+</sup>
2077
2078
2079### nextTransition<sup>20+</sup>
2080
2081nextTransition(date?: number): ZoneOffsetTransition
2082
2083Obtains the **nextTransition** object for the specified time.
2084
2085**Atomic service API**: This API can be used in atomic services since API version 20.
2086
2087**System capability**: SystemCapability.Global.I18n
2088
2089**Parameters**
2090
2091| Name   | Type    | Mandatory  | Description    |
2092| ------ | ------ | ---- | ------ |
2093| date | number | No   | Timestamp of next transition. It is measured as the number of milliseconds from 00:00:00 on January 1, 1970 (UTC) to the specified time, which defaults to the current system time.|
2094
2095**Return value**
2096
2097| Type      | Description        |
2098| -------- | ---------- |
2099| [ZoneOffsetTransition](#zoneoffsettransition20) | **nextTransition** object.|
2100
2101**Example**
2102```ts
2103import { i18n } from '@kit.LocalizationKit';
2104
2105// Obtain the time zone of Tijuana.
2106let timeZone: i18n.TimeZone = i18n.getTimeZone('America/Tijuana');
2107// Obtain the time zone transition rule of Tijuana.
2108let zoneRules: i18n.ZoneRules = timeZone.getZoneRules();
2109let date = new Date(2025, 4, 13);
2110// Obtain the next time zone transition for Tijuana after May 13, 2025.
2111let zoneOffsetTransition: i18n.ZoneOffsetTransition = zoneRules.nextTransition(date.getTime());
2112```
2113
2114## ZoneOffsetTransition<sup>20+</sup>
2115
2116
2117### getMilliseconds<sup>20+</sup>
2118
2119getMilliseconds(): number
2120
2121Obtains the timestamp of the time zone transition point.
2122
2123**Atomic service API**: This API can be used in atomic services since API version 20.
2124
2125**System capability**: SystemCapability.Global.I18n
2126
2127**Return value**
2128
2129| Type      | Description        |
2130| -------- | ---------- |
2131| number | Timestamp of the time zone transition point. It is measured as the number of milliseconds from 00:00:00 on January 1, 1970 (UTC) to the time zone transition point, for example, 1762074000000. If the [raw offset](#getrawoffset) remains unchanged and DST is not used, **0** is returned.|
2132
2133**Example**
2134```ts
2135import { i18n } from '@kit.LocalizationKit';
2136
2137let timeZone: i18n.TimeZone = i18n.getTimeZone('America/Tijuana');
2138let zoneRules: i18n.ZoneRules = timeZone.getZoneRules();
2139let date = new Date(2025, 4, 13);
2140let zoneOffsetTransition: i18n.ZoneOffsetTransition =
2141    zoneRules.nextTransition(date.getTime()); // Obtain the ZoneOffsetTransition object for time zone transition after May 13, 2025.
2142zoneOffsetTransition.getMilliseconds(); // Timestamp of the transition point: 1762074000000
2143```
2144
2145### getOffsetAfter<sup>20+</sup>
2146
2147getOffsetAfter(): number
2148
2149Obtains the offset after the time zone transition.
2150
2151**Atomic service API**: This API can be used in atomic services since API version 20.
2152
2153**System capability**: SystemCapability.Global.I18n
2154
2155**Return value**
2156
2157| Type      | Description        |
2158| -------- | ---------- |
2159| number | Post-transition offset, that is, the time difference between the post-transition time and UTC, measured in ms. For example, **-28800000** indicates that the time after the transition is 28800000 ms (8 hours) later than UTC.|
2160
2161**Example**
2162```ts
2163import { i18n } from '@kit.LocalizationKit';
2164
2165let timeZone: i18n.TimeZone = i18n.getTimeZone('America/Tijuana');
2166let zoneRules: i18n.ZoneRules = timeZone.getZoneRules();
2167let date = new Date(2025, 4, 13);
2168let zoneOffsetTransition: i18n.ZoneOffsetTransition =
2169    zoneRules.nextTransition(date.getTime()); // Obtain the ZoneOffsetTransition object for time zone transition after May 13, 2025.
2170zoneOffsetTransition.getOffsetAfter(); // Post-transition offset: -28800000
2171```
2172
2173### getOffsetBefore<sup>20+</sup>
2174
2175getOffsetBefore(): number
2176
2177Obtains the offset before the time zone transition.
2178
2179**Atomic service API**: This API can be used in atomic services since API version 20.
2180
2181**System capability**: SystemCapability.Global.I18n
2182
2183**Return value**
2184
2185| Type      | Description        |
2186| -------- | ---------- |
2187| number | Pre-transition offset, that is, the time difference between the pre-transition time and UTC, measured in ms. For example, **-25200000** indicates that the pre-transition time is 25200000 ms (7 hours) slower than UTC.|
2188
2189**Example**
2190```ts
2191import { i18n } from '@kit.LocalizationKit';
2192
2193let timeZone: i18n.TimeZone = i18n.getTimeZone('America/Tijuana');
2194let zoneRules: i18n.ZoneRules = timeZone.getZoneRules();
2195let date = new Date(2025, 4, 13);
2196let zoneOffsetTransition: i18n.ZoneOffsetTransition =
2197    zoneRules.nextTransition(date.getTime()); // Obtain the ZoneOffsetTransition object for time zone transition after May 13, 2025.
2198zoneOffsetTransition.getOffsetBefore(); // Pre-transition offset: -25200000
2199```
2200
2201
2202## Transliterator<sup>9+</sup>
2203
2204
2205### getAvailableIDs<sup>9+</sup>
2206
2207static getAvailableIDs(): string[]
2208
2209Obtains a list of IDs supported by the **Transliterator** object.
2210
2211**Atomic service API**: This API can be used in atomic services since API version 12.
2212
2213**System capability**: SystemCapability.Global.I18n
2214
2215**Return value**
2216
2217| Type      | Description        |
2218| -------- | ---------- |
2219| string[] | List of IDs supported by the **Transliterator** object.|
2220
2221**Example**
2222  ```ts
2223  // A total of 742 IDs are supported. One ID is comprised of two parts separated by a hyphen (-) in the format of source-destination. For example, in **ids = ["Han-Latin","Latin-ASCII", "Amharic-Latin/BGN","Accents-Any", ...]**, **Han-Latin** indicates conversion from Chinese to Latin, and **Amharic-Latin** indicates conversion from Amharic to Latin.
2224  // For more information, see ISO-15924.
2225  let ids: string[] = i18n.Transliterator.getAvailableIDs();
2226  ```
2227
2228
2229### getInstance<sup>9+</sup>
2230
2231static getInstance(id: string): Transliterator
2232
2233Creates a **Transliterator** object based on the specified ID.
2234
2235**Atomic service API**: This API can be used in atomic services since API version 12.
2236
2237**System capability**: SystemCapability.Global.I18n
2238
2239**Parameters**
2240
2241| Name | Type    | Mandatory  | Description      |
2242| ---- | ------ | ---- | -------- |
2243| id   | string | Yes   | ID supported by the **Transliterator** object.|
2244
2245**Return value**
2246
2247| Type                                | Description   |
2248| ---------------------------------- | ----- |
2249| [Transliterator](#transliterator9) | **Transliterator** object.|
2250
2251**Example**
2252  ```ts
2253  let transliterator: i18n.Transliterator = i18n.Transliterator.getInstance('Any-Latn');
2254  ```
2255
2256
2257### transform<sup>9+</sup>
2258
2259transform(text: string): string
2260
2261Converts the input text from the source format to the target format.
2262
2263**Atomic service API**: This API can be used in atomic services since API version 12.
2264
2265**System capability**: SystemCapability.Global.I18n
2266
2267**Parameters**
2268
2269| Name | Type    | Mandatory  | Description    |
2270| ---- | ------ | ---- | ------ |
2271| text | string | Yes   | **text** object.|
2272
2273**Return value**
2274
2275| Type    | Description      |
2276| ------ | -------- |
2277| string | Text after conversion.|
2278
2279**Example**
2280  ```ts
2281  let transliterator: i18n.Transliterator = i18n.Transliterator.getInstance('Any-Latn');
2282  let wordArray = ['China', 'Germany', 'US', 'France"]
2283  for (let i = 0; i < wordArray.length; i++) {
2284    let transliterLatn =
2285      transliterator.transform(wordArray[i]); // transliterLatn: 'zhōng guó', 'dé guó', 'měi guó', 'fǎ guó'
2286  }
2287
2288  // Chinese transliteration and tone removal
2289  let transliter = i18n.Transliterator.getInstance('Any-Latn;Latin-Ascii');
2290  let transliterAscii = transliter.transform('中国'); // transliterAscii ='zhong guo'
2291
2292  // Chinese surname pronunciation
2293  let nameTransliter = i18n.Transliterator.getInstance('Han-Latin/Names');
2294  let transliterNames = nameTransliter.transform('单老师'); // transliterNames = 'shàn lǎo shī'
2295  transliterNames = nameTransliter.transform('长孙无忌'); // transliterNames = 'zhǎng sūn wú jì'
2296  ```
2297
2298
2299## Unicode<sup>9+</sup>
2300
2301**Atomic service API**: This API can be used in atomic services since API version 12.
2302
2303### isDigit<sup>9+</sup>
2304
2305static isDigit(char: string): boolean
2306
2307Checks whether the input character is a digit.
2308
2309**Atomic service API**: This API can be used in atomic services since API version 12.
2310
2311**System capability**: SystemCapability.Global.I18n
2312
2313**Parameters**
2314
2315| Name | Type    | Mandatory  | Description   |
2316| ---- | ------ | ---- | ----- |
2317| char | string | Yes   | Input character. If the input is a string, only the type of the first character is checked.|
2318
2319**Return value**
2320
2321| Type     | Description                                  |
2322| ------- | ------------------------------------ |
2323| boolean | **true** if the input character is a digit, and **false** otherwise.|
2324
2325**Example**
2326  ```ts
2327  let isDigit: boolean = i18n.Unicode.isDigit('1'); // isDigit = true
2328  ```
2329
2330
2331### isSpaceChar<sup>9+</sup>
2332
2333static isSpaceChar(char: string): boolean
2334
2335Checks whether the input character is a space.
2336
2337**Atomic service API**: This API can be used in atomic services since API version 12.
2338
2339**System capability**: SystemCapability.Global.I18n
2340
2341**Parameters**
2342
2343| Name | Type    | Mandatory  | Description   |
2344| ---- | ------ | ---- | ----- |
2345| char | string | Yes   | Input character. If the input is a string, only the type of the first character is checked.|
2346
2347**Return value**
2348
2349| Type     | Description                                    |
2350| ------- | -------------------------------------- |
2351| boolean | **true** if the input character is a space, and **false** otherwise.|
2352
2353**Example**
2354  ```ts
2355  let isSpacechar: boolean = i18n.Unicode.isSpaceChar('a'); // isSpacechar = false
2356  ```
2357
2358
2359### isWhitespace<sup>9+</sup>
2360
2361static isWhitespace(char: string): boolean
2362
2363Checks whether the input character is a whitespace.
2364
2365**Atomic service API**: This API can be used in atomic services since API version 12.
2366
2367**System capability**: SystemCapability.Global.I18n
2368
2369**Parameters**
2370
2371| Name | Type    | Mandatory  | Description   |
2372| ---- | ------ | ---- | ----- |
2373| char | string | Yes   | Input character. If the input is a string, only the type of the first character is checked.|
2374
2375**Return value**
2376
2377| Type     | Description                                    |
2378| ------- | -------------------------------------- |
2379| boolean | **true** if the input character is a white space, and **false** otherwise.|
2380
2381**Example**
2382  ```ts
2383  let isWhitespace: boolean = i18n.Unicode.isWhitespace('a'); // isWhitespace = false
2384  ```
2385
2386
2387### isRTL<sup>9+</sup>
2388
2389static isRTL(char: string): boolean
2390
2391Checks whether the input character is of the right to left (RTL) language.
2392
2393**Atomic service API**: This API can be used in atomic services since API version 12.
2394
2395**System capability**: SystemCapability.Global.I18n
2396
2397**Parameters**
2398
2399| Name | Type    | Mandatory  | Description   |
2400| ---- | ------ | ---- | ----- |
2401| char | string | Yes   | Input character. If the input is a string, only the type of the first character is checked.|
2402
2403**Return value**
2404
2405| Type     | Description                                      |
2406| ------- | ---------------------------------------- |
2407| boolean | **true** if the input character is of the RTL language, and **false** otherwise.|
2408
2409**Example**
2410  ```ts
2411  let isRtl: boolean = i18n.Unicode.isRTL('a'); // isRtl = false
2412  ```
2413
2414
2415### isIdeograph<sup>9+</sup>
2416
2417static isIdeograph(char: string): boolean
2418
2419Checks whether the input character is an ideographic character.
2420
2421**Atomic service API**: This API can be used in atomic services since API version 12.
2422
2423**System capability**: SystemCapability.Global.I18n
2424
2425**Parameters**
2426
2427| Name | Type    | Mandatory  | Description   |
2428| ---- | ------ | ---- | ----- |
2429| char | string | Yes   | Input character. If the input is a string, only the type of the first character is checked.|
2430
2431**Return value**
2432
2433| Type     | Description                                      |
2434| ------- | ---------------------------------------- |
2435| boolean | **true** if the input character an ideographic character, and **false** otherwise.|
2436
2437**Example**
2438  ```ts
2439  let isIdeograph: boolean = i18n.Unicode.isIdeograph('a'); // isIdeograph = false
2440  ```
2441
2442
2443### isLetter<sup>9+</sup>
2444
2445static isLetter(char: string): boolean
2446
2447Checks whether the input character is a letter.
2448
2449**Atomic service API**: This API can be used in atomic services since API version 12.
2450
2451**System capability**: SystemCapability.Global.I18n
2452
2453**Parameters**
2454
2455| Name | Type    | Mandatory  | Description   |
2456| ---- | ------ | ---- | ----- |
2457| char | string | Yes   | Input character. If the input is a string, only the type of the first character is checked.|
2458
2459**Return value**
2460
2461| Type     | Description                                  |
2462| ------- | ------------------------------------ |
2463| boolean | **true** if the input character a letter, and **false** otherwise.|
2464
2465**Example**
2466  ```ts
2467  let isLetter: boolean = i18n.Unicode.isLetter('a'); // isLetter = true
2468  ```
2469
2470
2471### isLowerCase<sup>9+</sup>
2472
2473static isLowerCase(char: string): boolean
2474
2475Checks whether the input character is a lowercase letter.
2476
2477**Atomic service API**: This API can be used in atomic services since API version 12.
2478
2479**System capability**: SystemCapability.Global.I18n
2480
2481**Parameters**
2482
2483| Name | Type    | Mandatory  | Description   |
2484| ---- | ------ | ---- | ----- |
2485| char | string | Yes   | Input character. If the input is a string, only the type of the first character is checked.|
2486
2487**Return value**
2488
2489| Type     | Description                                      |
2490| ------- | ---------------------------------------- |
2491| boolean | **true** if the input character a lowercase letter, and **false** otherwise.|
2492
2493**Example**
2494  ```ts
2495  let isLowercase: boolean = i18n.Unicode.isLowerCase('a'); // isLowercase = true
2496  ```
2497
2498
2499### isUpperCase<sup>9+</sup>
2500
2501static isUpperCase(char: string): boolean
2502
2503Checks whether the input character is an uppercase letter.
2504
2505**Atomic service API**: This API can be used in atomic services since API version 12.
2506
2507**System capability**: SystemCapability.Global.I18n
2508
2509**Parameters**
2510
2511| Name | Type    | Mandatory  | Description   |
2512| ---- | ------ | ---- | ----- |
2513| char | string | Yes   | Input character. If the input is a string, only the type of the first character is checked.|
2514
2515**Return value**
2516
2517| Type     | Description                                      |
2518| ------- | ---------------------------------------- |
2519| boolean | **true** if the input character an uppercase letter, and **false** otherwise.|
2520
2521**Example**
2522  ```ts
2523  let isUppercase: boolean = i18n.Unicode.isUpperCase('a'); // isUppercase = false
2524  ```
2525
2526
2527### getType<sup>9+</sup>
2528
2529static getType(char: string): string
2530
2531Obtains the type of the input character.
2532
2533**Atomic service API**: This API can be used in atomic services since API version 12.
2534
2535**System capability**: SystemCapability.Global.I18n
2536
2537**Parameters**
2538
2539| Name | Type    | Mandatory  | Description   |
2540| ---- | ------ | ---- | ----- |
2541| char | string | Yes   | Input character. If the input is a string, only the type of the first character is checked.|
2542
2543**Return value**
2544
2545| Type    | Description         |
2546| ------ | ----------- |
2547| string | Type of the input character.|
2548
2549The following table lists only the common types. For more details, see the Unicode Standard.
2550
2551| Name| Value| Description|
2552| ---- | -------- | ---------- |
2553| U_UNASSIGNED | U_UNASSIGNED | Non-category for unassigned and non-character code points.|
2554| U_GENERAL_OTHER_TYPES | U_GENERAL_OTHER_TYPES | Same as **U_UNASSIGNED**.|
2555| U_UPPERCASE_LETTER | U_UPPERCASE_LETTER | Uppercase letter.|
2556| U_LOWERCASE_LETTER | U_LOWERCASE_LETTER | Lowercase letter. |
2557| U_TITLECASE_LETTER | U_TITLECASE_LETTER | Title case letter.|
2558| U_MODIFIER_LETTER | U_MODIFIER_LETTER | Modifier letter.|
2559| U_OTHER_LETTER | U_OTHER_LETTER | Letters other than the uppercase letter, lowercase letter, title case letter, and modifier letter.|
2560| U_NON_SPACING_MARK | U_NON_SPACING_MARK | Non-spacing mark, such as the accent symbol **'** and the variable symbol **#**.|
2561| U_ENCLOSING_MARK | U_ENCLOSING_MARK | Enclosing mark, for example, a circle or a box.|
2562| U_COMBINING_SPACING_MARK | U_COMBINING_SPACING_MARK | Spacing mark, for example, the vowel symbol **[]**.|
2563| U_DECIMAL_DIGIT_NUMBER | U_DECIMAL_DIGIT_NUMBER | Decimal number.|
2564| U_LETTER_NUMBER | U_LETTER_NUMBER | Letter and number (including Roman numeral).|
2565| U_OTHER_NUMBER | U_OTHER_NUMBER | Other numbers, which are used as encryption symbols, marker symbols, or non-Arabic numerals, such as **@**, **#**, **(1)**, and **①**.|
2566| U_SPACE_SEPARATOR | U_SPACE_SEPARATOR | Space separator, for example, a space character, uninterrupted space character, or space character with a fixed width.|
2567| U_LINE_SEPARATOR | U_LINE_SEPARATOR | Line separator.|
2568| U_PARAGRAPH_SEPARATOR | U_PARAGRAPH_SEPARATOR | Paragraph separator.|
2569| U_CONTROL_CHAR | U_CONTROL_CHAR | Control character.|
2570| U_FORMAT_CHAR | U_FORMAT_CHAR | Format character.|
2571| U_PRIVATE_USE_CHAR | U_PRIVATE_USE_CHAR | Privately used character, for example, a company logo.|
2572| U_SURROGATE | U_SURROGATE | Surrogate, which is used to represent supplementary characters in UTF-16.|
2573| U_DASH_PUNCTUATION | U_DASH_PUNCTUATION | Dash punctuation.|
2574| U_START_PUNCTUATION | U_START_PUNCTUATION | Start punctuation, for example, the left parenthesis.|
2575| U_END_PUNCTUATION | U_END_PUNCTUATION | End punctuation, for example, the right parenthesis.|
2576| U_INITIAL_PUNCTUATION | U_INITIAL_PUNCTUATION | Initial punctuation, for example, the left double quotation mark or left single quotation mark.|
2577| U_FINAL_PUNCTUATION | U_FINAL_PUNCTUATION | Final punctuation, for example, the right double quotation mark or right single quotation mark.|
2578| U_CONNECTOR_PUNCTUATION | U_CONNECTOR_PUNCTUATION | Connector punctuation.|
2579| U_OTHER_PUNCTUATION | U_OTHER_PUNCTUATION | Other punctuations.|
2580| U_MATH_SYMBOL | U_MATH_SYMBOL | Mathematical symbol.|
2581| U_CURRENCY_SYMBOL | U_CURRENCY_SYMBOL | Currency symbol.|
2582| U_MODIFIER_SYMBOL | U_MODIFIER_SYMBOL | Modifier symbol.|
2583| U_OTHER_SYMBOL | U_OTHER_SYMBOL | Other symbols.|
2584
2585**Example**
2586  ```ts
2587  let unicodeType: string = i18n.Unicode.getType('a'); // unicodeType = 'U_LOWERCASE_LETTER'
2588  ```
2589
2590## I18NUtil<sup>9+</sup>
2591
2592
2593### unitConvert<sup>9+</sup>
2594
2595static unitConvert(fromUnit: UnitInfo, toUnit: UnitInfo, value: number, locale: string, style?: string): string
2596
2597Converts one measurement unit into another and formats the unit based on the specified locale and style.
2598
2599**Atomic service API**: This API can be used in atomic services since API version 12.
2600
2601**System capability**: SystemCapability.Global.I18n
2602
2603**Parameters**
2604
2605| Name     | Type                    | Mandatory  | Description                                      |
2606| -------- | ---------------------- | ---- | ---------------------------------------- |
2607| fromUnit | [UnitInfo](#unitinfo8) | Yes   | Measurement unit to be converted.                                |
2608| toUnit   | [UnitInfo](#unitinfo8) | Yes   | Measurement unit to be converted to.                                |
2609| value    | number                 | Yes   | Value of the measurement unit to be converted.                            |
2610| locale   | string                 | Yes   | [Locale ID](../../internationalization/i18n-locale-culture.md#how-it-works), which consists of the language, script, and country/region, for example, **zh-Hans-CN**.               |
2611| style    | string                 | No   | Style used for formatting. The value can be **long**, **short**, or **narrow**. The default value is **short**.<br>For details about the meaning or display effect of different values, see [Number and Unit of Measurement Formatting](../../internationalization/i18n-numbers-weights-measures.md).|
2612
2613**Return value**
2614
2615| Type    | Description                     |
2616| ------ | ----------------------- |
2617| string | String converted to the measurement unit after formatting.|
2618
2619**Example**
2620  ```ts
2621  let fromUnit: i18n.UnitInfo = { unit: 'cup', measureSystem: 'US' };
2622  let toUnit: i18n.UnitInfo = { unit: 'liter', measureSystem: 'SI' };
2623  let convertResult: string =
2624    i18n.I18NUtil.unitConvert(fromUnit, toUnit, 1000, 'en-US', 'long'); // convertResult = '236.588 liters'
2625  ```
2626
2627### getDateOrder<sup>9+</sup>
2628
2629static getDateOrder(locale: string): string
2630
2631Obtains the sequence of the year, month, and day in the specified locale.
2632
2633**Atomic service API**: This API can be used in atomic services since API version 12.
2634
2635**System capability**: SystemCapability.Global.I18n
2636
2637**Parameters**
2638
2639| Name   | Type    | Mandatory  | Description                       |
2640| ------ | ------ | ---- | ------------------------- |
2641| locale | string | Yes   | [Locale ID](../../internationalization/i18n-locale-culture.md#how-it-works), which consists of the language, script, and country/region, for example, **zh-Hans-CN**.|
2642
2643**Return value**
2644
2645| Type    | Description                 |
2646| ------ | ------------------- |
2647| string | Sequence of the year, month, and day in the locale. **y** indicates the year, **L** indicates the month, and **d** indicates the day.|
2648
2649**Example**
2650  ```ts
2651  let order: string = i18n.I18NUtil.getDateOrder('zh-CN'); // order = 'y-L-d'
2652  ```
2653
2654
2655### getTimePeriodName<sup>11+</sup>
2656
2657static getTimePeriodName(hour:number, locale?: string): string
2658
2659Obtains the localized expression of the specified time in the specified locale.
2660
2661**Atomic service API**: This API can be used in atomic services since API version 12.
2662
2663**System capability**: SystemCapability.Global.I18n
2664
2665**Parameters**
2666
2667| Name   | Type    | Mandatory  | Description                       |
2668| ------ | ------ | ---- | ------------------------- |
2669| hour | number | Yes   | Specified time, for example, **16**.|
2670| locale | string | No   | [System locale](../../internationalization/i18n-locale-culture.md#how-it-works), which consists of the language, script, and country/region. for example, **zh-Hans-CN**.<br>The default value is the current system locale.|
2671
2672**Return value**
2673
2674| Type    | Description                 |
2675| ------ | ------------------- |
2676| string | Localized expression of the specified time in the specified locale.|
2677
2678**Error codes**
2679
2680For details about the error codes, see [ohos.i18n Error Codes](errorcode-i18n.md) and [Universal Error Codes](../errorcode-universal.md).
2681
2682| ID | Error Message                  |
2683| ------ | ---------------------- |
2684| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
2685| 890001 | Invalid parameter. Possible causes: Parameter verification failed. |
2686
2687**Example**
2688  ```ts
2689  import { BusinessError } from '@kit.BasicServicesKit';
2690
2691  try {
2692    let name: string = i18n.I18NUtil.getTimePeriodName(2, 'zh-CN'); // name = 'a.m.'
2693  } catch (error) {
2694    let err: BusinessError = error as BusinessError;
2695    console.error(`call I18NUtil.getTimePeriodName failed, error code: ${err.code}, message: ${err.message}.`);
2696  }
2697  ```
2698
2699### getBestMatchLocale<sup>12+</sup>
2700
2701static getBestMatchLocale(locale: string, localeList: string[]): string
2702
2703Obtains the locale that best matches a region from the specified locale list.
2704
2705**Atomic service API**: This API can be used in atomic services since API version 12.
2706
2707**System capability**: SystemCapability.Global.I18n
2708
2709**Parameters**
2710
2711| Name   | Type    | Mandatory  | Description                       |
2712| ------ | ------ | ---- | ------------------------- |
2713| locale | string | Yes   | [Locale ID](../../internationalization/i18n-locale-culture.md#how-it-works), for example, **zh-Hans-CN**.|
2714| localeList | string[] | Yes  | List of locale IDs.|
2715
2716**Return value**
2717
2718| Type    | Description                 |
2719| ------ | ------------------- |
2720| string | ID of the locale that best matches a region. If no matching locale is found, an empty string is returned.|
2721
2722**Error codes**
2723
2724For details about the error codes, see [ohos.i18n Error Codes](errorcode-i18n.md) and [Universal Error Codes](../errorcode-universal.md).
2725
2726| ID | Error Message                  |
2727| ------ | ---------------------- |
2728| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
2729| 890001 | Invalid parameter. Possible causes: Parameter verification failed. |
2730
2731**Example**
2732
2733  ```ts
2734  import { BusinessError } from '@kit.BasicServicesKit';
2735
2736  try {
2737    let matchedLocaleId: string = i18n.I18NUtil.getBestMatchLocale('zh-Hans-CN',
2738      ['en-Latn-US', 'en-GB', 'zh-Hant-CN', 'zh-Hans-MO']); // matchedLocaleId = 'zh-Hans-MO'
2739  } catch (error) {
2740    let err: BusinessError = error as BusinessError;
2741    console.error(`call I18NUtil.getBestMatchLocale failed, error code: ${err.code}, message: ${err.message}.`);
2742  }
2743  ```
2744
2745### getThreeLetterLanguage<sup>12+</sup>
2746
2747static getThreeLetterLanguage(locale: string): string
2748
2749Converts a language code from two letters to three letters.  <br>For example, the two-letter language code of Chinese is **zh**, and the corresponding three-letter language code is **zho**. For details, see [ISO 639](https://www.iso.org/iso-639-language-code).
2750
2751**Atomic service API**: This API can be used in atomic services since API version 12.
2752
2753**System capability**: SystemCapability.Global.I18n
2754
2755**Parameters**
2756
2757| Name| Type  | Mandatory| Description                    |
2758| ------ | ------ | ---- | ------------------------ |
2759| locale | string | Yes  | Two-letter code of the language to be converted, for example, **zh**.|
2760
2761**Return value**
2762
2763| Type    | Description                 |
2764| ------ | ------------------- |
2765| string | Language code after conversion.|
2766
2767**Error codes**
2768
2769For details about the error codes, see [ohos.i18n Error Codes](errorcode-i18n.md) and [Universal Error Codes](../errorcode-universal.md).
2770
2771| ID| Error Message                                                    |
2772| -------- | ------------------------------------------------------------ |
2773| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
2774| 890001   | Invalid parameter. Possible causes: Parameter verification failed. |
2775
2776**Example**
2777
2778  ```ts
2779  import { BusinessError } from '@kit.BasicServicesKit';
2780
2781  try {
2782    let language: string = i18n.I18NUtil.getThreeLetterLanguage('zh') // language = 'zho'
2783  } catch (error) {
2784    let err: BusinessError = error as BusinessError;
2785    console.error(`call I18NUtil.getThreeLetterLanguage failed, error code: ${err.code}, message: ${err.message}.`);
2786  }
2787  ```
2788
2789### getThreeLetterRegion<sup>12+</sup>
2790
2791static getThreeLetterRegion(locale: string): string
2792
2793Converts a region code from two letters to three letters.  <br>For example, the two-letter region code of China is **CN**, and the corresponding three-letter region code is **CHN**. For details, see [ISO 3166](https://www.iso.org/iso-3166-country-codes.html).
2794
2795**Atomic service API**: This API can be used in atomic services since API version 12.
2796
2797**System capability**: SystemCapability.Global.I18n
2798
2799**Parameters**
2800
2801| Name| Type  | Mandatory| Description                    |
2802| ------ | ------ | ---- | ------------------------ |
2803| locale | string | Yes  | Two-letter country/region code to be converted, for example, **CN**.|
2804
2805**Return value**
2806
2807| Type    | Description                 |
2808| ------ | ------------------- |
2809| string | Region code after conversion .|
2810
2811**Error codes**
2812
2813For details about the error codes, see [ohos.i18n Error Codes](errorcode-i18n.md) and [Universal Error Codes](../errorcode-universal.md).
2814
2815| ID| Error Message                                                    |
2816| -------- | ------------------------------------------------------------ |
2817| 401      | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
2818| 890001   | Invalid parameter. Possible causes: Parameter verification failed. |
2819
2820**Example**
2821
2822  ```ts
2823  import { BusinessError } from '@kit.BasicServicesKit';
2824
2825  try {
2826    let region: string = i18n.I18NUtil.getThreeLetterRegion('CN') // region = 'CHN'
2827  } catch (error) {
2828    let err: BusinessError = error as BusinessError;
2829    console.error(`call I18NUtil.getThreeLetterRegion failed, error code: ${err.code}, message: ${err.message}.`);
2830  }
2831  ```
2832
2833### getUnicodeWrappedFilePath<sup>20+</sup>
2834
2835static getUnicodeWrappedFilePath(path: string, delimiter?: string, locale?: Intl.Locale): string
2836
2837Localizes a file path for the specified locale.<br>For example, **/data/out/tmp** is changed to **tmp/out/data/** after localization.
2838
2839**Atomic service API**: This API can be used in atomic services since API version 20.
2840
2841**System capability**: SystemCapability.Global.I18n
2842
2843**Parameters**
2844
2845| Name| Type  | Mandatory| Description                    |
2846| ------ | ------ | ---- | ------------------------ |
2847| path | string | Yes  | Path to mirror, for example, **/data/out/tmp**.|
2848| delimiter | string | No  | Path delimiter. The default value is **/**.|
2849| locale | [Intl.Locale](https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale) | No  | **Locale** object. The default value is the current system locale.|
2850
2851**Return value**
2852
2853| Type    | Description                 |
2854| ------ | ------------------- |
2855| string | File path after localization. If the specified locale object corresponds to an RTL language, the processed file path contains a direction control character to ensure that the file path is displayed in mirror mode.|
2856
2857**Error codes**
2858
2859For details about the error codes, see [i18n Error Codes](errorcode-i18n.md).
2860
2861| ID| Error Message                                                    |
2862| -------- | ------------------------------------------------------------ |
2863| 890001   | Invalid parameter. Possible causes: Parameter verification failed. |
2864
2865**Example**
2866
2867```ts
2868import { BusinessError } from '@kit.BasicServicesKit';
2869
2870try {
2871  let path: string = '/data/out/tmp';
2872  let delimiter: string = '/';
2873  let locale: Intl.Locale = new Intl.Locale('ar');
2874  let mirrorPath: string =
2875    i18n.I18NUtil.getUnicodeWrappedFilePath(path, delimiter, locale); // mirrorPath is displayed as tmp/out/data/.
2876} catch (error) {
2877  let err: BusinessError = error as BusinessError;
2878  console.error(`call I18NUtil.getUnicodeWrappedFilePath failed, error code: ${err.code}, message: ${err.message}.`);
2879}
2880```
2881
2882### getUnicodeWrappedFilePath<sup>(deprecated)</sup>
2883
2884static getUnicodeWrappedFilePath(path: string, delimiter?: string, locale?: intl.Locale): string
2885
2886This API is supported since API version 18 and deprecated since API version 20. You are advised to use [getUnicodeWrappedFilePath](#getunicodewrappedfilepath20).
2887
2888Localizes a file path for the specified locale.<br>For example, **/data/out/tmp** is changed to **tmp/out/data/** after localization.
2889
2890**Atomic service API**: This API can be used in atomic services since API version 18.
2891
2892**System capability**: SystemCapability.Global.I18n
2893
2894**Parameters**
2895
2896| Name| Type  | Mandatory| Description                    |
2897| ------ | ------ | ---- | ------------------------ |
2898| path | string | Yes  | Path to mirror, for example, **/data/out/tmp**.|
2899| delimiter | string | No  | Path delimiter. The default value is **/**.|
2900| locale | [intl.Locale](./js-apis-intl.md#localedeprecated) | No  | **Locale** object. The default value is the current system locale.|
2901
2902**Return value**
2903
2904| Type    | Description                 |
2905| ------ | ------------------- |
2906| string | File path after localization. If the specified locale object corresponds to an RTL language, the processed file path contains a direction control character to ensure that the file path is displayed in mirror mode.|
2907
2908**Error codes**
2909
2910For details about the error codes, see [i18n Error Codes](errorcode-i18n.md).
2911
2912| ID| Error Message                                                    |
2913| -------- | ------------------------------------------------------------ |
2914| 890001   | Invalid parameter. Possible causes: Parameter verification failed. |
2915
2916**Example**
2917
2918```ts
2919import { BusinessError } from '@kit.BasicServicesKit';
2920import { intl } from '@kit.LocalizationKit';
2921
2922try {
2923  let path: string = '/data/out/tmp';
2924  let delimiter: string = '/';
2925  let locale: intl.Locale = new intl.Locale('ar');
2926  let mirrorPath: string =
2927    i18n.I18NUtil.getUnicodeWrappedFilePath(path, delimiter, locale); // mirrorPath is displayed as tmp/out/data/.
2928} catch (error) {
2929  let err: BusinessError = error as BusinessError;
2930  console.error(`call I18NUtil.getUnicodeWrappedFilePath failed, error code: ${err.code}, message: ${err.message}.`);
2931}
2932```
2933
2934## Normalizer<sup>10+</sup>
2935
2936
2937### getInstance<sup>10+</sup>
2938
2939static getInstance(mode: NormalizerMode): Normalizer
2940
2941Obtains a **Normalizer** object.
2942
2943**Atomic service API**: This API can be used in atomic services since API version 12.
2944
2945**System capability**: SystemCapability.Global.I18n
2946
2947**Parameters**
2948
2949| Name   | Type    | Mandatory  | Description                       |
2950| ------ | ------ | ---- | ------------------------- |
2951| mode | [NormalizerMode](#normalizermode10) | Yes   | Text normalization mode.|
2952
2953**Return value**
2954
2955| Type    | Description                 |
2956| ------ | ------------------- |
2957| [Normalizer](#normalizer10) | **Normalizer** object for text normalization.|
2958
2959**Error codes**
2960
2961For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2962
2963| ID | Error Message                  |
2964| ------ | ---------------------- |
2965| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
2966
2967**Example**
2968  ```ts
2969  import { BusinessError } from '@kit.BasicServicesKit';
2970
2971  try {
2972    let normalizer: i18n.Normalizer = i18n.Normalizer.getInstance(i18n.NormalizerMode.NFC);
2973  } catch (error) {
2974    let err: BusinessError = error as BusinessError;
2975    console.error(`call Normalizer.getInstance failed, error code: ${err.code}, message: ${err.message}.`);
2976  }
2977  ```
2978
2979
2980### normalize<sup>10+</sup>
2981
2982normalize(text: string): string
2983
2984Normalizes input strings.
2985
2986**Atomic service API**: This API can be used in atomic services since API version 12.
2987
2988**System capability**: SystemCapability.Global.I18n
2989
2990**Parameters**
2991
2992| Name   | Type    | Mandatory  | Description                       |
2993| ------ | ------ | ---- | ------------------------- |
2994| text | string | Yes   | **text** object.|
2995
2996**Return value**
2997
2998| Type    | Description                 |
2999| ------ | ------------------- |
3000| string | Normalized strings.|
3001
3002**Error codes**
3003
3004For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3005
3006| ID | Error Message                  |
3007| ------ | ---------------------- |
3008| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
3009
3010**Example**
3011  ```ts
3012  import { BusinessError } from '@kit.BasicServicesKit';
3013
3014  try {
3015    let normalizer: i18n.Normalizer = i18n.Normalizer.getInstance(i18n.NormalizerMode.NFC);
3016    let normalizedText: string = normalizer.normalize('\u1E9B\u0323'); // normalizedText = 'ẛ̣'
3017  } catch (error) {
3018    let err: BusinessError = error as BusinessError;
3019    console.error(`call Normalizer.getInstance failed, error code: ${err.code}, message: ${err.message}.`);
3020  }
3021  ```
3022
3023## NormalizerMode<sup>10+</sup>
3024
3025Enumerates text normalization modes.
3026
3027**Atomic service API**: This API can be used in atomic services since API version 12.
3028
3029**System capability**: SystemCapability.Global.I18n
3030
3031| Name| Value| Description|
3032| -------- | -------- | -------- |
3033| NFC | 1 | NFC.|
3034| NFD | 2 | NFD.|
3035| NFKC | 3 | NFKC.|
3036| NFKD | 4 | NFKD.|
3037
3038
3039## HolidayManager<sup>11+</sup>
3040
3041
3042### constructor<sup>11+</sup>
3043
3044constructor(icsPath: String)
3045
3046Creates a **HolidayManager** object for parsing holiday data.
3047
3048**Atomic service API**: This API can be used in atomic services since API version 12.
3049
3050**System capability**: SystemCapability.Global.I18n
3051
3052**Parameters**
3053
3054|   Name |      Type     | Mandatory|     Description     |
3055| --------- | ------------- | ---- | ------------- |
3056| icsPath   | String | Yes  | Path of the **.ics** file with the read permission granted for applications. |
3057
3058**Error codes**
3059
3060For details about the error codes, see [ohos.i18n Error Codes](errorcode-i18n.md) and [Universal Error Codes](../errorcode-universal.md).
3061
3062| ID | Error Message                  |
3063| ------ | ---------------------- |
3064| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
3065| 890001 | Invalid parameter. Possible causes: Parameter verification failed. |
3066
3067**Example**
3068  ```ts
3069  import { BusinessError } from '@kit.BasicServicesKit';
3070
3071  try {
3072    let holidayManager = new i18n.HolidayManager('/system/lib/US.ics');
3073  } catch (error) {
3074    let err: BusinessError = error as BusinessError;
3075    console.error(`call i18n.HolidayManager failed, error code: ${err.code}, message: ${err.message}.`);
3076  }
3077  ```
3078
3079### isHoliday<sup>11+</sup>
3080
3081isHoliday(date?: Date): boolean
3082
3083Determines whether the specified date is a holiday.
3084
3085**Atomic service API**: This API can be used in atomic services since API version 12.
3086
3087**System capability**: SystemCapability.Global.I18n
3088
3089**Parameters**
3090
3091|   Name |      Type     | Mandatory|     Description     |
3092| --------- | ---------------| ---- | ------------- |
3093| date      | Date           | No  | Date and time. Note: The month starts from **0**. For example, **0** indicates January.<br>The default value is the current date.|
3094
3095**Return value**
3096
3097|       Type       |         Description         |
3098| ----------------- | ----------------------|
3099| boolean           | **true** if the specified date is a holiday, and **false** otherwise.|
3100
3101**Error codes**
3102
3103For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3104
3105| ID | Error Message                  |
3106| ------ | ---------------------- |
3107| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
3108
3109**Example**
3110  ```ts
3111  import { BusinessError } from '@kit.BasicServicesKit';
3112
3113  try {
3114    // Replace /system/lib/US.ics with the actual ICS file path.
3115    let holidayManager: i18n.HolidayManager = new i18n.HolidayManager('/system/lib/US.ics');
3116    let isHoliday: boolean = holidayManager.isHoliday();
3117    isHoliday = holidayManager.isHoliday(new Date(2023, 5, 25)); // The date is 2023.06.25.
3118  } catch (error) {
3119    let err: BusinessError = error as BusinessError;
3120    console.error(`call holidayManager.isHoliday failed, error code: ${err.code}, message: ${err.message}.`);
3121  }
3122  ```
3123
3124
3125### getHolidayInfoItemArray<sup>11+</sup>
3126
3127getHolidayInfoItemArray(year?: number): Array&lt;[HolidayInfoItem](#holidayinfoitem11)&gt;
3128
3129Obtains the holiday information list of the specified year.
3130
3131**Atomic service API**: This API can be used in atomic services since API version 12.
3132
3133**System capability**: SystemCapability.Global.I18n
3134
3135**Parameters**
3136
3137|   Name |      Type     | Mandatory|     Description     |
3138| --------- | -------------  | ---- | ------------- |
3139| year      | number         | No  | Specified year, for example, 2023.<br>The default value is the current year.|
3140
3141**Return value**
3142
3143|       Type       |         Description         |
3144| ----------------- | -------------------- |
3145| Array&lt;[HolidayInfoItem](#holidayinfoitem11)&gt; | Holiday information list.|
3146
3147**Error codes**
3148
3149For details about the error codes, see [ohos.i18n Error Codes](errorcode-i18n.md) and [Universal Error Codes](../errorcode-universal.md).
3150
3151| ID | Error Message                  |
3152| ------ | ---------------------- |
3153| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
3154| 890001 | Invalid parameter. Possible causes: Parameter verification failed. |
3155
3156**Example**
3157  ```ts
3158  import { BusinessError } from '@kit.BasicServicesKit';
3159
3160  try {
3161    // Replace /system/lib/US.ics with the actual ICS file path.
3162    let holidayManager: i18n.HolidayManager = new i18n.HolidayManager('/system/lib/US.ics');
3163    let holidayInfoItemArray: Array<i18n.HolidayInfoItem> = holidayManager.getHolidayInfoItemArray(2023);
3164  } catch (error) {
3165    let err: BusinessError = error as BusinessError;
3166    console.error(`call holidayManager.getHolidayInfoItemArray failed, error code: ${err.code}, message: ${err.message}.`);
3167  }
3168  ```
3169
3170## HolidayInfoItem<sup>11+</sup>
3171
3172Represents the holiday information.
3173
3174**Atomic service API**: This API can be used in atomic services since API version 12.
3175
3176**System capability**: SystemCapability.Global.I18n
3177
3178| Name           | Type            |  Read-Only  |  Optional  |  Description                                  |
3179| --------------- | --------------- | ------  | ------  | --------------------------------------- |
3180| baseName        | string          |   No   |   No   | Holiday name.             |
3181| year            | number          |   No   |   No   | Year of the holiday.                  |
3182| month           | number          |   No   |   No   | Month of the holiday.         |
3183| day             | number          |   No   |   No   | Day of the holiday.                        |
3184| localNames      | Array&lt;[HolidayLocalName](#holidaylocalname11)&gt;          |   No   |   Yes   | Local names of the holiday.         |
3185
3186## HolidayLocalName<sup>11+</sup>
3187
3188Represents the name of a holiday in different languages.
3189
3190**Atomic service API**: This API can be used in atomic services since API version 12.
3191
3192**System capability**: SystemCapability.Global.I18n
3193
3194| Name           | Type            |  Read-Only  |  Optional  |  Description                                  |
3195| --------------- | -----------------| ------  | ------  | --------------------------------------- |
3196| language        | string           |   No   |   No   | Language, for example, **ar**, **en**, or **tr**.         |
3197| name            | string           |   No   |   No   | Local name of a holiday. For example, the Turkish name of Sacrifice Feast is Kurban Bayrami.     |
3198
3199
3200## i18n.getSimpleDateTimeFormatByPattern<sup>20+</sup>
3201
3202getSimpleDateTimeFormatByPattern(pattern: string, locale?: Intl.Locale): SimpleDateTimeFormat
3203
3204Obtains a **SimpleDateTimeFormat** object based on the specified pattern string. For details about the difference between the objects obtained by this API and [getSimpleDateTimeFormatBySkeleton](#i18ngetsimpledatetimeformatbyskeleton20), see the examples in [SimpleDateTimeFormat.format](#format18).
3205
3206**Atomic service API**: This API can be used in atomic services since API version 20.
3207
3208**System capability**: SystemCapability.Global.I18n
3209
3210**Parameters**
3211
3212| Name   | Type    | Mandatory  | Description                                      |
3213| ------- | ----------- | ----- | ---------------------------------------- |
3214| pattern | string      | Yes   | Valid pattern, which supports free combinations of field patterns in [Date Field Symbol Table](https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table). This parameter also supports custom text enclosed in single quotation marks (`''`).|
3215| locale  | [Intl.Locale](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale) | No   | **Locale** object. The default value is the current system locale.|
3216
3217**Return value**
3218
3219| Type                    | Description   |
3220| ---------------------- | ----- |
3221| [SimpleDateTimeFormat](#simpledatetimeformat18) | **SimpleDateTimeFormat** object.|
3222
3223**Error codes**
3224
3225For details about the error codes, see [i18n Error Codes](errorcode-i18n.md).
3226
3227| ID | Error Message                  |
3228| ------ | ---------------------- |
3229| 890001 | Invalid parameter. Possible causes: Parameter verification failed. |
3230
3231**Example**
3232```ts
3233import { BusinessError } from '@kit.BasicServicesKit';
3234
3235try {
3236  let locale: Intl.Locale = new Intl.Locale('zh-Hans-CN');
3237  let formatter: i18n.SimpleDateTimeFormat = i18n.getSimpleDateTimeFormatByPattern("'month('M')'", locale);
3238} catch (error) {
3239  let err: BusinessError = error as BusinessError;
3240  console.error(`call i18n.getSimpleDateTimeFormatByPattern failed, error code: ${err.code}, message: ${err.message}.`);
3241}
3242```
3243
3244## i18n.getSimpleDateTimeFormatByPattern<sup>(deprecated)</sup>
3245
3246getSimpleDateTimeFormatByPattern(pattern: string, locale?: intl.Locale): SimpleDateTimeFormat
3247
3248This API is supported since API version 18 and deprecated since API version 20. You are advised to use [getSimpleDateTimeFormatByPattern](#i18ngetsimpledatetimeformatbypattern20).
3249
3250Obtains a **SimpleDateTimeFormat** object based on the specified pattern string. For details about the difference between the objects obtained by this API and [getSimpleDateTimeFormatBySkeleton](#i18ngetsimpledatetimeformatbyskeletondeprecated), see the examples in [SimpleDateTimeFormat.format](#format18).
3251
3252**Atomic service API**: This API can be used in atomic services since API version 18.
3253
3254**System capability**: SystemCapability.Global.I18n
3255
3256**Parameters**
3257
3258| Name   | Type    | Mandatory  | Description                                      |
3259| ------- | ----------- | ----- | ---------------------------------------- |
3260| pattern | string      | Yes   | Valid pattern, which supports free combinations of field patterns in [Date Field Symbol Table](https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table). This parameter also supports custom text enclosed in single quotation marks (`''`).|
3261| locale  | [intl.Locale](./js-apis-intl.md#localedeprecated) | No   | **Locale** object. The default value is the current system locale.|
3262
3263**Return value**
3264
3265| Type                    | Description   |
3266| ---------------------- | ----- |
3267| [SimpleDateTimeFormat](#simpledatetimeformat18) | **SimpleDateTimeFormat** object.|
3268
3269**Error codes**
3270
3271For details about the error codes, see [i18n Error Codes](errorcode-i18n.md).
3272
3273| ID | Error Message                  |
3274| ------ | ---------------------- |
3275| 890001 | Invalid parameter. Possible causes: Parameter verification failed. |
3276
3277**Example**
3278```ts
3279import { BusinessError } from '@kit.BasicServicesKit';
3280import { intl } from '@kit.LocalizationKit';
3281
3282try {
3283  let locale: intl.Locale = new intl.Locale('zh-Hans-CN');
3284  let formatter: i18n.SimpleDateTimeFormat = i18n.getSimpleDateTimeFormatByPattern("'month('M')'", locale);
3285} catch (error) {
3286  let err: BusinessError = error as BusinessError;
3287  console.error(`call i18n.getSimpleDateTimeFormatByPattern failed, error code: ${err.code}, message: ${err.message}.`);
3288}
3289```
3290
3291## i18n.getSimpleDateTimeFormatBySkeleton<sup>20+</sup>
3292
3293getSimpleDateTimeFormatBySkeleton(skeleton: string, locale?: Intl.Locale): SimpleDateTimeFormat
3294
3295Obtains a **SimpleDateTimeFormat** object based on the specified skeleton. For details about the difference between the objects obtained by this API and [getSimpleDateTimeFormatByPattern](#i18ngetsimpledatetimeformatbypattern20), see the examples in [SimpleDateTimeFormat.format](#format18).
3296
3297**Atomic service API**: This API can be used in atomic services since API version 20.
3298
3299**System capability**: SystemCapability.Global.I18n
3300
3301**Parameters**
3302
3303| Name   | Type    | Mandatory  | Description                                      |
3304| ------- | ----------- | ----- | ---------------------------------------- |
3305| skeleton | string      | Yes   | Valid skeleton, which supports free combinations of field patterns in [Date Field Symbol Table](https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table). This parameter does not support custom text.|
3306| locale  | [Intl.Locale](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale) | No   | **Locale** object. The default value is the current system locale.|
3307
3308**Return value**
3309
3310| Type                    | Description   |
3311| ---------------------- | ----- |
3312| [SimpleDateTimeFormat](#simpledatetimeformat18) | **SimpleDateTimeFormat** object.|
3313
3314**Error codes**
3315
3316For details about the error codes, see [i18n Error Codes](errorcode-i18n.md).
3317
3318| ID | Error Message                  |
3319| ------ | ---------------------- |
3320| 890001 | Invalid parameter. Possible causes: Parameter verification failed. |
3321
3322**Example**
3323```ts
3324import { BusinessError } from '@kit.BasicServicesKit';
3325
3326try {
3327  let locale: Intl.Locale = new Intl.Locale('zh-Hans-CN');
3328  let formatter: i18n.SimpleDateTimeFormat = i18n.getSimpleDateTimeFormatBySkeleton('yMd', locale);
3329} catch (error) {
3330  let err: BusinessError = error as BusinessError;
3331  console.error(`call i18n.getSimpleDateTimeFormatBySkeleton failed, error code: ${err.code}, message: ${err.message}.`);
3332}
3333```
3334
3335## i18n.getSimpleDateTimeFormatBySkeleton<sup>(deprecated)</sup>
3336
3337getSimpleDateTimeFormatBySkeleton(skeleton: string, locale?: intl.Locale): SimpleDateTimeFormat
3338
3339This API is supported since API version 18 and deprecated since API version 20. You are advised to use [getSimpleDateTimeFormatBySkeleton](#i18ngetsimpledatetimeformatbyskeleton20).
3340
3341Obtains a **SimpleDateTimeFormat** object based on the specified skeleton. For details about the difference between the objects obtained by this API and [getSimpleDateTimeFormatByPattern](#i18ngetsimpledatetimeformatbypatterndeprecated), see the examples in [SimpleDateTimeFormat.format](#format18).
3342
3343**Atomic service API**: This API can be used in atomic services since API version 18.
3344
3345**System capability**: SystemCapability.Global.I18n
3346
3347**Parameters**
3348
3349| Name   | Type    | Mandatory  | Description                                      |
3350| ------- | ----------- | ----- | ---------------------------------------- |
3351| skeleton | string      | Yes   | Valid skeleton, which supports free combinations of field patterns in [Date Field Symbol Table](https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table). This parameter does not support custom text.|
3352| locale  | [intl.Locale](./js-apis-intl.md#localedeprecated) | No   | **Locale** object. The default value is the current system locale.|
3353
3354**Return value**
3355
3356| Type                    | Description   |
3357| ---------------------- | ----- |
3358| [SimpleDateTimeFormat](#simpledatetimeformat18) | **SimpleDateTimeFormat** object.|
3359
3360**Error codes**
3361
3362For details about the error codes, see [i18n Error Codes](errorcode-i18n.md).
3363
3364| ID | Error Message                  |
3365| ------ | ---------------------- |
3366| 890001 | Invalid parameter. Possible causes: Parameter verification failed. |
3367
3368**Example**
3369```ts
3370import { BusinessError } from '@kit.BasicServicesKit';
3371import { intl } from '@kit.LocalizationKit';
3372
3373try {
3374  let locale: intl.Locale = new intl.Locale('zh-Hans-CN');
3375  let formatter: i18n.SimpleDateTimeFormat = i18n.getSimpleDateTimeFormatBySkeleton('yMd', locale);
3376} catch (error) {
3377  let err: BusinessError = error as BusinessError;
3378  console.error(`call i18n.getSimpleDateTimeFormatBySkeleton failed, error code: ${err.code}, message: ${err.message}.`);
3379}
3380```
3381
3382## SimpleDateTimeFormat<sup>18+</sup>
3383
3384### format<sup>18+</sup>
3385
3386format(date: Date): string
3387
3388Formats the date and time.
3389
3390**Atomic service API**: This API can be used in atomic services since API version 18.
3391
3392**System capability**: SystemCapability.Global.I18n
3393
3394**Parameters**
3395
3396| Name | Type  | Mandatory  | Description               |
3397| ---- | ---- | ---- | ----------------- |
3398| date | Date | Yes   | Date and time. Note: The month starts from **0**. For example, **0** indicates January.|
3399
3400**Return value**
3401
3402| Type                    | Description   |
3403| ---------------------- | ----- |
3404| string | A string containing the formatted date and time.|
3405
3406**Example**
3407  ```ts
3408  import { BusinessError } from '@kit.BasicServicesKit';
3409
3410  try {
3411    let locale : Intl.Locale = new Intl.Locale("zh-Hans-CN");
3412    let date: Date = new Date(2024, 11, 13); // Set the date to 2024.12.13.
3413
3414    let formatterWithText: i18n.SimpleDateTimeFormat =
3415      i18n.getSimpleDateTimeFormatByPattern("'month('M')'", locale);
3416    let formattedDate: string = formatterWithText.format(date); // formattedDate = 'month(12)'
3417
3418    let patternFormatter: i18n.SimpleDateTimeFormat = i18n.getSimpleDateTimeFormatByPattern('yMd', locale);
3419    formattedDate = patternFormatter.format(date); // formattedDate = '20241213'
3420
3421    let skeletonFormatter: i18n.SimpleDateTimeFormat = i18n.getSimpleDateTimeFormatBySkeleton('yMd', locale);
3422    formattedDate = skeletonFormatter.format(date); // formattedDate = '2024/12/13'
3423  } catch (error) {
3424    let err: BusinessError = error as BusinessError;
3425    console.error(`call SimpleDateTimeFormat.format failed, error code: ${err.code}, message: ${err.message}.`);
3426  }
3427  ```
3428
3429
3430## i18n.getSimpleNumberFormatBySkeleton<sup>20+</sup>
3431
3432getSimpleNumberFormatBySkeleton(skeleton: string, locale?: Intl.Locale): SimpleNumberFormat
3433
3434Obtains a **SimpleNumberFormat** object based on the specified skeleton.
3435
3436**Atomic service API**: This API can be used in atomic services since API version 20.
3437
3438**System capability**: SystemCapability.Global.I18n
3439
3440**Parameters**
3441
3442| Name   | Type    | Mandatory  | Description                                      |
3443| ------- | ----------- | ----- | ---------------------------------------- |
3444| skeleton | string      | Yes   | Valid skeleton. For details about the supported characters and their meanings, see [Number Skeletons](https://unicode-org.github.io/icu/userguide/format_parse/numbers/skeletons.html#number-skeletons).|
3445| locale  | [Intl.Locale](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale) | No   | **Locale** object. The default value is the current system locale.|
3446
3447**Return value**
3448
3449| Type                    | Description   |
3450| ---------------------- | ----- |
3451| [SimpleNumberFormat](#simplenumberformat18) | **SimpleNumberFormat** object.|
3452
3453**Error codes**
3454
3455For details about the error codes, see [i18n Error Codes](errorcode-i18n.md).
3456
3457| ID | Error Message                  |
3458| ------ | ---------------------- |
3459| 890001 | Invalid parameter. Possible causes: Parameter verification failed. |
3460
3461**Example**
3462```ts
3463import { BusinessError } from '@kit.BasicServicesKit';
3464
3465try {
3466  let locale: Intl.Locale = new Intl.Locale('zh-Hans-CN');
3467  let formatter: i18n.SimpleNumberFormat = i18n.getSimpleNumberFormatBySkeleton('%', locale);
3468} catch (error) {
3469  let err: BusinessError = error as BusinessError;
3470  console.error(`call SimpleDateTimeFormat.getSimpleNumberFormatBySkeleton failed, error code: ${err.code}, message: ${err.message}.`);
3471}
3472```
3473
3474## i18n.getSimpleNumberFormatBySkeleton<sup>(deprecated)</sup>
3475
3476getSimpleNumberFormatBySkeleton(skeleton: string, locale?: intl.Locale): SimpleNumberFormat
3477
3478This API is supported since API version 18 and deprecated since API version 20. You are advised to use [getSimpleNumberFormatBySkeleton](#i18ngetsimplenumberformatbyskeleton20).
3479
3480Obtains a **SimpleNumberFormat** object based on the specified skeleton.
3481
3482**Atomic service API**: This API can be used in atomic services since API version 18.
3483
3484**System capability**: SystemCapability.Global.I18n
3485
3486**Parameters**
3487
3488| Name   | Type    | Mandatory  | Description                                      |
3489| ------- | ----------- | ----- | ---------------------------------------- |
3490| skeleton | string      | Yes   | Valid skeleton. For details about the supported characters and their meanings, see [Number Skeletons](https://unicode-org.github.io/icu/userguide/format_parse/numbers/skeletons.html#number-skeletons).|
3491| locale  | [intl.Locale](./js-apis-intl.md#localedeprecated) | No   | **Locale** object. The default value is the current system locale.|
3492
3493**Return value**
3494
3495| Type                    | Description   |
3496| ---------------------- | ----- |
3497| [SimpleNumberFormat](#simplenumberformat18) | **SimpleNumberFormat** object.|
3498
3499**Error codes**
3500
3501For details about the error codes, see [i18n Error Codes](errorcode-i18n.md).
3502
3503| ID | Error Message                  |
3504| ------ | ---------------------- |
3505| 890001 | Invalid parameter. Possible causes: Parameter verification failed. |
3506
3507**Example**
3508```ts
3509import { BusinessError } from '@kit.BasicServicesKit';
3510import { intl } from '@kit.LocalizationKit';
3511
3512try {
3513  let locale: intl.Locale = new intl.Locale('zh-Hans-CN');
3514  let formatter: i18n.SimpleNumberFormat = i18n.getSimpleNumberFormatBySkeleton('%', locale);
3515} catch (error) {
3516  let err: BusinessError = error as BusinessError;
3517  console.error(`call SimpleDateTimeFormat.getSimpleNumberFormatBySkeleton failed, error code: ${err.code}, message: ${err.message}.`);
3518}
3519```
3520
3521## SimpleNumberFormat<sup>18+</sup>
3522
3523### format<sup>18+</sup>
3524
3525format(value: number): string
3526
3527Formats a number.
3528
3529**Atomic service API**: This API can be used in atomic services since API version 18.
3530
3531**System capability**: SystemCapability.Global.I18n
3532
3533**Parameters**
3534
3535| Name | Type  | Mandatory  | Description               |
3536| ---- | ---- | ---- | ----------------- |
3537| value | number | Yes   | Number to be formatted.|
3538
3539**Return value**
3540
3541| Type                    | Description   |
3542| ---------------------- | ----- |
3543| string | Formatted number.|
3544
3545**Example**
3546```ts
3547import { BusinessError } from '@kit.BasicServicesKit';
3548
3549try {
3550  let locale: Intl.Locale = new Intl.Locale('zh-Hans-CN');
3551  let formatter: i18n.SimpleNumberFormat = i18n.getSimpleNumberFormatBySkeleton('%', locale);
3552  let formattedNumber: string = formatter.format(10); // formattedNumber = '10%'
3553} catch (error) {
3554  let err: BusinessError = error as BusinessError;
3555  console.error(`call SimpleNumberFormat.format failed, error code: ${err.code}, message: ${err.message}.`);
3556}
3557```
3558
3559## StyledNumberFormat<sup>18+</sup>
3560
3561### constructor<sup>18+</sup>
3562
3563constructor(numberFormat: intl.NumberFormat | SimpleNumberFormat, options?: StyledNumberFormatOptions)
3564
3565Creates a **NumberFormat** object for rich text display.
3566
3567**Atomic service API**: This API can be used in atomic services since API version 18.
3568
3569**System capability**: SystemCapability.Global.I18n
3570
3571**Parameters**
3572
3573|   Name |      Type     | Mandatory|     Description     |
3574| --------- | ------------- | ---- | ------------- |
3575| numberFormat | [intl.NumberFormat](js-apis-intl.md#numberformat) \| [SimpleNumberFormat](#simplenumberformat18) | Yes  | **NumberFormat** object. |
3576| options | [StyledNumberFormatOptions](#stylednumberformatoptions18) | No| Configuration options of the **NumberFormat** object. The default value is the default text style. |
3577
3578**Example**
3579  ```ts
3580  import { BusinessError } from '@kit.BasicServicesKit';
3581  import { intl } from '@kit.LocalizationKit';
3582
3583  try {
3584    let integerTextStyle: TextStyle = new TextStyle({ fontColor: Color.Red });
3585    let decimalTextStyle: TextStyle = new TextStyle({ fontColor: Color.Brown });
3586    let fractionTextStyle: TextStyle = new TextStyle({ fontColor: Color.Blue });
3587    let unitTextStyle: TextStyle = new TextStyle({ fontColor: Color.Green });
3588
3589    // Create a StyledNumberFormat object through intl.NumberFormat.
3590    let numFmt: intl.NumberFormat = new intl.NumberFormat('zh', { style: 'unit', unit: 'percent' });
3591    let styledNumFmt: i18n.StyledNumberFormat = new i18n.StyledNumberFormat(numFmt, {
3592      integer: integerTextStyle,
3593      decimal: decimalTextStyle,
3594      fraction: fractionTextStyle,
3595      unit: unitTextStyle
3596    });
3597
3598    // Create a StyledNumberFormat object through SimpleNumberFormat.
3599    let locale: intl.Locale = new intl.Locale('zh');
3600    let simpleNumFmt: i18n.SimpleNumberFormat = i18n.getSimpleNumberFormatBySkeleton('percent', locale);
3601    let styledSimpleNumFmt: i18n.StyledNumberFormat = new i18n.StyledNumberFormat(simpleNumFmt, {
3602      integer: integerTextStyle,
3603      decimal: decimalTextStyle,
3604      fraction: fractionTextStyle,
3605      unit: unitTextStyle
3606    });
3607  } catch (error) {
3608    let err: BusinessError = error as BusinessError;
3609    console.error(`call i18n.StyledNumberFormat failed, error code: ${err.code}, message: ${err.message}.`);
3610  }
3611  ```
3612
3613### format<sup>18+</sup>
3614
3615format(value: number): StyledString
3616
3617Formats a number as a rich text object.
3618
3619**Atomic service API**: This API can be used in atomic services since API version 18.
3620
3621**System capability**: SystemCapability.Global.I18n
3622
3623**Parameters**
3624
3625|   Name |      Type     | Mandatory|     Description     |
3626| --------- | ------------- | ---- | ------------- |
3627| value | number | Yes| Number to be formatted. |
3628
3629**Return value**
3630
3631|       Type       |         Description         |
3632| ----------------- | ----------------------|
3633| [StyledString](../apis-arkui/arkui-ts/ts-universal-styled-string.md#styledstring) | Rich text object after formatting.|
3634
3635**Example**
3636  ```ts
3637  import { BusinessError } from '@kit.BasicServicesKit';
3638  import { intl } from '@kit.LocalizationKit';
3639
3640  try {
3641    let integerTextStyle: TextStyle = new TextStyle({ fontColor: Color.Red });
3642    let decimalTextStyle: TextStyle = new TextStyle({ fontColor: Color.Brown });
3643    let fractionTextStyle: TextStyle = new TextStyle({ fontColor: Color.Blue });
3644    let unitTextStyle: TextStyle = new TextStyle({ fontColor: Color.Green });
3645
3646    // Create a StyledNumberFormat object through intl.NumberFormat.
3647    let numFmt: intl.NumberFormat = new intl.NumberFormat('zh', { style: 'unit', unit: 'percent' });
3648    let styledNumFmt: i18n.StyledNumberFormat = new i18n.StyledNumberFormat(numFmt, {
3649      integer: integerTextStyle,
3650      decimal: decimalTextStyle,
3651      fraction: fractionTextStyle,
3652      unit: unitTextStyle
3653    });
3654    // formattedNumber.getString () is 1,234.568%. In the formatted number, 1,234 is in red, . in brown, 568 in blue, and % in green.
3655    let formattedNumber: StyledString = styledNumFmt.format(1234.5678);
3656
3657    // Create a StyledNumberFormat object through SimpleNumberFormat.
3658    let locale: intl.Locale = new intl.Locale('zh');
3659    let simpleNumFmt: i18n.SimpleNumberFormat = i18n.getSimpleNumberFormatBySkeleton('percent', locale);
3660    let styledSimpleNumFmt: i18n.StyledNumberFormat = new i18n.StyledNumberFormat(simpleNumFmt, {
3661      integer: integerTextStyle,
3662      decimal: decimalTextStyle,
3663      fraction: fractionTextStyle,
3664      unit: unitTextStyle
3665    });
3666    // formattedSimpleNumber.getString () is 1,234.5678%. In the formatted number, '1,234' is in red, . in brown, 5678 in blue, and % in green.
3667    let formattedSimpleNumber: StyledString = styledSimpleNumFmt.format(1234.5678);
3668  } catch (error) {
3669    let err: BusinessError = error as BusinessError;
3670    console.error(`call StyledNumberFormat.format failed, error code: ${err.code}, message: ${err.message}.`);
3671  }
3672  ```
3673
3674## StyledNumberFormatOptions<sup>18+</sup>
3675
3676Represents optional configuration items for the **NumberFormat** object.
3677
3678**Atomic service API**: This API can be used in atomic services since API version 18.
3679
3680**System capability**: SystemCapability.Global.I18n
3681
3682| Name           | Type            |  Read-Only  |  Optional  |  Description                                  |
3683| --------------- | --------------- | ------  | ------  | --------------------------------------- |
3684| integer        | [TextStyle](../apis-arkui/arkui-ts/ts-universal-styled-string.md#textstyle) |   No   |   Yes   |  Text style for the integer part. The default value is the default text style.    |
3685| decimal        | [TextStyle](../apis-arkui/arkui-ts/ts-universal-styled-string.md#textstyle) |   No   |   Yes   |  Text style for the decimal point. The default value is the default text style.   |
3686| fraction       | [TextStyle](../apis-arkui/arkui-ts/ts-universal-styled-string.md#textstyle) |   No   |   Yes   |  Text style for the fraction part. The default value is the default text style.    |
3687| unit           | [TextStyle](../apis-arkui/arkui-ts/ts-universal-styled-string.md#textstyle) |   No   |   Yes   |  Text style for the unit. The default value is the default text style.    |
3688
3689## i18n.getDisplayCountry<sup>(deprecated)</sup>
3690
3691getDisplayCountry(country: string, locale: string, sentenceCase?: boolean): string
3692
3693Obtains the localized name of the specified country/region.
3694
3695This API is deprecated since API version 9. You are advised to use [System.getDisplayCountry](#getdisplaycountry9).
3696
3697**System capability**: SystemCapability.Global.I18n
3698
3699**Parameters**
3700
3701| Name         | Type     | Mandatory  | Description              |
3702| ------------ | ------- | ---- | ---------------- |
3703| country      | string  | Yes   | Specified country.           |
3704| locale       | string  | Yes   | [System locale](../../internationalization/i18n-locale-culture.md#how-it-works), which consists of the language, script, and country/region.     |
3705| sentenceCase | boolean | No   | Whether to use sentence case to display the text. The value **true** means to display the text in title case format, and the value **false** means to display the text in the default case format of the locale. The default value is **true**.|
3706
3707**Return value**
3708
3709| Type    | Description           |
3710| ------ | ------------- |
3711| string | Localized script for the specified country.|
3712
3713**Example**
3714  ```ts
3715  let countryName: string = i18n.getDisplayCountry('zh-CN', 'en-GB', true); // countryName = 'China'
3716  countryName = i18n.getDisplayCountry('zh-CN', 'en-GB'); // countryName = 'China'
3717  ```
3718
3719## i18n.getDisplayLanguage<sup>(deprecated)</sup>
3720
3721getDisplayLanguage(language: string, locale: string, sentenceCase?: boolean): string
3722
3723Obtains the localized script for the specified language.
3724
3725This API is deprecated since API version 9. You are advised to use [System.getDisplayLanguage](#getdisplaylanguage9).
3726
3727**System capability**: SystemCapability.Global.I18n
3728
3729**Parameters**
3730
3731| Name         | Type     | Mandatory  | Description              |
3732| ------------ | ------- | ---- | ---------------- |
3733| language     | string  | Yes   | Specified language.           |
3734| locale       | string  | Yes   | [System locale](../../internationalization/i18n-locale-culture.md#how-it-works), which consists of the language, script, and country/region.     |
3735| sentenceCase | boolean | No   | Whether to use sentence case to display the text. The value **true** means to display the text in title case format, and the value **false** means to display the text in the default case format of the locale. The default value is **true**.|
3736
3737**Return value**
3738
3739| Type    | Description           |
3740| ------ | ------------- |
3741| string | Localized script for the specified language.|
3742
3743**Example**
3744  ```ts
3745  let languageName: string = i18n.getDisplayLanguage('zh', 'en-GB', true); // languageName = 'Chinese'
3746  languageName = i18n.getDisplayLanguage('zh', 'en-GB'); // languageName = 'Chinese'
3747  ```
3748
3749
3750## i18n.getSystemLanguage<sup>(deprecated)</sup>
3751
3752getSystemLanguage(): string
3753
3754Obtains the system language.
3755
3756This API is deprecated since API version 9. You are advised to use [System.getSystemLanguage](#getsystemlanguage9).
3757
3758**System capability**: SystemCapability.Global.I18n
3759
3760**Return value**
3761
3762| Type    | Description     |
3763| ------ | ------- |
3764| string | System language ID.|
3765
3766**Example**
3767  ```ts
3768  let systemLanguage: string = i18n.getSystemLanguage();
3769  ```
3770
3771
3772## i18n.getSystemRegion<sup>(deprecated)</sup>
3773
3774getSystemRegion(): string
3775
3776Obtains the system region.
3777
3778This API is deprecated since API version 9. You are advised to use [System.getSystemRegion](#getsystemregion9).
3779
3780**System capability**: SystemCapability.Global.I18n
3781
3782**Return value**
3783
3784| Type    | Description     |
3785| ------ | ------- |
3786| string | System region ID.|
3787
3788**Example**
3789  ```ts
3790  let region: string = i18n.getSystemRegion();
3791  ```
3792
3793
3794## i18n.getSystemLocale<sup>(deprecated)</sup>
3795
3796getSystemLocale(): string
3797
3798Obtains the system locale.
3799
3800This API is deprecated since API version 9. You are advised to use [System.getSystemLocale](#getsystemlocale9).
3801
3802**System capability**: SystemCapability.Global.I18n
3803
3804**Return value**
3805
3806| Type    | Description     |
3807| ------ | ------- |
3808| string | System locale ID.|
3809
3810**Example**
3811  ```ts
3812  let locale: string = i18n.getSystemLocale();
3813  ```
3814
3815
3816## i18n.is24HourClock<sup>(deprecated)</sup>
3817
3818is24HourClock(): boolean
3819
3820Checks whether the 24-hour clock is used.
3821
3822This API is deprecated since API version 9. You are advised to use [System.is24HourClock](#is24hourclock9).
3823
3824**System capability**: SystemCapability.Global.I18n
3825
3826**Return value**
3827
3828| Type     | Description                                      |
3829| ------- | ---------------------------------------- |
3830| boolean | **true** if the 24-hour clock is used, and **false** otherwise.|
3831
3832**Example**
3833  ```ts
3834  let is24HourClock: boolean = i18n.is24HourClock();
3835  ```
3836
3837
3838## i18n.set24HourClock<sup>(deprecated)</sup>
3839
3840set24HourClock(option: boolean): boolean
3841
3842Sets the 24-hour clock.
3843
3844This API is deprecated since API version 9. The substitute API is available only for system applications.
3845
3846**Permission required**: ohos.permission.UPDATE_CONFIGURATION
3847
3848**System capability**: SystemCapability.Global.I18n
3849
3850**Parameters**
3851
3852| Name   | Type     | Mandatory  | Description                                      |
3853| ------ | ------- | ---- | ---------------------------------------- |
3854| 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.|
3855
3856**Return value**
3857
3858| Type     | Description                           |
3859| ------- | ----------------------------- |
3860| boolean | **true** if the setting is successful, and **false** otherwise.|
3861
3862**Example**
3863  ```ts
3864  // Set the system time to the 24-hour clock.
3865  let success: boolean = i18n.set24HourClock(true);
3866  ```
3867
3868
3869## i18n.addPreferredLanguage<sup>(deprecated)</sup>
3870
3871addPreferredLanguage(language: string, index?: number): boolean
3872
3873Adds a preferred language to the specified position on the preferred language list.
3874
3875This API is supported since API version 8 and is deprecated since API version 9. The substitute API is available only for system applications.
3876
3877**Permission required**: ohos.permission.UPDATE_CONFIGURATION
3878
3879**System capability**: SystemCapability.Global.I18n
3880
3881**Parameters**
3882
3883| Name     | Type    | Mandatory  | Description        |
3884| -------- | ------ | ---- | ---------- |
3885| language | string | Yes   | Preferred language to add. |
3886| index    | number | No   | Position to which the preferred language is added. The default value is the length of the preferred language list.|
3887
3888**Return value**
3889
3890| Type     | Description                           |
3891| ------- | ----------------------------- |
3892| boolean | **true** if the operation is successful, and **false** otherwise.|
3893
3894**Example**
3895  ```ts
3896  // Add zh-CN to the preferred language list.
3897  let language: string = 'zh-CN';
3898  let index: number = 0;
3899  let success: boolean = i18n.addPreferredLanguage(language, index);
3900  ```
3901
3902
3903## i18n.removePreferredLanguage<sup>(deprecated)</sup>
3904
3905removePreferredLanguage(index: number): boolean
3906
3907Removes a preferred language from the specified position on the preferred language list.
3908
3909This API is supported since API version 8 and is deprecated since API version 9. The substitute API is available only for system applications.
3910
3911**Permission required**: ohos.permission.UPDATE_CONFIGURATION
3912
3913**System capability**: SystemCapability.Global.I18n
3914
3915**Parameters**
3916
3917| Name  | Type    | Mandatory  | Description                   |
3918| ----- | ------ | ---- | --------------------- |
3919| index | number | Yes   | Position of the preferred language to delete.|
3920
3921**Return value**
3922
3923| Type     | Description                           |
3924| ------- | ----------------------------- |
3925| boolean | Whether the operation is successful. The value **true** indicates that the operation is successful, and the value **false** indicates the opposite.|
3926
3927**Example**
3928  ```ts
3929  // Delete the first preferred language from the preferred language list.
3930  let index: number = 0;
3931  let success: boolean = i18n.removePreferredLanguage(index);
3932  ```
3933
3934
3935## i18n.getPreferredLanguageList<sup>(deprecated)</sup>
3936
3937getPreferredLanguageList(): Array&lt;string&gt;
3938
3939Obtains the list of preferred languages.
3940
3941This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [System.getPreferredLanguageList](#getpreferredlanguagelist9).
3942
3943**System capability**: SystemCapability.Global.I18n
3944
3945**Return value**
3946
3947| Type                 | Description       |
3948| ------------------- | --------- |
3949| Array&lt;string&gt; | List of preferred languages.|
3950
3951**Example**
3952  ```ts
3953  let preferredLanguageList: Array<string> = i18n.getPreferredLanguageList();
3954  ```
3955
3956
3957## i18n.getFirstPreferredLanguage<sup>(deprecated)</sup>
3958
3959getFirstPreferredLanguage(): string
3960
3961Obtains the first language in the preferred language list.
3962
3963This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [System.getFirstPreferredLanguage](#getfirstpreferredlanguage9).
3964
3965**System capability**: SystemCapability.Global.I18n
3966
3967**Return value**
3968
3969| Type    | Description            |
3970| ------ | -------------- |
3971| string | First language in the preferred language list.|
3972
3973**Example**
3974  ```ts
3975  let firstPreferredLanguage: string = i18n.getFirstPreferredLanguage();
3976  ```
3977
3978
3979## Util<sup>(deprecated)</sup>
3980
3981
3982### unitConvert<sup>(deprecated)</sup>
3983
3984unitConvert(fromUnit: UnitInfo, toUnit: UnitInfo, value: number, locale: string, style?: string): string
3985
3986Converts one measurement unit into another and formats the unit based on the specified locale and style.
3987
3988This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [unitConvert](#unitconvert9).
3989
3990**System capability**: SystemCapability.Global.I18n
3991
3992**Parameters**
3993
3994| Name     | Type                    | Mandatory  | Description                                      |
3995| -------- | ---------------------- | ---- | ---------------------------------------- |
3996| fromUnit | [UnitInfo](#unitinfo8) | Yes   | Measurement unit to be converted.                                |
3997| toUnit   | [UnitInfo](#unitinfo8) | Yes   | Measurement unit to be converted to.                                |
3998| value    | number                 | Yes   | Value of the measurement unit to be converted.                            |
3999| locale   | string                 | Yes   | Locale ID used for formatting, for example, **zh-Hans-CN**.               |
4000| style    | string                 | No   | Style used for formatting. The value can be **long**, **short**, or **narrow**. The default value is **short**.|
4001
4002**Return value**
4003
4004| Type    | Description                     |
4005| ------ | ----------------------- |
4006| string | String obtained after formatting based on the measurement unit specified by **toUnit**.|
4007
4008
4009## Character<sup>(deprecated)</sup>
4010
4011
4012### isDigit<sup>(deprecated)</sup>
4013
4014isDigit(char: string): boolean
4015
4016Checks whether the input character is a digit.
4017
4018This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [isDigit](#isdigit9).
4019
4020**System capability**: SystemCapability.Global.I18n
4021
4022**Parameters**
4023
4024| Name | Type    | Mandatory  | Description   |
4025| ---- | ------ | ---- | ----- |
4026| char | string | Yes   | Input character. If the input is a string, only the type of the first character is checked.|
4027
4028**Return value**
4029
4030| Type     | Description                                  |
4031| ------- | ------------------------------------ |
4032| boolean | **true** if the input character is a digit, and **false** otherwise.|
4033
4034
4035### isSpaceChar<sup>(deprecated)</sup>
4036
4037isSpaceChar(char: string): boolean
4038
4039Checks whether the input character is a space.
4040
4041This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [isSpaceChar](#isspacechar9).
4042
4043**System capability**: SystemCapability.Global.I18n
4044
4045**Parameters**
4046
4047| Name | Type    | Mandatory  | Description   |
4048| ---- | ------ | ---- | ----- |
4049| char | string | Yes   | Input character. If the input is a string, only the type of the first character is checked.|
4050
4051**Return value**
4052
4053| Type     | Description                                    |
4054| ------- | -------------------------------------- |
4055| boolean | **true** if the input character is a space, and **false** otherwise.|
4056
4057
4058### isWhitespace<sup>(deprecated)</sup>
4059
4060isWhitespace(char: string): boolean
4061
4062Checks whether the input character is a whitespace.
4063
4064This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [isWhitespace](#iswhitespace9).
4065
4066**System capability**: SystemCapability.Global.I18n
4067
4068**Parameters**
4069
4070| Name | Type    | Mandatory  | Description   |
4071| ---- | ------ | ---- | ----- |
4072| char | string | Yes   | Input character. If the input is a string, only the type of the first character is checked.|
4073
4074**Return value**
4075
4076| Type     | Description                                    |
4077| ------- | -------------------------------------- |
4078| boolean | **true** if the input character is a white space, and **false** otherwise.|
4079
4080
4081### isRTL<sup>(deprecated)</sup>
4082
4083isRTL(char: string): boolean
4084
4085Checks whether the input character is of the right to left (RTL) language.
4086
4087This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [isRTL](#isrtl9).
4088
4089**System capability**: SystemCapability.Global.I18n
4090
4091**Parameters**
4092
4093| Name | Type    | Mandatory  | Description   |
4094| ---- | ------ | ---- | ----- |
4095| char | string | Yes   | Input character. If the input is a string, only the type of the first character is checked.|
4096
4097**Return value**
4098
4099| Type     | Description                                      |
4100| ------- | ---------------------------------------- |
4101| boolean | **true** if the input character is of the RTL language, and **false** otherwise.|
4102
4103
4104### isIdeograph<sup>(deprecated)</sup>
4105
4106isIdeograph(char: string): boolean
4107
4108Checks whether the input character is an ideographic character.
4109
4110This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [isIdeograph](#isideograph9).
4111
4112**System capability**: SystemCapability.Global.I18n
4113
4114**Parameters**
4115
4116| Name | Type    | Mandatory  | Description   |
4117| ---- | ------ | ---- | ----- |
4118| char | string | Yes   | Input character. If the input is a string, only the type of the first character is checked.|
4119
4120**Return value**
4121
4122| Type     | Description                                      |
4123| ------- | ---------------------------------------- |
4124| boolean | **true** if the input character an ideographic character, and **false** otherwise.|
4125
4126
4127### isLetter<sup>(deprecated)</sup>
4128
4129isLetter(char: string): boolean
4130
4131Checks whether the input character is a letter.
4132
4133This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [isLetter](#isletter9).
4134
4135**System capability**: SystemCapability.Global.I18n
4136
4137**Parameters**
4138
4139| Name | Type    | Mandatory  | Description   |
4140| ---- | ------ | ---- | ----- |
4141| char | string | Yes   | Input character. If the input is a string, only the type of the first character is checked.|
4142
4143**Return value**
4144
4145| Type     | Description                                  |
4146| ------- | ------------------------------------ |
4147| boolean | **true** if the input character a letter, and **false** otherwise.|
4148
4149
4150### isLowerCase<sup>(deprecated)</sup>
4151
4152isLowerCase(char: string): boolean
4153
4154Checks whether the input character is a lowercase letter.
4155
4156This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [isLowerCase](#islowercase9).
4157
4158**System capability**: SystemCapability.Global.I18n
4159
4160**Parameters**
4161
4162| Name | Type    | Mandatory  | Description   |
4163| ---- | ------ | ---- | ----- |
4164| char | string | Yes   | Input character. If the input is a string, only the type of the first character is checked.|
4165
4166**Return value**
4167
4168| Type     | Description                                      |
4169| ------- | ---------------------------------------- |
4170| boolean | **true** if the input character a lowercase letter, and **false** otherwise.|
4171
4172
4173### isUpperCase<sup>(deprecated)</sup>
4174
4175isUpperCase(char: string): boolean
4176
4177Checks whether the input character is an uppercase letter.
4178
4179This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [isUpperCase](#isuppercase9).
4180
4181**System capability**: SystemCapability.Global.I18n
4182
4183**Parameters**
4184
4185| Name | Type    | Mandatory  | Description   |
4186| ---- | ------ | ---- | ----- |
4187| char | string | Yes   | Input character. If the input is a string, only the type of the first character is checked.|
4188
4189**Return value**
4190
4191| Type     | Description                                      |
4192| ------- | ---------------------------------------- |
4193| boolean | **true** if the input character an uppercase letter, and **false** otherwise.|
4194
4195
4196### getType<sup>(deprecated)</sup>
4197
4198getType(char: string): string
4199
4200Obtains the type of the input character.
4201
4202This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [getType](#gettype9).
4203
4204**System capability**: SystemCapability.Global.I18n
4205
4206**Parameters**
4207
4208| Name | Type    | Mandatory  | Description   |
4209| ---- | ------ | ---- | ----- |
4210| char | string | Yes   | Input character. If the input is a string, only the type of the first character is checked.|
4211
4212**Return value**
4213
4214| Type    | Description         |
4215| ------ | ----------- |
4216| string | Type of the input character.|
4217
4218<!--no_check-->
4219