• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# @ohos.i18n (Internationalization) (System API)
2
3 This module provides system-related or enhanced i18n capabilities, such as locale management, phone number formatting, and calendar, through supplementary i18n APIs that are not defined in ECMA 402. 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>  - 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.
7>
8>  - Since API version 11, some APIs of this module are supported in ArkTS widgets.
9>
10>  - This topic describes only system APIs provided by the module. For details about its public APIs, see [@ohos.i18n (Internationalization)](js-apis-intl.md).
11
12
13## Modules to Import
14
15```ts
16import { i18n } from '@kit.LocalizationKit';
17```
18
19## System<sup>9+</sup>
20
21### setSystemLanguage<sup>9+</sup>
22
23static setSystemLanguage(language: string): void
24
25Sets the system language.
26
27To listen for system language changes, enable listening for [COMMON_EVENT_LOCALE_CHANGED](../apis-basic-services-kit/common_event/commonEventManager-definitions.md#common_event_locale_changed).
28
29**System API**: This is a system API.
30
31**Permission required**: ohos.permission.UPDATE_CONFIGURATION
32
33**System capability**: SystemCapability.Global.I18n
34
35**Parameters**
36
37| Name     | Type    | Mandatory  | Description   |
38| -------- | ------ | ---- | ----- |
39| language | string | Yes   | Valid language ID.|
40
41**Error codes**
42
43For details about the error codes, see [ohos.i18n Error Codes](errorcode-i18n.md) and [Universal Error Codes](../errorcode-universal.md).
44
45| ID | Error Message                  |
46| ------ | ---------------------- |
47| 201 | Permission verification failed. The application does not have the permission required to call the API. |
48| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
49| 890001 | Invalid parameter. Possible causes: Parameter verification failed. |
50
51**Example**
52  ```ts
53  import { BusinessError, commonEventManager } from '@kit.BasicServicesKit';
54
55  // Set the system language
56  try {
57    i18n.System.setSystemLanguage('zh'); // Set the current system language to zh.
58  } catch(error) {
59    let err: BusinessError = error as BusinessError;
60    console.error(`call System.setSystemLanguage failed, error code: ${err.code}, message: ${err.message}.`);
61  }
62
63  // Subscribe to a common event.
64  let subscriber: commonEventManager.CommonEventSubscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription.
65  let subscribeInfo: commonEventManager.CommonEventSubscribeInfo = { // Define subscriber information.
66    events: [commonEventManager.Support.COMMON_EVENT_LOCALE_CHANGED]
67  };
68  commonEventManager.createSubscriber(subscribeInfo).then((commonEventSubscriber:commonEventManager.CommonEventSubscriber) => { // Create a subscriber.
69      console.info("createSubscriber");
70      subscriber = commonEventSubscriber;
71      commonEventManager.subscribe(subscriber, (err, data) => {
72        if (err) {
73          console.error(`Failed to subscribe common event. error code: ${err.code}, message: ${err.message}.`);
74          return;
75        }
76        console.info("the subscribed event has occurred."); // Triggered when the subscribed event occurs.
77      })
78  }).catch((err: BusinessError) => {
79      console.error(`createSubscriber failed, code is ${err.code}, message is ${err.message}`);
80  });
81  ```
82
83### setSystemRegion<sup>9+</sup>
84
85static setSystemRegion(region: string): void
86
87Sets the system region.
88
89To listen for system region changes, enable listening for [COMMON_EVENT_LOCALE_CHANGED](../apis-basic-services-kit/common_event/commonEventManager-definitions.md#common_event_locale_changed).
90
91**System API**: This is a system API.
92
93**Permission required**: ohos.permission.UPDATE_CONFIGURATION
94
95**System capability**: SystemCapability.Global.I18n
96
97**Parameters**
98
99| Name   | Type    | Mandatory  | Description   |
100| ------ | ------ | ---- | ----- |
101| region | string | Yes   | Valid region ID.|
102
103**Error codes**
104
105For details about the error codes, see [ohos.i18n Error Codes](errorcode-i18n.md) and [Universal Error Codes](../errorcode-universal.md).
106
107| ID | Error Message                  |
108| ------ | ---------------------- |
109| 201 | Permission verification failed. The application does not have the permission required to call the API. |
110| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
111| 890001 | Invalid parameter. Possible causes: Parameter verification failed. |
112
113**Example**
114  ```ts
115  import { BusinessError } from '@kit.BasicServicesKit';
116
117  try {
118    i18n.System.setSystemRegion('CN'); // Set the current system region to CN.
119  } catch(error) {
120    let err: BusinessError = error as BusinessError;
121    console.error(`call System.setSystemRegion failed, error code: ${err.code}, message: ${err.message}.`);
122  }
123  ```
124
125
126
127### setSystemLocale<sup>9+</sup>
128
129static setSystemLocale(locale: string): void
130
131Sets the system locale.
132
133To listen for system locale changes, enable listening for [COMMON_EVENT_LOCALE_CHANGED](../apis-basic-services-kit/common_event/commonEventManager-definitions.md#common_event_locale_changed).
134
135**System API**: This is a system API.
136
137**Permission required**: ohos.permission.UPDATE_CONFIGURATION
138
139**System capability**: SystemCapability.Global.I18n
140
141**Parameters**
142
143| Name   | Type    | Mandatory  | Description             |
144| ------ | ------ | ---- | --------------- |
145| locale | string | Yes   | [System locale](../../internationalization/i18n-locale-culture.md#how-it-works), which consists of the language, script, and country/region.|
146
147**Error codes**
148
149For details about the error codes, see [ohos.i18n Error Codes](errorcode-i18n.md) and [Universal Error Codes](../errorcode-universal.md).
150
151| ID | Error Message                  |
152| ------ | ---------------------- |
153| 201 | Permission verification failed. The application does not have the permission required to call the API. |
154| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
155| 890001 | Invalid parameter. Possible causes: Parameter verification failed. |
156
157**Example**
158  ```ts
159  import { BusinessError } from '@kit.BasicServicesKit';
160
161  try {
162    i18n.System.setSystemLocale('zh-CN'); // Set the system locale to zh-CN.
163  } catch(error) {
164    let err: BusinessError = error as BusinessError;
165    console.error(`call System.setSystemLocale failed, error code: ${err.code}, message: ${err.message}.`);
166  }
167  ```
168
169
170### set24HourClock<sup>9+</sup>
171
172static set24HourClock(option: boolean): void
173
174Sets whether to use the 24-hour clock.
175
176**System API**: This is a system API.
177
178**Permission required**: ohos.permission.UPDATE_CONFIGURATION
179
180**System capability**: SystemCapability.Global.I18n
181
182**Parameters**
183
184| Name   | Type     | Mandatory  | Description                                      |
185| ------ | ------- | ---- | ---------------------------------------- |
186| option | boolean | Yes   | Whether to use the 24-hour clock. The value **true** means to use the 24-hour clock, the the value **false** means the opposite.|
187
188**Error codes**
189
190For details about the error codes, see [ohos.i18n Error Codes](errorcode-i18n.md) and [Universal Error Codes](../errorcode-universal.md).
191
192| ID | Error Message                  |
193| ------ | ---------------------- |
194| 201 | Permission verification failed. The application does not have the permission required to call the API. |
195| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
196| 890001 | Invalid parameter. Possible causes: Parameter verification failed. |
197
198**Example**
199  ```ts
200  import { BusinessError } from '@kit.BasicServicesKit';
201
202  // Set the system time to the 24-hour clock.
203  try {
204    i18n.System.set24HourClock(true);
205  } catch(error) {
206    let err: BusinessError = error as BusinessError;
207    console.error(`call System.set24HourClock failed, error code: ${err.code}, message: ${err.message}.`);
208  }
209  ```
210
211### addPreferredLanguage<sup>9+</sup>
212
213static addPreferredLanguage(language: string, index?: number): void
214
215Adds a preferred language to the specified position on the preferred language list.
216
217**System API**: This is a system API.
218
219**Permission required**: ohos.permission.UPDATE_CONFIGURATION
220
221**System capability**: SystemCapability.Global.I18n
222
223**Parameters**
224
225| Name     | Type    | Mandatory  | Description        |
226| -------- | ------ | ---- | ---------- |
227| language | string | Yes   | Valid ID of the language to be added as a preferred language. |
228| index    | number | No   | Position to which the preferred language is added. The default value is the length of the preferred language list.|
229
230**Error codes**
231
232For details about the error codes, see [ohos.i18n Error Codes](errorcode-i18n.md) and [Universal Error Codes](../errorcode-universal.md).
233
234| ID | Error Message                  |
235| ------ | ---------------------- |
236| 201 | Permission verification failed. The application does not have the permission required to call the API. |
237| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
238| 890001 | Invalid parameter. Possible causes: Parameter verification failed. |
239
240**Example**
241  ```ts
242  import { BusinessError } from '@kit.BasicServicesKit';
243
244  // Add zh-CN to the preferred language list.
245  let language = 'zh-CN';
246  let index = 0;
247  try {
248    i18n.System.addPreferredLanguage(language, index); // Add zh-CN to the first place in the preferred language list.
249  } catch(error) {
250    let err: BusinessError = error as BusinessError;
251    console.error(`call System.addPreferredLanguage failed, error code: ${err.code}, message: ${err.message}.`);
252  }
253  ```
254
255### removePreferredLanguage<sup>9+</sup>
256
257static removePreferredLanguage(index: number): void
258
259Removes a preferred language from the specified position on the preferred language list.
260
261**System API**: This is a system API.
262
263**Permission required**: ohos.permission.UPDATE_CONFIGURATION
264
265**System capability**: SystemCapability.Global.I18n
266
267**Parameters**
268
269| Name  | Type    | Mandatory  | Description                   |
270| ----- | ------ | ---- | --------------------- |
271| index | number | Yes   | Position of the preferred language to delete.|
272
273**Error codes**
274
275For details about the error codes, see [ohos.i18n Error Codes](errorcode-i18n.md) and [Universal Error Codes](../errorcode-universal.md).
276
277| ID | Error Message                  |
278| ------ | ---------------------- |
279| 201 | Permission verification failed. The application does not have the permission required to call the API. |
280| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
281| 890001 | Invalid parameter. Possible causes: Parameter verification failed. |
282
283**Example**
284  ```ts
285  import { BusinessError } from '@kit.BasicServicesKit';
286
287  // Delete the first preferred language from the preferred language list.
288  let index: number = 0;
289  try {
290    i18n.System.removePreferredLanguage(index);
291  } catch(error) {
292    let err: BusinessError = error as BusinessError;
293    console.error(`call System.removePreferredLanguage failed, error code: ${err.code}, message: ${err.message}.`);
294  }
295  ```
296
297### setUsingLocalDigit<sup>9+</sup>
298
299static setUsingLocalDigit(flag: boolean): void
300
301Specifies whether to enable use of local digits.
302
303**System API**: This is a system API.
304
305**Permission required**: ohos.permission.UPDATE_CONFIGURATION
306
307**System capability**: SystemCapability.Global.I18n
308
309**Parameters**
310
311| Name | Type     | Mandatory  | Description                             |
312| ---- | ------- | ---- | ------------------------------- |
313| flag | boolean | Yes   | Whether to turn on the local digit switch. The value **true** means to turn on the local digit switch, and the value **false** indicates the opposite.|
314
315**Error codes**
316
317For details about the error codes, see [ohos.i18n Error Codes](errorcode-i18n.md) and [Universal Error Codes](../errorcode-universal.md).
318
319| ID | Error Message                  |
320| ------ | ---------------------- |
321| 201 | Permission verification failed. The application does not have the permission required to call the API. |
322| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
323| 890001 | Invalid parameter. Possible causes: Parameter verification failed. |
324
325**Example**
326  ```ts
327  import { BusinessError } from '@kit.BasicServicesKit';
328
329  try {
330    i18n.System.setUsingLocalDigit(true); // Enable the local digit switch.
331  } catch(error) {
332    let err: BusinessError = error as BusinessError;
333    console.error(`call System.setUsingLocalDigit failed, error code: ${err.code}, message: ${err.message}.`);
334  }
335  ```
336
337
338### setTemperatureType<sup>18+</sup>
339
340static setTemperatureType(type: TemperatureType): void
341
342Sets the temperature unit of the system.
343
344**System API**: This is a system API.
345
346**Permission required**: ohos.permission.UPDATE_CONFIGURATION
347
348**System capability**: SystemCapability.Global.I18n
349
350**Parameters**
351
352| Name | Type     | Mandatory  | Description                             |
353| ---- | ------- | ---- | ------------------------------- |
354| type | [TemperatureType](./js-apis-i18n.md#temperaturetype18) | Yes| Temperature unit.|
355
356**Error codes**
357
358For details about the error codes, see [ohos.i18n Error Codes](errorcode-i18n.md) and [Universal Error Codes](../errorcode-universal.md).
359
360| ID | Error Message                  |
361| ------ | ---------------------- |
362| 201 | Permission verification failed. The application does not have the permission required to call the API. |
363| 202 | Permission verification failed. A non-system application calls a system API. |
364| 890001 | Invalid parameter. Possible causes: Parameter verification failed. |
365
366> **NOTE**
367>
368> The error message of 890001 is subject to the actual error.
369
370**Example**
371  ```ts
372  import { BusinessError } from '@kit.BasicServicesKit';
373
374  try {
375    i18n.System.setTemperatureType(i18n.TemperatureType.CELSIUS); //: Set the temperature unit to °C.
376  } catch(error) {
377    let err: BusinessError = error as BusinessError;
378    console.error(`call System.setTemperatureType failed, error code: ${err.code}, message: ${err.message}.`);
379  }
380  ```
381
382### setFirstDayOfWeek<sup>18+</sup>
383
384static setFirstDayOfWeek(type: WeekDay): void
385
386Sets the first day of a week.
387
388**System API**: This is a system API.
389
390**Permission required**: ohos.permission.UPDATE_CONFIGURATION
391
392**System capability**: SystemCapability.Global.I18n
393
394**Parameters**
395
396| Name | Type     | Mandatory  | Description                             |
397| ---- | ------- | ---- | ------------------------------- |
398| type | [WeekDay](./js-apis-i18n.md#weekday18) | Yes| Start day of a week.|
399
400**Error codes**
401
402For details about the error codes, see [ohos.i18n Error Codes](errorcode-i18n.md) and [Universal Error Codes](../errorcode-universal.md).
403
404| ID | Error Message                  |
405| ------ | ---------------------- |
406| 201 | Permission verification failed. The application does not have the permission required to call the API. |
407| 202 | Permission verification failed. A non-system application calls a system API. |
408| 890001 | Invalid parameter. Possible causes: Parameter verification failed. |
409
410> **NOTE**
411>
412> The error message of 890001 is subject to the actual error.
413
414**Example**
415  ```ts
416  import { BusinessError } from '@kit.BasicServicesKit';
417
418  try {
419    i18n.System.setFirstDayOfWeek (i18n.WeekDay.MON); // Set the preferred start day of a week to Monday.
420  } catch(error) {
421    let err: BusinessError = error as BusinessError;
422    console.error(`call System.setFirstDayOfWeek failed, error code: ${err.code}, message: ${err.message}.`);
423  }
424  ```
425
426### getSystemCollations<sup>20+</sup>
427
428static getSystemCollations(): Map&lt;string, string&gt;
429
430Obtains the collation modes supported by the system and their names. If the system language is English, the system supports the collation mode where uppercase letters come before lowercase letters or vice versa.
431
432**System API**: This is a system API.
433
434**System capability**: SystemCapability.Global.I18n
435
436**Return value**
437
438| Type                    | Description   |
439| ---------------------- | ----- |
440| Map&lt;string, string&gt; | Collation modes supported by the system and their names. The **Map** object employs the key-value format, where the key is a string that indicates the collation mode, and the value is a string that indicates its name. The range of supported collation modes is subject to the system language.|
441
442**Error codes**
443
444For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
445
446| ID | Error Message                  |
447| ------ | ---------------------- |
448| 202 | Permission verification failed. A non-system application calls a system API. |
449
450**Example**
451```ts
452import { BusinessError } from '@kit.BasicServicesKit';
453import { i18n } from '@kit.LocalizationKit';
454
455try {
456  let systemCollations: Map<string, string> = i18n.System.getSystemCollations();
457} catch(error) {
458  let err: BusinessError = error as BusinessError;
459  console.error(`call System.getSystemCollations failed, error code: ${err.code}, message: ${err.message}.`);
460}
461```
462
463### getUsingCollation<sup>20+</sup>
464
465static getUsingCollation(): string
466
467Obtains the current collation mode of the system.
468
469**System API**: This is a system API.
470
471**System capability**: SystemCapability.Global.I18n
472
473**Return value**
474
475| Type                    | Description   |
476| ---------------------- | ----- |
477| string | Current collation mode of the system.|
478
479**Error codes**
480
481For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
482
483| ID | Error Message                  |
484| ------ | ---------------------- |
485| 202 | Permission verification failed. A non-system application calls a system API. |
486
487**Example**
488```ts
489import { BusinessError } from '@kit.BasicServicesKit';
490import { i18n } from '@kit.LocalizationKit';
491
492try {
493  let usingCollation: string = i18n.System.getUsingCollation();
494} catch(error) {
495  let err: BusinessError = error as BusinessError;
496  console.error(`call System.getUsingCollation failed, error code: ${err.code}, message: ${err.message}.`);
497}
498```
499
500### setSystemCollation<sup>20+</sup>
501
502static setSystemCollation(identifier: string): void
503
504Sets the collation mode used by the system.
505
506**System API**: This is a system API.
507
508**Permission required**: ohos.permission.UPDATE_CONFIGURATION
509
510**System capability**: SystemCapability.Global.I18n
511
512**Parameters**
513
514| Name | Type     | Mandatory  | Description                             |
515| ---- | ------- | ---- | ------------------------------- |
516| identifier | string | Yes| Collation mode used by the system. You can obtain the range supported collation modes by calling [getSystemCollations](#getsystemcollations20).|
517
518**Error codes**
519
520For details about the error codes, see [ohos.i18n Error Codes](errorcode-i18n.md) and [Universal Error Codes](../errorcode-universal.md).
521
522| ID | Error Message                  |
523| ------ | ---------------------- |
524| 201 | Permission verification failed. The application does not have the permission required to call the API. |
525| 202 | Permission verification failed. A non-system application calls a system API. |
526| 8900001 | Invalid parameter. Possible causes: Parameter verification failed. |
527
528**Example**
529```ts
530import { BusinessError } from '@kit.BasicServicesKit';
531import { i18n } from '@kit.LocalizationKit';
532
533try {
534  i18n.System.setSystemCollation("zhuyin"); // If the specified collation mode is not supported, an error is reported.
535} catch(error) {
536  let err: BusinessError = error as BusinessError;
537  console.error(`call System.setSystemCollation failed, error code: ${err.code}, message: ${err.message}.`);
538}
539```
540
541### getSystemNumberingSystems<sup>20+</sup>
542
543static getSystemNumberingSystems(): Map&lt;string, string&gt;
544
545Obtains the numbering systems supported by the system and examples. The examples illustrate the display of digits 0 to 9 in the corresponding numbering system.
546
547**System API**: This is a system API.
548
549**System capability**: SystemCapability.Global.I18n
550
551**Return value**
552
553| Type                    | Description   |
554| ---------------------- | ----- |
555| Map&lt;string, string&gt; | Numbering systems supported by the system and examples. The **Map** object employs the key-value format, where the key is a string that indicates the numbering system, and the value indicates an example. The range of supported numbering systems is subject to the system language.|
556
557**Error codes**
558
559For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
560
561| ID | Error Message                  |
562| ------ | ---------------------- |
563| 202 | Permission verification failed. A non-system application calls a system API. |
564
565**Example**
566```ts
567import { BusinessError } from '@kit.BasicServicesKit';
568import { i18n } from '@kit.LocalizationKit';
569
570try {
571  let systemNumberingSystems: Map<string, string> = i18n.System.getSystemNumberingSystems();
572} catch(error) {
573  let err: BusinessError = error as BusinessError;
574  console.error(`call System.getSystemNumberingSystems failed, error code: ${err.code}, message: ${err.message}.`);
575}
576```
577
578### setSystemNumberingSystem<sup>20+</sup>
579
580static setSystemNumberingSystem(identifier: string):void
581
582Sets the numbering system used by the system.
583
584**System API**: This is a system API.
585
586**Permission required**: ohos.permission.UPDATE_CONFIGURATION
587
588**System capability**: SystemCapability.Global.I18n
589
590**Parameters**
591
592| Name | Type     | Mandatory  | Description                             |
593| ---- | ------- | ---- | ------------------------------- |
594| identifier | string | Yes| Numbering system used by the system. You can obtain the range of supported numbering systems by calling [getSystemNumberingSystems](#getsystemnumberingsystems20).|
595
596**Error codes**
597
598For details about the error codes, see [ohos.i18n Error Codes](errorcode-i18n.md) and [Universal Error Codes](../errorcode-universal.md).
599
600| ID | Error Message                  |
601| ------ | ---------------------- |
602| 201 | Permission verification failed. The application does not have the permission required to call the API. |
603| 202 | Permission verification failed. A non-system application calls a system API. |
604| 8900001 | Invalid parameter. Possible causes: Parameter verification failed. |
605
606**Example**
607```ts
608import { BusinessError } from '@kit.BasicServicesKit';
609import { i18n } from '@kit.LocalizationKit';
610
611try {
612  i18n.System.setSystemNumberingSystem("arab"); // If the specified numbering system is not supported, an error is reported.
613} catch(error) {
614  let err: BusinessError = error as BusinessError;
615  console.error(`call System.setSystemNumberingSystem failed, error code: ${err.code}, message: ${err.message}.`);
616}
617```
618
619### getSystemNumberPatterns<sup>20+</sup>
620
621static getSystemNumberPatterns(): Map&lt;string, string&gt;
622
623Obtains the number patterns supported by the system and examples. A number pattern determines the format of the thousands separator and decimal separator in numbers.
624
625**System API**: This is a system API.
626
627**System capability**: SystemCapability.Global.I18n
628
629**Return value**
630
631| Type                    | Description   |
632| ---------------------- | ----- |
633| Map&lt;string, string&gt; | Number patterns supported by the system and examples. The **Map** object employs the key-value format, where the key is the number pattern (represented by Unicode code of the thousand separator and decimal separator), and the value indicates an example. The range of supported number patterns is subject to the system language.|
634
635**Error codes**
636
637For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
638
639| ID | Error Message                  |
640| ------ | ---------------------- |
641| 202 | Permission verification failed. A non-system application calls a system API. |
642
643**Example**
644```ts
645import { BusinessError } from '@kit.BasicServicesKit';
646import { i18n } from '@kit.LocalizationKit';
647
648try {
649  let systemNumberPatterns: Map<string, string> = i18n.System.getSystemNumberPatterns();
650} catch(error) {
651  let err: BusinessError = error as BusinessError;
652  console.error(`call System.getSystemNumberPatterns failed, error code: ${err.code}, message: ${err.message}.`);
653}
654```
655
656### getUsingNumberPattern<sup>20+</sup>
657
658static getUsingNumberPattern(): string
659
660Obtains the current number pattern of the system.
661
662**System API**: This is a system API.
663
664**System capability**: SystemCapability.Global.I18n
665
666**Return value**
667
668| Type                    | Description   |
669| ---------------------- | ----- |
670| string | Current number pattern of the system.|
671
672**Error codes**
673
674For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
675
676| ID | Error Message                  |
677| ------ | ---------------------- |
678| 202 | Permission verification failed. A non-system application calls a system API. |
679
680**Example**
681```ts
682import { BusinessError } from '@kit.BasicServicesKit';
683import { i18n } from '@kit.LocalizationKit';
684
685try {
686  let usingNumberPattern: string = i18n.System.getUsingNumberPattern();
687} catch(error) {
688  let err: BusinessError = error as BusinessError;
689  console.error(`call System.getUsingNumberPattern failed, error code: ${err.code}, message: ${err.message}.`);
690}
691```
692
693### setSystemNumberPattern<sup>20+</sup>
694
695static setSystemNumberPattern(pattern: string): void
696
697Sets the number pattern used by the system.
698
699**System API**: This is a system API.
700
701**Permission required**: ohos.permission.UPDATE_CONFIGURATION
702
703**System capability**: SystemCapability.Global.I18n
704
705**Parameters**
706
707| Name | Type     | Mandatory  | Description                             |
708| ---- | ------- | ---- | ------------------------------- |
709| pattern | string | Yes| Number pattern used by the system. You can obtain the range of supported number patterns by calling [getSystemNumberPatterns](#getsystemnumberpatterns20).|
710
711**Error codes**
712
713For details about the error codes, see [ohos.i18n Error Codes](errorcode-i18n.md) and [Universal Error Codes](../errorcode-universal.md).
714
715| ID | Error Message                  |
716| ------ | ---------------------- |
717| 201 | Permission verification failed. The application does not have the permission required to call the API. |
718| 202 | Permission verification failed. A non-system application calls a system API. |
719| 8900001 | Invalid parameter. Possible causes: Parameter verification failed. |
720
721**Example**
722```ts
723import { BusinessError } from '@kit.BasicServicesKit';
724import { i18n } from '@kit.LocalizationKit';
725
726try {
727  i18n.System.setSystemNumberPattern("002e002c"); // If the specified number pattern is not supported, an error is reported.
728} catch(error) {
729  let err: BusinessError = error as BusinessError;
730  console.error(`call System.setSystemNumberPattern failed, error code: ${err.code}, message: ${err.message}.`);
731}
732```
733
734### getSystemMeasurements<sup>20+</sup>
735
736static getSystemMeasurements(): Map&lt;string, string&gt;
737
738Obtains the measurement systems supported by the system and their names.
739
740**System API**: This is a system API.
741
742**System capability**: SystemCapability.Global.I18n
743
744**Return value**
745
746| Type                    | Description   |
747| ---------------------- | ----- |
748| Map&lt;string, string&gt; | Measurement systems supported by the system and their names. The **Map** object employs the key-value format, where the key indicates the ID of the measurement system, and the value indicates its name. The supported measurement systems are as follows:<br>- **metric**: metric system<br>- **uksystem**: imperial system<br>- **ussystem**: US system|
749
750**Error codes**
751
752For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
753
754| ID | Error Message                  |
755| ------ | ---------------------- |
756| 202 | Permission verification failed. A non-system application calls a system API. |
757
758**Example**
759```ts
760import { BusinessError } from '@kit.BasicServicesKit';
761import { i18n } from '@kit.LocalizationKit';
762
763try {
764  let systemMeasurements: Map<string, string> = i18n.System.getSystemMeasurements();
765} catch(error) {
766  let err: BusinessError = error as BusinessError;
767  console.error(`call System.getSystemMeasurements failed, error code: ${err.code}, message: ${err.message}.`);
768}
769```
770
771### getUsingMeasurement<sup>20+</sup>
772
773static getUsingMeasurement(): string
774
775Obtains the current measurement system of the system.
776
777**System API**: This is a system API.
778
779**System capability**: SystemCapability.Global.I18n
780
781**Return value**
782
783| Type                    | Description   |
784| ---------------------- | ----- |
785| string | Current measurement system of the system. The supported measurement systems are as follows:<br>- **metric**: metric system<br>- **uksystem**: imperial system<br>- **ussystem**: US system|
786
787**Error codes**
788
789For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
790
791| ID | Error Message                  |
792| ------ | ---------------------- |
793| 202 | Permission verification failed. A non-system application calls a system API. |
794
795**Example**
796```ts
797import { BusinessError } from '@kit.BasicServicesKit';
798import { i18n } from '@kit.LocalizationKit';
799
800try {
801  let usingMeasurement: string = i18n.System.getUsingMeasurement();
802} catch(error) {
803  let err: BusinessError = error as BusinessError;
804  console.error(`call System.getUsingMeasurement failed, error code: ${err.code}, message: ${err.message}.`);
805}
806```
807
808### setSystemMeasurement<sup>20+</sup>
809
810static setSystemMeasurement(identifier: string): void
811
812Sets the measurement system used by the system.
813
814**System API**: This is a system API.
815
816**Permission required**: ohos.permission.UPDATE_CONFIGURATION
817
818**System capability**: SystemCapability.Global.I18n
819
820**Parameters**
821
822| Name | Type     | Mandatory  | Description                             |
823| ---- | ------- | ---- | ------------------------------- |
824| identifier | string | Yes| Measurement system used by the system. You can obtain the range of supported measurement systems by calling [getSystemMeasurements](#getsystemmeasurements20).|
825
826**Error codes**
827
828For details about the error codes, see [ohos.i18n Error Codes](errorcode-i18n.md) and [Universal Error Codes](../errorcode-universal.md).
829
830| ID | Error Message                  |
831| ------ | ---------------------- |
832| 201 | Permission verification failed. The application does not have the permission required to call the API. |
833| 202 | Permission verification failed. A non-system application calls a system API. |
834| 8900001 | Invalid parameter. Possible causes: Parameter verification failed. |
835
836**Example**
837```ts
838import { BusinessError } from '@kit.BasicServicesKit';
839import { i18n } from '@kit.LocalizationKit';
840
841try {
842  i18n.System.setSystemMeasurement("uksystem"); // If the specified measurement system is not supported, error code 8900001 is reported.
843} catch(error) {
844  let err: BusinessError = error as BusinessError;
845  console.error(`call System.setSystemMeasurement failed, error code: ${err.code}, message: ${err.message}.`);
846}
847```
848
849### getSystemNumericalDatePatterns<sup>20+</sup>
850
851static getSystemNumericalDatePatterns(): Map&lt;string, string&gt;
852
853Obtains the numerical date patterns supported by the system and examples.
854
855**System API**: This is a system API.
856
857**System capability**: SystemCapability.Global.I18n
858
859**Return value**
860
861| Type                    | Description   |
862| ---------------------- | ----- |
863| Map&lt;string, string&gt; | Numerical date patterns supported by the system and examples. The **Map** object employs the key-value format, where the key indicates the numerical date pattern, for example, `dd/MM/y`, and the value indicates an example, for example, `18/07/2025`.|
864
865**Error codes**
866
867For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
868
869| ID | Error Message                  |
870| ------ | ---------------------- |
871| 202 | Permission verification failed. A non-system application calls a system API. |
872
873**Example**
874```ts
875import { BusinessError } from '@kit.BasicServicesKit';
876import { i18n } from '@kit.LocalizationKit';
877
878try {
879  let datePatterns: Map<string, string> = i18n.System.getSystemNumericalDatePatterns();
880} catch(error) {
881  let err: BusinessError = error as BusinessError;
882  console.error(`call System.getSystemNumericalDatePatterns failed, error code: ${err.code}, message: ${err.message}.`);
883}
884```
885
886### getUsingNumericalDatePattern<sup>20+</sup>
887
888static getUsingNumericalDatePattern(): string
889
890Obtains the current numerical date pattern of the system.
891
892**System API**: This is a system API.
893
894**System capability**: SystemCapability.Global.I18n
895
896**Return value**
897
898| Type                    | Description   |
899| ---------------------- | ----- |
900| string | Current numerical date pattern of the system.|
901
902**Error codes**
903
904For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
905
906| ID | Error Message                  |
907| ------ | ---------------------- |
908| 202 | Permission verification failed. A non-system application calls a system API. |
909
910**Example**
911```ts
912import { BusinessError } from '@kit.BasicServicesKit';
913import { i18n } from '@kit.LocalizationKit';
914
915try {
916  let datePattern: string = i18n.System.getUsingNumericalDatePattern();
917} catch(error) {
918  let err: BusinessError = error as BusinessError;
919  console.error(`call System.getUsingNumericalDatePattern failed, error code: ${err.code}, message: ${err.message}.`);
920}
921```
922
923### setSystemNumericalDatePattern<sup>20+</sup>
924
925static setSystemNumericalDatePattern(identifier: string): void
926
927Sets the numerical date pattern used by the system.
928
929**System API**: This is a system API.
930
931**Permission required**: ohos.permission.UPDATE_CONFIGURATION
932
933**System capability**: SystemCapability.Global.I18n
934
935**Parameters**
936
937| Name | Type     | Mandatory  | Description                             |
938| ---- | ------- | ---- | ------------------------------- |
939| identifier | string | Yes| Numerical date pattern used by the system. You can obtain the range of supported numerical date patterns by calling [getSystemNumericalDatePatterns](#getsystemnumericaldatepatterns20).|
940
941**Error codes**
942
943For details about the error codes, see [ohos.i18n Error Codes](errorcode-i18n.md) and [Universal Error Codes](../errorcode-universal.md).
944
945| ID | Error Message                  |
946| ------ | ---------------------- |
947| 201 | Permission verification failed. The application does not have the permission required to call the API. |
948| 202 | Permission verification failed. A non-system application calls a system API. |
949| 8900001 | Invalid parameter. Possible causes: Parameter verification failed. |
950
951**Example**
952```ts
953import { BusinessError } from '@kit.BasicServicesKit';
954import { i18n } from '@kit.LocalizationKit';
955
956try {
957  i18n.System.setSystemNumericalDatePattern("dd/MM/y"); // If the specified numerical date pattern is not supported, error code 8900001 is reported.
958} catch(error) {
959  let err: BusinessError = error as BusinessError;
960  console.error(`call System.setSystemNumericalDatePattern failed, error code: ${err.code}, message: ${err.message}.`);
961}
962```
963
964## SystemLocaleManager<sup>10+</sup>
965
966### constructor<sup>10+</sup>
967
968constructor()
969
970Creates a **SystemLocaleManager** object.
971
972**System API**: This is a system API.
973
974**System capability**: SystemCapability.Global.I18n
975
976**Example**
977  ```ts
978  let systemLocaleManager: i18n.SystemLocaleManager = new i18n.SystemLocaleManager();
979  ```
980
981
982### getLanguageInfoArray<sup>10+</sup>
983
984getLanguageInfoArray(languages: Array&lt;string&gt;, options?: SortOptions): Array&lt;LocaleItem&gt;
985
986Obtains the list of languages after sorting.
987
988**System API**: This is a system API.
989
990**System capability**: SystemCapability.Global.I18n
991
992**Parameters**
993
994|   Name |      Type     | Mandatory|     Description     |
995| --------- | ------------- | ---- | ------------- |
996| languages | Array&lt;string&gt; | Yes  | Valid IDs of the languages to be sorted.|
997| options   | [SortOptions](#sortoptions10)   | No  | Language sorting option.|
998
999**Return value**
1000
1001|       Type       |         Description         |
1002| ----------------- | -------------------- |
1003| Array&lt;[LocaleItem](#localeitem10)&gt; | Language list after sorting.|
1004
1005**Error codes**
1006
1007For details about the error codes, see [ohos.i18n Error Codes](errorcode-i18n.md) and [Universal Error Codes](../errorcode-universal.md).
1008
1009| ID | Error Message                  |
1010| ------ | ---------------------- |
1011| 202 | Permission verification failed. A non-system application calls a system API. |
1012| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
1013| 890001 | Invalid parameter. Possible causes: Parameter verification failed. |
1014
1015**Example**
1016  ```ts
1017  import { BusinessError } from '@kit.BasicServicesKit';
1018
1019  // Assume that the system language is zh-Hans, the system region is CN, and the system locale is zh-Hans-CN.
1020  let systemLocaleManager: i18n.SystemLocaleManager = new i18n.SystemLocaleManager();
1021  let languages: string[] = ["zh-Hans", "en-US", "pt", "ar"];
1022  let sortOptions: i18n.SortOptions = {locale: "zh-Hans-CN", isUseLocalName: true, isSuggestedFirst: true};
1023  try {
1024      // The language list after sorting is [zh-Hans, en-US, pt, ar].
1025      let sortedLanguages: Array<i18n.LocaleItem> = systemLocaleManager.getLanguageInfoArray(languages, sortOptions);
1026  } catch(error) {
1027      let err: BusinessError = error as BusinessError;
1028      console.error(`call systemLocaleManager.getLanguageInfoArray failed, error code: ${err.code}, message: ${err.message}.`);
1029  }
1030  ```
1031
1032
1033### getRegionInfoArray<sup>10+</sup>
1034
1035getRegionInfoArray(regions: Array&lt;string&gt;, options?: SortOptions): Array&lt;LocaleItem&gt;
1036
1037Obtains the IDs of the countries or regions after sorting.
1038
1039**System API**: This is a system API.
1040
1041**System capability**: SystemCapability.Global.I18n
1042
1043**Parameters**
1044
1045|   Name |      Type     | Mandatory|     Description     |
1046| --------- | ------------- | ---- | ------------- |
1047| regions   | Array&lt;string&gt; | Yes  | Valid IDs of the countries or regions to be sorted.|
1048| options   | [SortOptions](#sortoptions10)   | No  | Country/region sorting option.<br>By default, **locale** is the current system locale, **isUseLocalName** is **false**, and **isSuggestedFirst** is **true**.|
1049
1050**Return value**
1051
1052|       Type       |         Description         |
1053| ----------------- | -------------------- |
1054| Array&lt;[LocaleItem](#localeitem10)&gt; | IDs of the countries or regions after sorting.|
1055
1056**Error codes**
1057
1058For details about the error codes, see [ohos.i18n Error Codes](errorcode-i18n.md) and [Universal Error Codes](../errorcode-universal.md).
1059
1060| ID | Error Message                  |
1061| ------ | ---------------------- |
1062| 202 | Permission verification failed. A non-system application calls a system API. |
1063| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
1064| 890001 | Invalid parameter. Possible causes: Parameter verification failed. |
1065
1066**Example**
1067  ```ts
1068  import { BusinessError } from '@kit.BasicServicesKit';
1069
1070  // Assume that the system language is zh-Hans, the system region is CN, and the system locale is zh-Hans-CN.
1071  let systemLocaleManager: i18n.SystemLocaleManager = new i18n.SystemLocaleManager();
1072  let regions: string[] = ["CN", "US", "PT", "EG"];
1073  let sortOptions: i18n.SortOptions = {locale: "zh-Hans-CN", isUseLocalName: false, isSuggestedFirst: true};
1074  try {
1075      // The country/region list after sorting is [CN, EG, US, PT].
1076      let sortedRegions: Array<i18n.LocaleItem> = systemLocaleManager.getRegionInfoArray(regions, sortOptions);
1077  } catch(error) {
1078      let err: BusinessError = error as BusinessError;
1079      console.error(`call systemLocaleManager.getRegionInfoArray failed, error code: ${err.code}, message: ${err.message}.`);
1080  }
1081  ```
1082
1083### getTimeZoneCityItemArray<sup>10+</sup>
1084
1085static getTimeZoneCityItemArray(): Array&lt;TimeZoneCityItem&gt;
1086
1087Obtains list of time zone city items after sorting.
1088
1089**System API**: This is a system API.
1090
1091**System capability**: SystemCapability.Global.I18n
1092
1093**Return value**
1094
1095|       Type       |         Description         |
1096| ----------------- | -------------------- |
1097| Array&lt;[TimeZoneCityItem](#timezonecityitem10)&gt; | List of time zone city items after sorting.|
1098
1099**Error codes**
1100
1101For details about the error codes, see [ohos.i18n Error Codes](errorcode-i18n.md) and [Universal Error Codes](../errorcode-universal.md).
1102
1103| ID | Error Message                  |
1104| ------ | ---------------------- |
1105| 202 | Permission verification failed. A non-system application calls a system API. |
1106
1107**Example**
1108  ```ts
1109  import { BusinessError } from '@kit.BasicServicesKit';
1110
1111  try {
1112    let timeZoneCityItemArray: Array<i18n.TimeZoneCityItem> = i18n.SystemLocaleManager.getTimeZoneCityItemArray();
1113    for (let i = 0; i < timeZoneCityItemArray.length; i++) {
1114        console.log(timeZoneCityItemArray[i].zoneId + ", " + timeZoneCityItemArray[i].cityId + ", " + timeZoneCityItemArray[i].cityDisplayName +
1115            ", " + timeZoneCityItemArray[i].offset + "\r\n");
1116    }
1117  } catch(error) {
1118    let err: BusinessError = error as BusinessError;
1119    console.error(`call SystemLocaleManager.getTimeZoneCityItemArray failed, error code: ${err.code}, message: ${err.message}.`);
1120  }
1121  ```
1122
1123## LocaleItem<sup>10+</sup>
1124
1125Represents the locale information, which consists of the language, script, and country/region.
1126
1127**System API**: This is a system API.
1128
1129**System capability**: SystemCapability.Global.I18n
1130
1131| Name           | Type           | Read-Only| Optional  |  Description                                  |
1132| --------------- | --------------- | ------ | ------ | --------------------------------------- |
1133| id              | string          |   No  |   No  | Language code or country/region code, for example, **zh** or **CN**.   |
1134| suggestionType  | [SuggestionType](#suggestiontype10)  |   No  |   No | Language or country/region suggestion type.                 |
1135| displayName     | string          |   No  |  No  | Representation of ID in the specified locale in **SystemLocaleManager**.|
1136| localName       | string          |   No  |  Yes  | Local name of the ID. This option is available only when the language information is presented.     |
1137
1138## TimeZoneCityItem<sup>10+</sup>
1139
1140Represents a time zone and city combination item.
1141
1142**System API**: This is a system API.
1143
1144**System capability**: SystemCapability.Global.I18n
1145
1146| Name           | Type            |  Read-Only  |  Optional  |  Description                                  |
1147| --------------- | --------------- | ------  | ------  | --------------------------------------- |
1148| zoneId          | string          |   No   |   No   | Time zone ID, for example, **Asia/Shanghai**.             |
1149| cityId          | string          |   No   |   No   | City ID, for example, Shanghai.                  |
1150| cityDisplayName | string          |   No   |   No   | City display name in the system locale.         |
1151| offset          | number             |   No   |   No   | Offset of the time zone ID.                        |
1152| zoneDisplayName | string          |   No   |   No   | Time zone display name in the system locale.         |
1153| rawOffset       | number             |   No   |   Yes   | Fixed offset of the time zone ID.                      |
1154
1155
1156## SuggestionType<sup>10+</sup>
1157
1158Represents the language or country/region suggestion type.
1159
1160**System API**: This is a system API.
1161
1162**System capability**: SystemCapability.Global.I18n
1163
1164| Name                  | Value | Description  |
1165| ---------------------- | ---- | ---- |
1166| SUGGESTION_TYPE_NONE   | 0x00 | Not a recommended language or country/region.|
1167| SUGGESTION_TYPE_RELATED| 0x01 | Country/region recommended by the system language or language recommended by the system country/region.|
1168| SUGGESTION_TYPE_SIM    | 0x02 | Language recommended by the country/region of the SIM card.|
1169
1170
1171## SortOptions<sup>10+<sup>
1172
1173Represents the language or country/region sorting option.
1174
1175**System API**: This is a system API.
1176
1177**System capability**: SystemCapability.Global.I18n
1178
1179| Name           | Type           |  Read-Only|  Optional|   Description                                |
1180| --------------- | --------------- | ---- | ---- | --------------------------------------- |
1181| locale          | string          |  No |  Yes | [Locale information](../../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.   |
1182| isUseLocalName  | boolean         |  No |  Yes | Whether to use the local name for sorting. The value **true** means to use the local name for sorting, and the value **false** means the opposite.<br>If **getLanguageInfoArray** is called, the default value of **isUseLocalName** is **true**.<br>If **getRegionInfoArray** is called, the default value of **isUseLocalName** is **false**.               |
1183| isSuggestedFirst | boolean        |  No |  Yes | Whether to move the recommended language or country/region to the top in the sorting result. The value **true** means to move the recommended language or country/region to the top, and the value **false** means the opposite.<br>The default value is **true**. |
1184