1e41f4b71Sopenharmony_ci# @ohos.i18n (Internationalization) (System API)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ci 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.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci>  **NOTE**
6e41f4b71Sopenharmony_ci>  - 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.
7e41f4b71Sopenharmony_ci>
8e41f4b71Sopenharmony_ci>  - Since API version 11, some APIs of this module are supported in ArkTS widgets.
9e41f4b71Sopenharmony_ci>
10e41f4b71Sopenharmony_ci>  - This topic describes only system APIs provided by the module. For details about its public APIs, see [@ohos.i18n (Internationalization)](js-apis-intl.md).
11e41f4b71Sopenharmony_ci
12e41f4b71Sopenharmony_ci
13e41f4b71Sopenharmony_ci## Modules to Import
14e41f4b71Sopenharmony_ci
15e41f4b71Sopenharmony_ci```ts
16e41f4b71Sopenharmony_ciimport { i18n } from '@kit.LocalizationKit';
17e41f4b71Sopenharmony_ci```
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ci## System<sup>9+</sup>
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci### setSystemLanguage<sup>9+</sup>
22e41f4b71Sopenharmony_ci
23e41f4b71Sopenharmony_cistatic setSystemLanguage(language: string): void
24e41f4b71Sopenharmony_ci
25e41f4b71Sopenharmony_ciSets the system language. Currently, this API does not support real-time updating of the system language.
26e41f4b71Sopenharmony_ci
27e41f4b71Sopenharmony_ciTo listen for [COMMON_EVENT_LOCALE_CHANGED](../apis-basic-services-kit/common_event/commonEventManager-definitions.md#common_event_locale_changed) events after the system language is set, you need to add an [event subscriber](../apis-basic-services-kit/js-apis-commonEventManager.md#commoneventmanagercreatesubscriber-1).
28e41f4b71Sopenharmony_ci
29e41f4b71Sopenharmony_ci**System API**: This is a system API.
30e41f4b71Sopenharmony_ci
31e41f4b71Sopenharmony_ci**Permission required**: ohos.permission.UPDATE_CONFIGURATION
32e41f4b71Sopenharmony_ci
33e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Global.I18n
34e41f4b71Sopenharmony_ci
35e41f4b71Sopenharmony_ci**Parameters**
36e41f4b71Sopenharmony_ci
37e41f4b71Sopenharmony_ci| Name     | Type    | Mandatory  | Description   |
38e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ----- |
39e41f4b71Sopenharmony_ci| language | string | Yes   | Valid language ID.|
40e41f4b71Sopenharmony_ci
41e41f4b71Sopenharmony_ci**Error codes**
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ciFor details about the error codes, see [ohos.i18n Error Codes](errorcode-i18n.md) and [Universal Error Codes](../errorcode-universal.md).
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ci| ID | Error Message                  |
46e41f4b71Sopenharmony_ci| ------ | ---------------------- |
47e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. |
48e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
49e41f4b71Sopenharmony_ci| 890001 | Invalid parameter. Possible causes: Parameter verification failed. |
50e41f4b71Sopenharmony_ci
51e41f4b71Sopenharmony_ci**Example**
52e41f4b71Sopenharmony_ci  ```ts
53e41f4b71Sopenharmony_ci  import { BusinessError, commonEventManager } from '@kit.BasicServicesKit';
54e41f4b71Sopenharmony_ci
55e41f4b71Sopenharmony_ci  // Set the system language
56e41f4b71Sopenharmony_ci  try {
57e41f4b71Sopenharmony_ci    i18n.System.setSystemLanguage('zh'); // Set the current system language to zh.
58e41f4b71Sopenharmony_ci  } catch(error) {
59e41f4b71Sopenharmony_ci    let err: BusinessError = error as BusinessError;
60e41f4b71Sopenharmony_ci    console.error(`call System.setSystemLanguage failed, error code: ${err.code}, message: ${err.message}.`);
61e41f4b71Sopenharmony_ci  }
62e41f4b71Sopenharmony_ci 
63e41f4b71Sopenharmony_ci  // Subscribe to a common event.
64e41f4b71Sopenharmony_ci  let subscriber: commonEventManager.CommonEventSubscriber; // Used to save the created subscriber object for subsequent subscription and unsubscription.
65e41f4b71Sopenharmony_ci  let subscribeInfo: commonEventManager.CommonEventSubscribeInfo = { // Define subscriber information.
66e41f4b71Sopenharmony_ci    events: [commonEventManager.Support.COMMON_EVENT_LOCALE_CHANGED]
67e41f4b71Sopenharmony_ci  };
68e41f4b71Sopenharmony_ci  commonEventManager.createSubscriber(subscribeInfo).then((commonEventSubscriber:commonEventManager.CommonEventSubscriber) => { // Create a subscriber.
69e41f4b71Sopenharmony_ci      console.info("createSubscriber");
70e41f4b71Sopenharmony_ci      subscriber = commonEventSubscriber;
71e41f4b71Sopenharmony_ci      commonEventManager.subscribe(subscriber, (err, data) => {
72e41f4b71Sopenharmony_ci        if (err) {
73e41f4b71Sopenharmony_ci          console.error(`Failed to subscribe common event. error code: ${err.code}, message: ${err.message}.`);
74e41f4b71Sopenharmony_ci          return;
75e41f4b71Sopenharmony_ci        }
76e41f4b71Sopenharmony_ci        console.info("the subscribed event has occurred."); // Triggered when the subscribed event occurs.
77e41f4b71Sopenharmony_ci      })
78e41f4b71Sopenharmony_ci  }).catch((err: BusinessError) => {
79e41f4b71Sopenharmony_ci      console.error(`createSubscriber failed, code is ${err.code}, message is ${err.message}`);
80e41f4b71Sopenharmony_ci  });  
81e41f4b71Sopenharmony_ci  ```
82e41f4b71Sopenharmony_ci
83e41f4b71Sopenharmony_ci### setSystemRegion<sup>9+</sup>
84e41f4b71Sopenharmony_ci
85e41f4b71Sopenharmony_cistatic setSystemRegion(region: string): void
86e41f4b71Sopenharmony_ci
87e41f4b71Sopenharmony_ciSets the system region.
88e41f4b71Sopenharmony_ci
89e41f4b71Sopenharmony_ci**System API**: This is a system API.
90e41f4b71Sopenharmony_ci
91e41f4b71Sopenharmony_ci**Permission required**: ohos.permission.UPDATE_CONFIGURATION
92e41f4b71Sopenharmony_ci
93e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Global.I18n
94e41f4b71Sopenharmony_ci
95e41f4b71Sopenharmony_ci**Parameters**
96e41f4b71Sopenharmony_ci
97e41f4b71Sopenharmony_ci| Name   | Type    | Mandatory  | Description   |
98e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ----- |
99e41f4b71Sopenharmony_ci| region | string | Yes   | Valid region ID.|
100e41f4b71Sopenharmony_ci
101e41f4b71Sopenharmony_ci**Error codes**
102e41f4b71Sopenharmony_ci
103e41f4b71Sopenharmony_ciFor details about the error codes, see [ohos.i18n Error Codes](errorcode-i18n.md) and [Universal Error Codes](../errorcode-universal.md).
104e41f4b71Sopenharmony_ci
105e41f4b71Sopenharmony_ci| ID | Error Message                  |
106e41f4b71Sopenharmony_ci| ------ | ---------------------- |
107e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. |
108e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
109e41f4b71Sopenharmony_ci| 890001 | Invalid parameter. Possible causes: Parameter verification failed. |
110e41f4b71Sopenharmony_ci
111e41f4b71Sopenharmony_ci**Example**
112e41f4b71Sopenharmony_ci  ```ts
113e41f4b71Sopenharmony_ci  import { BusinessError } from '@kit.BasicServicesKit';
114e41f4b71Sopenharmony_ci
115e41f4b71Sopenharmony_ci  try {
116e41f4b71Sopenharmony_ci    i18n.System.setSystemRegion('CN'); // Set the current system region to CN.
117e41f4b71Sopenharmony_ci  } catch(error) {
118e41f4b71Sopenharmony_ci    let err: BusinessError = error as BusinessError;
119e41f4b71Sopenharmony_ci    console.error(`call System.setSystemRegion failed, error code: ${err.code}, message: ${err.message}.`);
120e41f4b71Sopenharmony_ci  }
121e41f4b71Sopenharmony_ci  ```
122e41f4b71Sopenharmony_ci
123e41f4b71Sopenharmony_ci
124e41f4b71Sopenharmony_ci
125e41f4b71Sopenharmony_ci### setSystemLocale<sup>9+</sup>
126e41f4b71Sopenharmony_ci
127e41f4b71Sopenharmony_cistatic setSystemLocale(locale: string): void
128e41f4b71Sopenharmony_ci
129e41f4b71Sopenharmony_ciSets the system locale.
130e41f4b71Sopenharmony_ci
131e41f4b71Sopenharmony_ci**System API**: This is a system API.
132e41f4b71Sopenharmony_ci
133e41f4b71Sopenharmony_ci**Permission required**: ohos.permission.UPDATE_CONFIGURATION
134e41f4b71Sopenharmony_ci
135e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Global.I18n
136e41f4b71Sopenharmony_ci
137e41f4b71Sopenharmony_ci**Parameters**
138e41f4b71Sopenharmony_ci
139e41f4b71Sopenharmony_ci| Name   | Type    | Mandatory  | Description             |
140e41f4b71Sopenharmony_ci| ------ | ------ | ---- | --------------- |
141e41f4b71Sopenharmony_ci| locale | string | Yes   | Valid locale ID, for example, **zh-CN**.|
142e41f4b71Sopenharmony_ci
143e41f4b71Sopenharmony_ci**Error codes**
144e41f4b71Sopenharmony_ci
145e41f4b71Sopenharmony_ciFor details about the error codes, see [ohos.i18n Error Codes](errorcode-i18n.md) and [Universal Error Codes](../errorcode-universal.md).
146e41f4b71Sopenharmony_ci
147e41f4b71Sopenharmony_ci| ID | Error Message                  |
148e41f4b71Sopenharmony_ci| ------ | ---------------------- |
149e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. |
150e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
151e41f4b71Sopenharmony_ci| 890001 | Invalid parameter. Possible causes: Parameter verification failed. |
152e41f4b71Sopenharmony_ci
153e41f4b71Sopenharmony_ci**Example**
154e41f4b71Sopenharmony_ci  ```ts
155e41f4b71Sopenharmony_ci  import { BusinessError } from '@kit.BasicServicesKit';
156e41f4b71Sopenharmony_ci
157e41f4b71Sopenharmony_ci  try {
158e41f4b71Sopenharmony_ci    i18n.System.setSystemLocale('zh-CN'); // Set the current system locale to zh-CN.
159e41f4b71Sopenharmony_ci  } catch(error) {
160e41f4b71Sopenharmony_ci    let err: BusinessError = error as BusinessError;
161e41f4b71Sopenharmony_ci    console.error(`call System.setSystemLocale failed, error code: ${err.code}, message: ${err.message}.`);
162e41f4b71Sopenharmony_ci  }
163e41f4b71Sopenharmony_ci  ```
164e41f4b71Sopenharmony_ci
165e41f4b71Sopenharmony_ci
166e41f4b71Sopenharmony_ci### set24HourClock<sup>9+</sup>
167e41f4b71Sopenharmony_ci
168e41f4b71Sopenharmony_cistatic set24HourClock(option: boolean): void
169e41f4b71Sopenharmony_ci
170e41f4b71Sopenharmony_ciSets the system time to the 24-hour clock.
171e41f4b71Sopenharmony_ci
172e41f4b71Sopenharmony_ci**System API**: This is a system API.
173e41f4b71Sopenharmony_ci
174e41f4b71Sopenharmony_ci**Permission required**: ohos.permission.UPDATE_CONFIGURATION
175e41f4b71Sopenharmony_ci
176e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Global.I18n
177e41f4b71Sopenharmony_ci
178e41f4b71Sopenharmony_ci**Parameters**
179e41f4b71Sopenharmony_ci
180e41f4b71Sopenharmony_ci| Name   | Type     | Mandatory  | Description                                      |
181e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ---------------------------------------- |
182e41f4b71Sopenharmony_ci| 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.|
183e41f4b71Sopenharmony_ci
184e41f4b71Sopenharmony_ci**Error codes**
185e41f4b71Sopenharmony_ci
186e41f4b71Sopenharmony_ciFor details about the error codes, see [ohos.i18n Error Codes](errorcode-i18n.md) and [Universal Error Codes](../errorcode-universal.md).
187e41f4b71Sopenharmony_ci
188e41f4b71Sopenharmony_ci| ID | Error Message                  |
189e41f4b71Sopenharmony_ci| ------ | ---------------------- |
190e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. |
191e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
192e41f4b71Sopenharmony_ci| 890001 | Invalid parameter. Possible causes: Parameter verification failed. |
193e41f4b71Sopenharmony_ci
194e41f4b71Sopenharmony_ci**Example**
195e41f4b71Sopenharmony_ci  ```ts
196e41f4b71Sopenharmony_ci  import { BusinessError } from '@kit.BasicServicesKit';
197e41f4b71Sopenharmony_ci
198e41f4b71Sopenharmony_ci  // Set the system time to the 24-hour clock.
199e41f4b71Sopenharmony_ci  try {
200e41f4b71Sopenharmony_ci    i18n.System.set24HourClock(true);
201e41f4b71Sopenharmony_ci  } catch(error) {
202e41f4b71Sopenharmony_ci    let err: BusinessError = error as BusinessError;
203e41f4b71Sopenharmony_ci    console.error(`call System.set24HourClock failed, error code: ${err.code}, message: ${err.message}.`);
204e41f4b71Sopenharmony_ci  }
205e41f4b71Sopenharmony_ci  ```
206e41f4b71Sopenharmony_ci
207e41f4b71Sopenharmony_ci### addPreferredLanguage<sup>9+</sup>
208e41f4b71Sopenharmony_ci
209e41f4b71Sopenharmony_cistatic addPreferredLanguage(language: string, index?: number): void
210e41f4b71Sopenharmony_ci
211e41f4b71Sopenharmony_ciAdds a preferred language to the specified position on the preferred language list.
212e41f4b71Sopenharmony_ci
213e41f4b71Sopenharmony_ci**System API**: This is a system API.
214e41f4b71Sopenharmony_ci
215e41f4b71Sopenharmony_ci**Permission required**: ohos.permission.UPDATE_CONFIGURATION
216e41f4b71Sopenharmony_ci
217e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Global.I18n
218e41f4b71Sopenharmony_ci
219e41f4b71Sopenharmony_ci**Parameters**
220e41f4b71Sopenharmony_ci
221e41f4b71Sopenharmony_ci| Name     | Type    | Mandatory  | Description        |
222e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ---------- |
223e41f4b71Sopenharmony_ci| language | string | Yes   | Valid ID of the language to be added as a preferred language. |
224e41f4b71Sopenharmony_ci| index    | number | No   | Position to which the preferred language is added. The default value is the length of the preferred language list.|
225e41f4b71Sopenharmony_ci
226e41f4b71Sopenharmony_ci**Error codes**
227e41f4b71Sopenharmony_ci
228e41f4b71Sopenharmony_ciFor details about the error codes, see [ohos.i18n Error Codes](errorcode-i18n.md) and [Universal Error Codes](../errorcode-universal.md).
229e41f4b71Sopenharmony_ci
230e41f4b71Sopenharmony_ci| ID | Error Message                  |
231e41f4b71Sopenharmony_ci| ------ | ---------------------- |
232e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. |
233e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
234e41f4b71Sopenharmony_ci| 890001 | Invalid parameter. Possible causes: Parameter verification failed. |
235e41f4b71Sopenharmony_ci
236e41f4b71Sopenharmony_ci**Example**
237e41f4b71Sopenharmony_ci  ```ts
238e41f4b71Sopenharmony_ci  import { BusinessError } from '@kit.BasicServicesKit';
239e41f4b71Sopenharmony_ci
240e41f4b71Sopenharmony_ci  // Add zh-CN to the preferred language list.
241e41f4b71Sopenharmony_ci  let language = 'zh-CN';
242e41f4b71Sopenharmony_ci  let index = 0;
243e41f4b71Sopenharmony_ci  try {
244e41f4b71Sopenharmony_ci    i18n.System.addPreferredLanguage(language, index); // Add zh-CN to the first place in the preferred language list.
245e41f4b71Sopenharmony_ci  } catch(error) {
246e41f4b71Sopenharmony_ci    let err: BusinessError = error as BusinessError;
247e41f4b71Sopenharmony_ci    console.error(`call System.addPreferredLanguage failed, error code: ${err.code}, message: ${err.message}.`);
248e41f4b71Sopenharmony_ci  }
249e41f4b71Sopenharmony_ci  ```
250e41f4b71Sopenharmony_ci
251e41f4b71Sopenharmony_ci### removePreferredLanguage<sup>9+</sup>
252e41f4b71Sopenharmony_ci
253e41f4b71Sopenharmony_cistatic removePreferredLanguage(index: number): void
254e41f4b71Sopenharmony_ci
255e41f4b71Sopenharmony_ciDeletes a preferred language from the specified position on the preferred language list.
256e41f4b71Sopenharmony_ci
257e41f4b71Sopenharmony_ci**System API**: This is a system API.
258e41f4b71Sopenharmony_ci
259e41f4b71Sopenharmony_ci**Permission required**: ohos.permission.UPDATE_CONFIGURATION
260e41f4b71Sopenharmony_ci
261e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Global.I18n
262e41f4b71Sopenharmony_ci
263e41f4b71Sopenharmony_ci**Parameters**
264e41f4b71Sopenharmony_ci
265e41f4b71Sopenharmony_ci| Name  | Type    | Mandatory  | Description                   |
266e41f4b71Sopenharmony_ci| ----- | ------ | ---- | --------------------- |
267e41f4b71Sopenharmony_ci| index | number | Yes   | Position of the preferred language to delete.|
268e41f4b71Sopenharmony_ci
269e41f4b71Sopenharmony_ci**Error codes**
270e41f4b71Sopenharmony_ci
271e41f4b71Sopenharmony_ciFor details about the error codes, see [ohos.i18n Error Codes](errorcode-i18n.md) and [Universal Error Codes](../errorcode-universal.md).
272e41f4b71Sopenharmony_ci
273e41f4b71Sopenharmony_ci| ID | Error Message                  |
274e41f4b71Sopenharmony_ci| ------ | ---------------------- |
275e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. |
276e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
277e41f4b71Sopenharmony_ci| 890001 | Invalid parameter. Possible causes: Parameter verification failed. |
278e41f4b71Sopenharmony_ci
279e41f4b71Sopenharmony_ci**Example**
280e41f4b71Sopenharmony_ci  ```ts
281e41f4b71Sopenharmony_ci  import { BusinessError } from '@kit.BasicServicesKit';
282e41f4b71Sopenharmony_ci
283e41f4b71Sopenharmony_ci  // Delete the first preferred language from the preferred language list.
284e41f4b71Sopenharmony_ci  let index: number = 0;
285e41f4b71Sopenharmony_ci  try {
286e41f4b71Sopenharmony_ci    i18n.System.removePreferredLanguage(index);
287e41f4b71Sopenharmony_ci  } catch(error) {
288e41f4b71Sopenharmony_ci    let err: BusinessError = error as BusinessError;
289e41f4b71Sopenharmony_ci    console.error(`call System.removePreferredLanguage failed, error code: ${err.code}, message: ${err.message}.`);
290e41f4b71Sopenharmony_ci  }
291e41f4b71Sopenharmony_ci  ```
292e41f4b71Sopenharmony_ci
293e41f4b71Sopenharmony_ci### setUsingLocalDigit<sup>9+</sup>
294e41f4b71Sopenharmony_ci
295e41f4b71Sopenharmony_cistatic setUsingLocalDigit(flag: boolean): void
296e41f4b71Sopenharmony_ci
297e41f4b71Sopenharmony_ciSpecifies whether to enable use of local digits.
298e41f4b71Sopenharmony_ci
299e41f4b71Sopenharmony_ci**System API**: This is a system API.
300e41f4b71Sopenharmony_ci
301e41f4b71Sopenharmony_ci**Permission required**: ohos.permission.UPDATE_CONFIGURATION
302e41f4b71Sopenharmony_ci
303e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Global.I18n
304e41f4b71Sopenharmony_ci
305e41f4b71Sopenharmony_ci**Parameters**
306e41f4b71Sopenharmony_ci
307e41f4b71Sopenharmony_ci| Name | Type     | Mandatory  | Description                             |
308e41f4b71Sopenharmony_ci| ---- | ------- | ---- | ------------------------------- |
309e41f4b71Sopenharmony_ci| 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.|
310e41f4b71Sopenharmony_ci
311e41f4b71Sopenharmony_ci**Error codes**
312e41f4b71Sopenharmony_ci
313e41f4b71Sopenharmony_ciFor details about the error codes, see [ohos.i18n Error Codes](errorcode-i18n.md) and [Universal Error Codes](../errorcode-universal.md).
314e41f4b71Sopenharmony_ci
315e41f4b71Sopenharmony_ci| ID | Error Message                  |
316e41f4b71Sopenharmony_ci| ------ | ---------------------- |
317e41f4b71Sopenharmony_ci| 201 | Permission verification failed. The application does not have the permission required to call the API. |
318e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
319e41f4b71Sopenharmony_ci| 890001 | Invalid parameter. Possible causes: Parameter verification failed. |
320e41f4b71Sopenharmony_ci
321e41f4b71Sopenharmony_ci**Example**
322e41f4b71Sopenharmony_ci  ```ts
323e41f4b71Sopenharmony_ci  import { BusinessError } from '@kit.BasicServicesKit';
324e41f4b71Sopenharmony_ci
325e41f4b71Sopenharmony_ci  try {
326e41f4b71Sopenharmony_ci    i18n.System.setUsingLocalDigit(true); // Enable the local digit switch.
327e41f4b71Sopenharmony_ci  } catch(error) {
328e41f4b71Sopenharmony_ci    let err: BusinessError = error as BusinessError;
329e41f4b71Sopenharmony_ci    console.error(`call System.setUsingLocalDigit failed, error code: ${err.code}, message: ${err.message}.`);
330e41f4b71Sopenharmony_ci  }
331e41f4b71Sopenharmony_ci  ```
332e41f4b71Sopenharmony_ci
333e41f4b71Sopenharmony_ci## SystemLocaleManager<sup>10+</sup>
334e41f4b71Sopenharmony_ci
335e41f4b71Sopenharmony_ci### constructor<sup>10+</sup>
336e41f4b71Sopenharmony_ci
337e41f4b71Sopenharmony_ciconstructor()
338e41f4b71Sopenharmony_ci
339e41f4b71Sopenharmony_ciCreates a **SystemLocaleManager** object.
340e41f4b71Sopenharmony_ci
341e41f4b71Sopenharmony_ci**System API**: This is a system API.
342e41f4b71Sopenharmony_ci
343e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Global.I18n
344e41f4b71Sopenharmony_ci
345e41f4b71Sopenharmony_ci**Example**
346e41f4b71Sopenharmony_ci  ```ts
347e41f4b71Sopenharmony_ci  let systemLocaleManager: i18n.SystemLocaleManager = new i18n.SystemLocaleManager();
348e41f4b71Sopenharmony_ci  ```
349e41f4b71Sopenharmony_ci
350e41f4b71Sopenharmony_ci
351e41f4b71Sopenharmony_ci### getLanguageInfoArray<sup>10+</sup>
352e41f4b71Sopenharmony_ci
353e41f4b71Sopenharmony_cigetLanguageInfoArray(languages: Array&lt;string&gt;, options?: SortOptions): Array&lt;LocaleItem&gt;
354e41f4b71Sopenharmony_ci
355e41f4b71Sopenharmony_ciObtains the language sorting array.
356e41f4b71Sopenharmony_ci
357e41f4b71Sopenharmony_ci**System API**: This is a system API.
358e41f4b71Sopenharmony_ci
359e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Global.I18n
360e41f4b71Sopenharmony_ci
361e41f4b71Sopenharmony_ci**Parameters**
362e41f4b71Sopenharmony_ci
363e41f4b71Sopenharmony_ci|   Name |      Type     | Mandatory|     Description     |
364e41f4b71Sopenharmony_ci| --------- | ------------- | ---- | ------------- |
365e41f4b71Sopenharmony_ci| languages | Array&lt;string&gt; | Yes  | Valid IDs of the languages to be sorted.|
366e41f4b71Sopenharmony_ci| options   | [SortOptions](#sortoptions10)   | No  | Language sorting option.|
367e41f4b71Sopenharmony_ci
368e41f4b71Sopenharmony_ci**Return value**
369e41f4b71Sopenharmony_ci
370e41f4b71Sopenharmony_ci|       Type       |         Description         |
371e41f4b71Sopenharmony_ci| ----------------- | -------------------- |
372e41f4b71Sopenharmony_ci| Array&lt;[LocaleItem](#localeitem10)&gt; | Language list after sorting.|
373e41f4b71Sopenharmony_ci
374e41f4b71Sopenharmony_ci**Error codes**
375e41f4b71Sopenharmony_ci
376e41f4b71Sopenharmony_ciFor details about the error codes, see [ohos.i18n Error Codes](errorcode-i18n.md) and [Universal Error Codes](../errorcode-universal.md).
377e41f4b71Sopenharmony_ci
378e41f4b71Sopenharmony_ci| ID | Error Message                  |
379e41f4b71Sopenharmony_ci| ------ | ---------------------- |
380e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. |
381e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
382e41f4b71Sopenharmony_ci| 890001 | Invalid parameter. Possible causes: Parameter verification failed. |
383e41f4b71Sopenharmony_ci
384e41f4b71Sopenharmony_ci**Example**
385e41f4b71Sopenharmony_ci  ```ts
386e41f4b71Sopenharmony_ci  import { BusinessError } from '@kit.BasicServicesKit';
387e41f4b71Sopenharmony_ci
388e41f4b71Sopenharmony_ci  // Assume that the system language is zh-Hans, the system region is CN, and the system locale is zh-Hans-CN.
389e41f4b71Sopenharmony_ci  let systemLocaleManager: i18n.SystemLocaleManager = new i18n.SystemLocaleManager();
390e41f4b71Sopenharmony_ci  let languages: string[] = ["zh-Hans", "en-US", "pt", "ar"];
391e41f4b71Sopenharmony_ci  let sortOptions: i18n.SortOptions = {locale: "zh-Hans-CN", isUseLocalName: true, isSuggestedFirst: true};
392e41f4b71Sopenharmony_ci  try {
393e41f4b71Sopenharmony_ci      // The language list after sorting is [zh-Hans, en-US, pt, ar].
394e41f4b71Sopenharmony_ci      let sortedLanguages: Array<i18n.LocaleItem> = systemLocaleManager.getLanguageInfoArray(languages, sortOptions);
395e41f4b71Sopenharmony_ci  } catch(error) {
396e41f4b71Sopenharmony_ci      let err: BusinessError = error as BusinessError;
397e41f4b71Sopenharmony_ci      console.error(`call systemLocaleManager.getLanguageInfoArray failed, error code: ${err.code}, message: ${err.message}.`);
398e41f4b71Sopenharmony_ci  }
399e41f4b71Sopenharmony_ci  ```
400e41f4b71Sopenharmony_ci
401e41f4b71Sopenharmony_ci
402e41f4b71Sopenharmony_ci### getRegionInfoArray<sup>10+</sup>
403e41f4b71Sopenharmony_ci
404e41f4b71Sopenharmony_cigetRegionInfoArray(regions: Array&lt;string&gt;, options?: SortOptions): Array&lt;LocaleItem&gt;
405e41f4b71Sopenharmony_ci
406e41f4b71Sopenharmony_ciObtains the country/region sorting array.
407e41f4b71Sopenharmony_ci
408e41f4b71Sopenharmony_ci**System API**: This is a system API.
409e41f4b71Sopenharmony_ci
410e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Global.I18n
411e41f4b71Sopenharmony_ci
412e41f4b71Sopenharmony_ci**Parameters**
413e41f4b71Sopenharmony_ci
414e41f4b71Sopenharmony_ci|   Name |      Type     | Mandatory|     Description     |
415e41f4b71Sopenharmony_ci| --------- | ------------- | ---- | ------------- |
416e41f4b71Sopenharmony_ci| regions   | Array&lt;string&gt; | Yes  | Valid IDs of the countries or regions to be sorted.|
417e41f4b71Sopenharmony_ci| options   | [SortOptions](#sortoptions10)   | No  | Country/region sorting option. The default value of **locale** is the system locale, the default value of **isUseLocalName** is **false**, and the default value of **isSuggestedFirst** is **true**.|
418e41f4b71Sopenharmony_ci
419e41f4b71Sopenharmony_ci**Return value**
420e41f4b71Sopenharmony_ci
421e41f4b71Sopenharmony_ci|       Type       |         Description         |
422e41f4b71Sopenharmony_ci| ----------------- | -------------------- |
423e41f4b71Sopenharmony_ci| Array&lt;[LocaleItem](#localeitem10)&gt; | Country/region list after sorting.|
424e41f4b71Sopenharmony_ci
425e41f4b71Sopenharmony_ci**Error codes**
426e41f4b71Sopenharmony_ci
427e41f4b71Sopenharmony_ciFor details about the error codes, see [ohos.i18n Error Codes](errorcode-i18n.md) and [Universal Error Codes](../errorcode-universal.md).
428e41f4b71Sopenharmony_ci
429e41f4b71Sopenharmony_ci| ID | Error Message                  |
430e41f4b71Sopenharmony_ci| ------ | ---------------------- |
431e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. |
432e41f4b71Sopenharmony_ci| 401 | Parameter error. Possible causes: 1.Mandatory parameters are left unspecified; 2.Incorrect parameter types. |
433e41f4b71Sopenharmony_ci| 890001 | Invalid parameter. Possible causes: Parameter verification failed. |
434e41f4b71Sopenharmony_ci
435e41f4b71Sopenharmony_ci**Example**
436e41f4b71Sopenharmony_ci  ```ts
437e41f4b71Sopenharmony_ci  import { BusinessError } from '@kit.BasicServicesKit';
438e41f4b71Sopenharmony_ci
439e41f4b71Sopenharmony_ci  // Assume that the system language is zh-Hans, the system region is CN, and the system locale is zh-Hans-CN.
440e41f4b71Sopenharmony_ci  let systemLocaleManager: i18n.SystemLocaleManager = new i18n.SystemLocaleManager();
441e41f4b71Sopenharmony_ci  let regions: string[] = ["CN", "US", "PT", "EG"];
442e41f4b71Sopenharmony_ci  let sortOptions: i18n.SortOptions = {locale: "zh-Hans-CN", isUseLocalName: false, isSuggestedFirst: true};
443e41f4b71Sopenharmony_ci  try {
444e41f4b71Sopenharmony_ci      // The country/region list after sorting is [CN, EG, US, PT].
445e41f4b71Sopenharmony_ci      let sortedRegions: Array<i18n.LocaleItem> = systemLocaleManager.getRegionInfoArray(regions, sortOptions);
446e41f4b71Sopenharmony_ci  } catch(error) {
447e41f4b71Sopenharmony_ci      let err: BusinessError = error as BusinessError;
448e41f4b71Sopenharmony_ci      console.error(`call systemLocaleManager.getRegionInfoArray failed, error code: ${err.code}, message: ${err.message}.`);
449e41f4b71Sopenharmony_ci  }
450e41f4b71Sopenharmony_ci  ```
451e41f4b71Sopenharmony_ci
452e41f4b71Sopenharmony_ci### getTimeZoneCityItemArray<sup>10+</sup>
453e41f4b71Sopenharmony_ci
454e41f4b71Sopenharmony_cistatic getTimeZoneCityItemArray(): Array&lt;TimeZoneCityItem&gt;
455e41f4b71Sopenharmony_ci
456e41f4b71Sopenharmony_ciObtains the array of time zone city items after sorting.
457e41f4b71Sopenharmony_ci
458e41f4b71Sopenharmony_ci**System API**: This is a system API.
459e41f4b71Sopenharmony_ci
460e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Global.I18n
461e41f4b71Sopenharmony_ci
462e41f4b71Sopenharmony_ci**Return value**
463e41f4b71Sopenharmony_ci
464e41f4b71Sopenharmony_ci|       Type       |         Description         |
465e41f4b71Sopenharmony_ci| ----------------- | -------------------- |
466e41f4b71Sopenharmony_ci| Array&lt;[TimeZoneCityItem](#timezonecityitem10)&gt; | Array of time zone city items.|
467e41f4b71Sopenharmony_ci
468e41f4b71Sopenharmony_ci**Error codes**
469e41f4b71Sopenharmony_ci
470e41f4b71Sopenharmony_ciFor details about the error codes, see [ohos.i18n Error Codes](errorcode-i18n.md) and [Universal Error Codes](../errorcode-universal.md).
471e41f4b71Sopenharmony_ci
472e41f4b71Sopenharmony_ci| ID | Error Message                  |
473e41f4b71Sopenharmony_ci| ------ | ---------------------- |
474e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. |
475e41f4b71Sopenharmony_ci
476e41f4b71Sopenharmony_ci**Example**
477e41f4b71Sopenharmony_ci  ```ts
478e41f4b71Sopenharmony_ci  import { BusinessError } from '@kit.BasicServicesKit';
479e41f4b71Sopenharmony_ci
480e41f4b71Sopenharmony_ci  try {
481e41f4b71Sopenharmony_ci    let timeZoneCityItemArray: Array<i18n.TimeZoneCityItem> = i18n.SystemLocaleManager.getTimeZoneCityItemArray();
482e41f4b71Sopenharmony_ci    for (let i = 0; i < timeZoneCityItemArray.length; i++) {
483e41f4b71Sopenharmony_ci        console.log(timeZoneCityItemArray[i].zoneId + ", " + timeZoneCityItemArray[i].cityId + ", " + timeZoneCityItemArray[i].cityDisplayName +
484e41f4b71Sopenharmony_ci            ", " + timeZoneCityItemArray[i].offset + "\r\n");
485e41f4b71Sopenharmony_ci    }
486e41f4b71Sopenharmony_ci  } catch(error) {
487e41f4b71Sopenharmony_ci    let err: BusinessError = error as BusinessError;
488e41f4b71Sopenharmony_ci    console.error(`call SystemLocaleManager.getTimeZoneCityItemArray failed, error code: ${err.code}, message: ${err.message}.`);
489e41f4b71Sopenharmony_ci  }
490e41f4b71Sopenharmony_ci  ```
491e41f4b71Sopenharmony_ci
492e41f4b71Sopenharmony_ci## LocaleItem<sup>10+</sup>
493e41f4b71Sopenharmony_ci
494e41f4b71Sopenharmony_ciRepresents the list of languages or countries/regions sorted by **SystemLocaleManager**.
495e41f4b71Sopenharmony_ci
496e41f4b71Sopenharmony_ci**System API**: This is a system API.
497e41f4b71Sopenharmony_ci
498e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Global.I18n
499e41f4b71Sopenharmony_ci
500e41f4b71Sopenharmony_ci| Name           | Type           |  Mandatory  |  Description                                  |
501e41f4b71Sopenharmony_ci| --------------- | --------------- | ------ | --------------------------------------- |
502e41f4b71Sopenharmony_ci| id              | string          |   Yes  | Language code or country/region code, for example, **zh** or **CN**.   |
503e41f4b71Sopenharmony_ci| suggestionType  | [SuggestionType](#suggestiontype10)  |   Yes | Language or country/region suggestion type.                 |
504e41f4b71Sopenharmony_ci| displayName     | string          |  Yes  | Displayed name of ID in the locale of **SystemLocaleManager**.|
505e41f4b71Sopenharmony_ci| localName       | string          |  No  | Local name of the ID.                          |
506e41f4b71Sopenharmony_ci
507e41f4b71Sopenharmony_ci## TimeZoneCityItem<sup>10+</sup>
508e41f4b71Sopenharmony_ci
509e41f4b71Sopenharmony_ciRepresents the time zone and city combination information.
510e41f4b71Sopenharmony_ci
511e41f4b71Sopenharmony_ci**System API**: This is a system API.
512e41f4b71Sopenharmony_ci
513e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Global.I18n
514e41f4b71Sopenharmony_ci
515e41f4b71Sopenharmony_ci| Name           | Type            |  Mandatory  |  Description                                  |
516e41f4b71Sopenharmony_ci| --------------- | --------------- | ------  | --------------------------------------- |
517e41f4b71Sopenharmony_ci| zoneId          | string          |   Yes   | Time zone ID, for example, **Asia/Shanghai**.             |
518e41f4b71Sopenharmony_ci| cityId          | string          |   Yes   | City ID, for example, **Shanghai**.                  |
519e41f4b71Sopenharmony_ci| cityDisplayName | string          |   Yes   | Displayed name of the city ID in the system locale.         |
520e41f4b71Sopenharmony_ci| offset          | int             |   Yes   | Offset of the time zone ID.                        |
521e41f4b71Sopenharmony_ci| zoneDisplayName | string          |   Yes   | Displayed name of the time zone ID in the system locale.         |
522e41f4b71Sopenharmony_ci| rawOffset       | int             |   No   | Fixed offset of the time zone ID.                      |
523e41f4b71Sopenharmony_ci
524e41f4b71Sopenharmony_ci
525e41f4b71Sopenharmony_ci## SuggestionType<sup>10+</sup>
526e41f4b71Sopenharmony_ci
527e41f4b71Sopenharmony_ciRepresents the language or country/region suggestion type.
528e41f4b71Sopenharmony_ci
529e41f4b71Sopenharmony_ci**System API**: This is a system API.
530e41f4b71Sopenharmony_ci
531e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Global.I18n
532e41f4b71Sopenharmony_ci
533e41f4b71Sopenharmony_ci| Name                  | Value | Description  |
534e41f4b71Sopenharmony_ci| ---------------------- | ---- | ---- |
535e41f4b71Sopenharmony_ci| SUGGESTION_TYPE_NONE   | 0x00 | Not a recommended language or country/region.|
536e41f4b71Sopenharmony_ci| SUGGESTION_TYPE_RELATED| 0x01 | Country/region recommended by the system language or language recommended by the system country/region.|
537e41f4b71Sopenharmony_ci| SUGGESTION_TYPE_SIM    | 0x02 | Language recommended by the country/region of the SIM card.|
538e41f4b71Sopenharmony_ci
539e41f4b71Sopenharmony_ci
540e41f4b71Sopenharmony_ci## SortOptions<sup>10+<sup>
541e41f4b71Sopenharmony_ci
542e41f4b71Sopenharmony_ciRepresents the language or country/region sorting option.
543e41f4b71Sopenharmony_ci
544e41f4b71Sopenharmony_ci**System API**: This is a system API.
545e41f4b71Sopenharmony_ci
546e41f4b71Sopenharmony_ci**System capability**: SystemCapability.Global.I18n
547e41f4b71Sopenharmony_ci
548e41f4b71Sopenharmony_ci| Name           | Type           |  Mandatory|   Description                                |
549e41f4b71Sopenharmony_ci| --------------- | --------------- | ---- | --------------------------------------- |
550e41f4b71Sopenharmony_ci| locale          | string          |  No | System locale, for example, **zh-Hans-CN**. The default value of **locale** is the system locale.   |
551e41f4b71Sopenharmony_ci| isUseLocalName  | boolean         |  No | Whether to use the local name for sorting. If **getLanguageInfoArray** is called, the default value of **isUseLocalName** is **true**. If **getRegionInfoArray** is called, the default value of **isUseLocalName** is **false**.               |
552e41f4b71Sopenharmony_ci| isSuggestedFirst | boolean        |  No | Whether to move the recommended language or country/region to the top in the sorting result. The default value of **isSuggestedFirst** is **true**. |
553