1e41f4b71Sopenharmony_ci# @ohos.i18n (国际化-I18n)(系统接口) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci 本模块提供系统相关的或者增强的国际化能力,包括区域管理、电话号码处理、日历等,相关接口为ECMA 402标准中未定义的补充接口。[Intl模块](js-apis-intl.md)提供了ECMA 402标准定义的基础国际化接口,与本模块共同使用可提供完整地国际化支持能力。 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ci> **说明:** 6e41f4b71Sopenharmony_ci> - 本模块首批接口从API version 7开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 7e41f4b71Sopenharmony_ci> 8e41f4b71Sopenharmony_ci> - 从API version 11开始,本模块部分接口支持在ArkTS卡片中使用。 9e41f4b71Sopenharmony_ci> 10e41f4b71Sopenharmony_ci> - 当前页面仅包含本模块的系统接口,其他公开接口参见[@ohos.i18n (国际化-I18n)](js-apis-intl.md)。 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ci## 导入模块 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_ci设置系统语言。当前调用该接口不支持系统界面语言的实时刷新。 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci若设置系统语言后,需要[监听事件](../apis-basic-services-kit/common_event/commonEventManager-definitions.md#common_event_locale_changed)OHOS::EventFwk::CommonEventSupport::COMMON_EVENT_LOCALE_CHANGED,可以[订阅](../apis-basic-services-kit/js-apis-commonEventManager.md#commoneventmanagercreatesubscriber-1)该事件。 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.UPDATE_CONFIGURATION 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Global.I18n 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ci**参数:** 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 38e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ----- | 39e41f4b71Sopenharmony_ci| language | string | 是 | 合法的语言ID。 | 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci**错误码:** 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[ohos.i18n错误码](errorcode-i18n.md)和[通用错误码](../errorcode-universal.md)。 44e41f4b71Sopenharmony_ci 45e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 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**示例:** 52e41f4b71Sopenharmony_ci ```ts 53e41f4b71Sopenharmony_ci import { BusinessError, commonEventManager } from '@kit.BasicServicesKit'; 54e41f4b71Sopenharmony_ci 55e41f4b71Sopenharmony_ci // 设置系统语言 56e41f4b71Sopenharmony_ci try { 57e41f4b71Sopenharmony_ci i18n.System.setSystemLanguage('zh'); // 设置系统当前语言为 "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 // 订阅公共事件 64e41f4b71Sopenharmony_ci let subscriber: commonEventManager.CommonEventSubscriber; // 用于保存创建成功的订阅者对象,后续使用其完成订阅及退订的动作 65e41f4b71Sopenharmony_ci let subscribeInfo: commonEventManager.CommonEventSubscribeInfo = { // 订阅者信息 66e41f4b71Sopenharmony_ci events: [commonEventManager.Support.COMMON_EVENT_LOCALE_CHANGED] 67e41f4b71Sopenharmony_ci }; 68e41f4b71Sopenharmony_ci commonEventManager.createSubscriber(subscribeInfo).then((commonEventSubscriber:commonEventManager.CommonEventSubscriber) => { // 创建订阅者 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."); // 订阅的事件发生时执行 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_ci设置系统区域。 88e41f4b71Sopenharmony_ci 89e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。 90e41f4b71Sopenharmony_ci 91e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.UPDATE_CONFIGURATION 92e41f4b71Sopenharmony_ci 93e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Global.I18n 94e41f4b71Sopenharmony_ci 95e41f4b71Sopenharmony_ci**参数:** 96e41f4b71Sopenharmony_ci 97e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 98e41f4b71Sopenharmony_ci| ------ | ------ | ---- | ----- | 99e41f4b71Sopenharmony_ci| region | string | 是 | 合法的地区ID。 | 100e41f4b71Sopenharmony_ci 101e41f4b71Sopenharmony_ci**错误码:** 102e41f4b71Sopenharmony_ci 103e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[ohos.i18n错误码](errorcode-i18n.md)和[通用错误码](../errorcode-universal.md)。 104e41f4b71Sopenharmony_ci 105e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 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**示例:** 112e41f4b71Sopenharmony_ci ```ts 113e41f4b71Sopenharmony_ci import { BusinessError } from '@kit.BasicServicesKit'; 114e41f4b71Sopenharmony_ci 115e41f4b71Sopenharmony_ci try { 116e41f4b71Sopenharmony_ci i18n.System.setSystemRegion('CN'); // 设置系统当前地区为 "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_ci设置系统Locale。 130e41f4b71Sopenharmony_ci 131e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。 132e41f4b71Sopenharmony_ci 133e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.UPDATE_CONFIGURATION 134e41f4b71Sopenharmony_ci 135e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Global.I18n 136e41f4b71Sopenharmony_ci 137e41f4b71Sopenharmony_ci**参数:** 138e41f4b71Sopenharmony_ci 139e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 140e41f4b71Sopenharmony_ci| ------ | ------ | ---- | --------------- | 141e41f4b71Sopenharmony_ci| locale | string | 是 | 合法的区域ID,例如zh-CN。 | 142e41f4b71Sopenharmony_ci 143e41f4b71Sopenharmony_ci**错误码:** 144e41f4b71Sopenharmony_ci 145e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[ohos.i18n错误码](errorcode-i18n.md)和[通用错误码](../errorcode-universal.md)。 146e41f4b71Sopenharmony_ci 147e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 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**示例:** 154e41f4b71Sopenharmony_ci ```ts 155e41f4b71Sopenharmony_ci import { BusinessError } from '@kit.BasicServicesKit'; 156e41f4b71Sopenharmony_ci 157e41f4b71Sopenharmony_ci try { 158e41f4b71Sopenharmony_ci i18n.System.setSystemLocale('zh-CN'); // 设置系统当前Locale为 "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_ci设置系统时间为24小时。 171e41f4b71Sopenharmony_ci 172e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。 173e41f4b71Sopenharmony_ci 174e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.UPDATE_CONFIGURATION 175e41f4b71Sopenharmony_ci 176e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Global.I18n 177e41f4b71Sopenharmony_ci 178e41f4b71Sopenharmony_ci**参数:** 179e41f4b71Sopenharmony_ci 180e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 181e41f4b71Sopenharmony_ci| ------ | ------- | ---- | ---------------------------------------- | 182e41f4b71Sopenharmony_ci| option | boolean | 是 | option为true,表示开启系统24小时制开关;返回false,表示关闭系统24小时开关。 | 183e41f4b71Sopenharmony_ci 184e41f4b71Sopenharmony_ci**错误码:** 185e41f4b71Sopenharmony_ci 186e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[ohos.i18n错误码](errorcode-i18n.md)和[通用错误码](../errorcode-universal.md)。 187e41f4b71Sopenharmony_ci 188e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 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**示例:** 195e41f4b71Sopenharmony_ci ```ts 196e41f4b71Sopenharmony_ci import { BusinessError } from '@kit.BasicServicesKit'; 197e41f4b71Sopenharmony_ci 198e41f4b71Sopenharmony_ci // 将系统时间设置为24小时制 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_ci在系统偏好语言列表中的指定位置添加偏好语言。 212e41f4b71Sopenharmony_ci 213e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。 214e41f4b71Sopenharmony_ci 215e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.UPDATE_CONFIGURATION 216e41f4b71Sopenharmony_ci 217e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Global.I18n 218e41f4b71Sopenharmony_ci 219e41f4b71Sopenharmony_ci**参数:** 220e41f4b71Sopenharmony_ci 221e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 222e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ---------- | 223e41f4b71Sopenharmony_ci| language | string | 是 | 待添加的偏好语言,要求是合法的语言ID。 | 224e41f4b71Sopenharmony_ci| index | number | 否 | 偏好语言的添加位置。默认值:系统偏好语言列表长度。 | 225e41f4b71Sopenharmony_ci 226e41f4b71Sopenharmony_ci**错误码:** 227e41f4b71Sopenharmony_ci 228e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[ohos.i18n错误码](errorcode-i18n.md)和[通用错误码](../errorcode-universal.md)。 229e41f4b71Sopenharmony_ci 230e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 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**示例:** 237e41f4b71Sopenharmony_ci ```ts 238e41f4b71Sopenharmony_ci import { BusinessError } from '@kit.BasicServicesKit'; 239e41f4b71Sopenharmony_ci 240e41f4b71Sopenharmony_ci // 将语言zh-CN添加到系统偏好语言列表中 241e41f4b71Sopenharmony_ci let language = 'zh-CN'; 242e41f4b71Sopenharmony_ci let index = 0; 243e41f4b71Sopenharmony_ci try { 244e41f4b71Sopenharmony_ci i18n.System.addPreferredLanguage(language, index); // 将zh-CN添加到系统偏好语言列表的第1位 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_ci删除系统偏好语言列表中指定位置的偏好语言。 256e41f4b71Sopenharmony_ci 257e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。 258e41f4b71Sopenharmony_ci 259e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.UPDATE_CONFIGURATION 260e41f4b71Sopenharmony_ci 261e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Global.I18n 262e41f4b71Sopenharmony_ci 263e41f4b71Sopenharmony_ci**参数:** 264e41f4b71Sopenharmony_ci 265e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 266e41f4b71Sopenharmony_ci| ----- | ------ | ---- | --------------------- | 267e41f4b71Sopenharmony_ci| index | number | 是 | 待删除偏好语言在系统偏好语言列表中的位置。 | 268e41f4b71Sopenharmony_ci 269e41f4b71Sopenharmony_ci**错误码:** 270e41f4b71Sopenharmony_ci 271e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[ohos.i18n错误码](errorcode-i18n.md)和[通用错误码](../errorcode-universal.md)。 272e41f4b71Sopenharmony_ci 273e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 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**示例:** 280e41f4b71Sopenharmony_ci ```ts 281e41f4b71Sopenharmony_ci import { BusinessError } from '@kit.BasicServicesKit'; 282e41f4b71Sopenharmony_ci 283e41f4b71Sopenharmony_ci // 删除系统偏好语言列表中的第一个偏好语言 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_ci设置系统是否使用本地数字。 298e41f4b71Sopenharmony_ci 299e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。 300e41f4b71Sopenharmony_ci 301e41f4b71Sopenharmony_ci**需要权限**:ohos.permission.UPDATE_CONFIGURATION 302e41f4b71Sopenharmony_ci 303e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Global.I18n 304e41f4b71Sopenharmony_ci 305e41f4b71Sopenharmony_ci**参数:** 306e41f4b71Sopenharmony_ci 307e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 308e41f4b71Sopenharmony_ci| ---- | ------- | ---- | ------------------------------- | 309e41f4b71Sopenharmony_ci| flag | boolean | 是 | true表示打开本地数字开关,false表示关闭本地数字开关。 | 310e41f4b71Sopenharmony_ci 311e41f4b71Sopenharmony_ci**错误码:** 312e41f4b71Sopenharmony_ci 313e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[ohos.i18n错误码](errorcode-i18n.md)和[通用错误码](../errorcode-universal.md)。 314e41f4b71Sopenharmony_ci 315e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 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**示例:** 322e41f4b71Sopenharmony_ci ```ts 323e41f4b71Sopenharmony_ci import { BusinessError } from '@kit.BasicServicesKit'; 324e41f4b71Sopenharmony_ci 325e41f4b71Sopenharmony_ci try { 326e41f4b71Sopenharmony_ci i18n.System.setUsingLocalDigit(true); // 打开本地化数字开关 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_ci创建SystemLocaleManager对象。 340e41f4b71Sopenharmony_ci 341e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。 342e41f4b71Sopenharmony_ci 343e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Global.I18n 344e41f4b71Sopenharmony_ci 345e41f4b71Sopenharmony_ci**示例:** 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<string>, options?: SortOptions): Array<LocaleItem> 354e41f4b71Sopenharmony_ci 355e41f4b71Sopenharmony_ci获取语言排序数组。 356e41f4b71Sopenharmony_ci 357e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。 358e41f4b71Sopenharmony_ci 359e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Global.I18n 360e41f4b71Sopenharmony_ci 361e41f4b71Sopenharmony_ci**参数:** 362e41f4b71Sopenharmony_ci 363e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 364e41f4b71Sopenharmony_ci| --------- | ------------- | ---- | ------------- | 365e41f4b71Sopenharmony_ci| languages | Array<string> | 是 | 待排序语言列表,要求是合法的语言ID。| 366e41f4b71Sopenharmony_ci| options | [SortOptions](#sortoptions10) | 否 | 语言排序选项。 | 367e41f4b71Sopenharmony_ci 368e41f4b71Sopenharmony_ci**返回值:** 369e41f4b71Sopenharmony_ci 370e41f4b71Sopenharmony_ci| 类型 | 说明 | 371e41f4b71Sopenharmony_ci| ----------------- | -------------------- | 372e41f4b71Sopenharmony_ci| Array<[LocaleItem](#localeitem10)> | 排序后的语言列表信息。 | 373e41f4b71Sopenharmony_ci 374e41f4b71Sopenharmony_ci**错误码:** 375e41f4b71Sopenharmony_ci 376e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[ohos.i18n错误码](errorcode-i18n.md)和[通用错误码](../errorcode-universal.md)。 377e41f4b71Sopenharmony_ci 378e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 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**示例:** 385e41f4b71Sopenharmony_ci ```ts 386e41f4b71Sopenharmony_ci import { BusinessError } from '@kit.BasicServicesKit'; 387e41f4b71Sopenharmony_ci 388e41f4b71Sopenharmony_ci // 当系统语言为zh-Hans,系统地区为CN,系统Locale为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 // 排序后的语言顺序为: [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<string>, options?: SortOptions): Array<LocaleItem> 405e41f4b71Sopenharmony_ci 406e41f4b71Sopenharmony_ci获取国家或地区排序数组。 407e41f4b71Sopenharmony_ci 408e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。 409e41f4b71Sopenharmony_ci 410e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Global.I18n 411e41f4b71Sopenharmony_ci 412e41f4b71Sopenharmony_ci**参数:** 413e41f4b71Sopenharmony_ci 414e41f4b71Sopenharmony_ci| 参数名 | 类型 | 必填 | 说明 | 415e41f4b71Sopenharmony_ci| --------- | ------------- | ---- | ------------- | 416e41f4b71Sopenharmony_ci| regions | Array<string> | 是 | 待排序的国家或地区列表,要求是合法的国家或地区ID。| 417e41f4b71Sopenharmony_ci| options | [SortOptions](#sortoptions10) | 否 | 国家或地区排序选项。默认值:locale的默认值为系统Locale,isUseLocalName的默认值为false,isSuggestedFirst的默认值为true。 | 418e41f4b71Sopenharmony_ci 419e41f4b71Sopenharmony_ci**返回值:** 420e41f4b71Sopenharmony_ci 421e41f4b71Sopenharmony_ci| 类型 | 说明 | 422e41f4b71Sopenharmony_ci| ----------------- | -------------------- | 423e41f4b71Sopenharmony_ci| Array<[LocaleItem](#localeitem10)> | 排序后的国家或地区列表信息。 | 424e41f4b71Sopenharmony_ci 425e41f4b71Sopenharmony_ci**错误码:** 426e41f4b71Sopenharmony_ci 427e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[ohos.i18n错误码](errorcode-i18n.md)和[通用错误码](../errorcode-universal.md)。 428e41f4b71Sopenharmony_ci 429e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 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**示例:** 436e41f4b71Sopenharmony_ci ```ts 437e41f4b71Sopenharmony_ci import { BusinessError } from '@kit.BasicServicesKit'; 438e41f4b71Sopenharmony_ci 439e41f4b71Sopenharmony_ci // 当系统语言为zh-Hans,系统地区为CN,系统Locale为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 // 排序后的地区顺序为: [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<TimeZoneCityItem> 455e41f4b71Sopenharmony_ci 456e41f4b71Sopenharmony_ci获取时区城市组合信息的数组。 457e41f4b71Sopenharmony_ci 458e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。 459e41f4b71Sopenharmony_ci 460e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Global.I18n 461e41f4b71Sopenharmony_ci 462e41f4b71Sopenharmony_ci**返回值:** 463e41f4b71Sopenharmony_ci 464e41f4b71Sopenharmony_ci| 类型 | 说明 | 465e41f4b71Sopenharmony_ci| ----------------- | -------------------- | 466e41f4b71Sopenharmony_ci| Array<[TimeZoneCityItem](#timezonecityitem10)> | 排序后的时区城市组合信息数组。 | 467e41f4b71Sopenharmony_ci 468e41f4b71Sopenharmony_ci**错误码:** 469e41f4b71Sopenharmony_ci 470e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[ohos.i18n错误码](errorcode-i18n.md)和[通用错误码](../errorcode-universal.md)。 471e41f4b71Sopenharmony_ci 472e41f4b71Sopenharmony_ci| 错误码ID | 错误信息 | 473e41f4b71Sopenharmony_ci| ------ | ---------------------- | 474e41f4b71Sopenharmony_ci| 202 | Permission verification failed. A non-system application calls a system API. | 475e41f4b71Sopenharmony_ci 476e41f4b71Sopenharmony_ci**示例:** 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_ciSystemLocaleManager对语言或国家地区列表的排序结果信息项。 495e41f4b71Sopenharmony_ci 496e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。 497e41f4b71Sopenharmony_ci 498e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Global.I18n 499e41f4b71Sopenharmony_ci 500e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 501e41f4b71Sopenharmony_ci| --------------- | --------------- | ------ | --------------------------------------- | 502e41f4b71Sopenharmony_ci| id | string | 是 | 语言代码或国家地区代码,如"zh"、"CN"。 | 503e41f4b71Sopenharmony_ci| suggestionType | [SuggestionType](#suggestiontype10) | 是 | 语言或国家地区推荐类型。 | 504e41f4b71Sopenharmony_ci| displayName | string | 是 | id在SystemLocaleManager的Locale下的表示。| 505e41f4b71Sopenharmony_ci| localName | string | 否 | id的本地名称。 | 506e41f4b71Sopenharmony_ci 507e41f4b71Sopenharmony_ci## TimeZoneCityItem<sup>10+</sup> 508e41f4b71Sopenharmony_ci 509e41f4b71Sopenharmony_ci时区城市组合信息。 510e41f4b71Sopenharmony_ci 511e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。 512e41f4b71Sopenharmony_ci 513e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Global.I18n 514e41f4b71Sopenharmony_ci 515e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 516e41f4b71Sopenharmony_ci| --------------- | --------------- | ------ | --------------------------------------- | 517e41f4b71Sopenharmony_ci| zoneId | string | 是 | 时区Id,例如Asia/Shanghai。 | 518e41f4b71Sopenharmony_ci| cityId | string | 是 | 城市Id,例如Shanghai。 | 519e41f4b71Sopenharmony_ci| cityDisplayName | string | 是 | 城市Id在系统Locale下显示的名称。 | 520e41f4b71Sopenharmony_ci| offset | int | 是 | 时区Id的偏移量。 | 521e41f4b71Sopenharmony_ci| zoneDisplayName | string | 是 | 时区Id在系统Locale下显示的名称。 | 522e41f4b71Sopenharmony_ci| rawOffset | int | 否 | 时区Id的固定偏移量。 | 523e41f4b71Sopenharmony_ci 524e41f4b71Sopenharmony_ci 525e41f4b71Sopenharmony_ci## SuggestionType<sup>10+</sup> 526e41f4b71Sopenharmony_ci 527e41f4b71Sopenharmony_ci语言或国家地区的推荐类型。 528e41f4b71Sopenharmony_ci 529e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。 530e41f4b71Sopenharmony_ci 531e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Global.I18n 532e41f4b71Sopenharmony_ci 533e41f4b71Sopenharmony_ci| 名称 | 值 | 说明 | 534e41f4b71Sopenharmony_ci| ---------------------- | ---- | ---- | 535e41f4b71Sopenharmony_ci| SUGGESTION_TYPE_NONE | 0x00 | 非推荐语言或国家地区。 | 536e41f4b71Sopenharmony_ci| SUGGESTION_TYPE_RELATED| 0x01 | 系统语言推荐的国家地区或系统国家地区推荐的语言。 | 537e41f4b71Sopenharmony_ci| SUGGESTION_TYPE_SIM | 0x02 | Sim卡国家地区推荐的语言。 | 538e41f4b71Sopenharmony_ci 539e41f4b71Sopenharmony_ci 540e41f4b71Sopenharmony_ci## SortOptions<sup>10+<sup> 541e41f4b71Sopenharmony_ci 542e41f4b71Sopenharmony_ci语言或国家地区排序选项。 543e41f4b71Sopenharmony_ci 544e41f4b71Sopenharmony_ci**系统接口**:此接口为系统接口。 545e41f4b71Sopenharmony_ci 546e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Global.I18n 547e41f4b71Sopenharmony_ci 548e41f4b71Sopenharmony_ci| 名称 | 类型 | 必填 | 说明 | 549e41f4b71Sopenharmony_ci| --------------- | --------------- | ---- | --------------------------------------- | 550e41f4b71Sopenharmony_ci| locale | string | 否 | 区域代码,如"zh-Hans-CN"。locale属性默认值为系统Locale。 | 551e41f4b71Sopenharmony_ci| isUseLocalName | boolean | 否 | 表示是否使用本地名称进行排序。若调用方法为getLanguageInfoArray,isUseLocalName属性默认值为true。若调用方法为getRegionInfoArray,isUseLocalName属性默认值为false。 | 552e41f4b71Sopenharmony_ci| isSuggestedFirst | boolean | 否 | 表示是否将推荐语言或国家地区在排序结果中置顶。isSuggestedFirst属性默认值为true。 | 553