未验证 提交 b9076754 编写于 作者: O openharmony_ci 提交者: Gitee

!11664 翻译已完成 10408

Merge pull request !11664 from shawn_he/10408-a
# Internationalization – I18N
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.
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.
> **NOTE**
> - 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.
>
> 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.
> - 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. For details about the basic I18N capabilities, see [Intl](js-apis-intl.md).
## Modules to Import
```
```js
import i18n from '@ohos.i18n';
```
## i18n.getDisplayLanguage
## System<sup>9+</sup>
getDisplayLanguage(language: string, locale: string, sentenceCase?: boolean): string
### getDisplayCountry<sup>9+</sup>
Obtains the localized script for the specified language.
static getDisplayCountry(country: string, locale: string, sentenceCase?: boolean): string
Obtains the localized script for the specified country.
**System capability**: SystemCapability.Global.I18n
......@@ -29,7 +30,7 @@ Obtains the localized script for the specified language.
| Name | Type | Mandatory | Description |
| ------------ | ------- | ---- | ---------------- |
| language | string | Yes | Specified language. |
| country | string | Yes | Specified country. |
| locale | string | Yes | Locale ID. |
| sentenceCase | boolean | No | Whether to use sentence case for the localized script.|
......@@ -37,20 +38,30 @@ Obtains the localized script for the specified language.
| Type | Description |
| ------ | ------------- |
| string | Localized script for the specified language.|
| string | Localized script for the specified country.|
**Error codes**
For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 890001 | Unspported para value. |
**Example**
```js
i18n.getDisplayLanguage("zh", "en-GB", true);
i18n.getDisplayLanguage("zh", "en-GB");
try {
var displayCountry = i18n.System.getDisplayCountry("zh-CN", "en-GB");
} catch(error) {
console.error(`call System.getDisplayCountry failed, error code: ${error.code}, message: ${error.message}.`)
}
```
### getDisplayLanguage<sup>9+</sup>
## i18n.getDisplayCountry
static getDisplayLanguage(language: string, locale: string, sentenceCase?: boolean): string
getDisplayCountry(country: string, locale: string, sentenceCase?: boolean): string
Obtains the localized script for the specified country.
Obtains the localized script for the specified language.
**System capability**: SystemCapability.Global.I18n
......@@ -58,7 +69,7 @@ Obtains the localized script for the specified country.
| Name | Type | Mandatory | Description |
| ------------ | ------- | ---- | ---------------- |
| country | string | Yes | Specified country. |
| language | string | Yes | Specified language. |
| locale | string | Yes | Locale ID. |
| sentenceCase | boolean | No | Whether to use sentence case for the localized script.|
......@@ -66,123 +77,173 @@ Obtains the localized script for the specified country.
| Type | Description |
| ------ | ------------- |
| string | Localized script for the specified country.|
| string | Localized script for the specified language.|
**Error codes**
For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 890001 | Unspported para value. |
**Example**
```js
i18n.getDisplayCountry("zh-CN", "en-GB", true);
i18n.getDisplayCountry("zh-CN", "en-GB");
try {
var displayLanguage = i18n.System.getDisplayLanguage("zh", "en-GB");
} catch(error) {
console.error(`call System.getDisplayLanguage failed, error code: ${error.code}, message: ${error.message}.`)
}
```
### getSystemLanguages<sup>9+</sup>
## i18n.isRTL<sup>7+</sup>
isRTL(locale: string): boolean
static getSystemLanguages(): Array&lt;string&gt;
Checks whether the localized script for the specified language is displayed from right to left.
Obtains the list of system languages.
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Description |
| ------ | ------ | ------- |
| locale | string | Locale ID.|
**Return value**
| Type | Description |
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the localized script is displayed from right to left; returns **false** otherwise.|
| ------------------- | ------------ |
| Array&lt;string&gt; | List of the IDs of system languages.|
**Error codes**
For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 890001 | Unspported para value. |
**Example**
```js
i18n.isRTL("zh-CN");// Since Chinese is not written from right to left, false is returned.
i18n.isRTL("ar-EG");// Since Arabic is written from right to left, true is returned.
try {
var systemLanguages = i18n.System.getSystemLanguages();
} catch(error) {
console.error(`call System.getSystemLanguages failed, error code: ${error.code}, message: ${error.message}.`)
}
```
### getSystemCountries<sup>9+</sup>
## i18n.getSystemLanguage
getSystemLanguage(): string
static getSystemCountries(language: string): Array&lt;string&gt;
Obtains the system language.
Obtains the list of countries and regions supported for the specified language.
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Description |
| -------- | ------ | ----- |
| language | string | Language ID.|
**Return value**
| Type | Description |
| ------ | ------- |
| string | System language ID.|
| ------------------- | ------------ |
| Array&lt;string&gt; | List of the IDs of the countries and regions supported for the specified language.|
**Example**
```js
i18n.getSystemLanguage();
```
**Error codes**
For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
## i18n.setSystemLanguage
| ID| Error Message|
| -------- | ---------------------------------------- |
| 890001 | Unspported para value. |
setSystemLanguage(language: string): boolean
**Example**
```js
try {
var systemCountries = i18n.System.getSystemCountries('zh');
} catch(error) {
console.error(`call System.getSystemCountries failed, error code: ${error.code}, message: ${error.message}.`)
}
```
Sets the system language. Currently, this API does not support real-time updating of the system language.
### isSuggested<sup>9+</sup>
This is a system API.
static isSuggested(language: string, region?: string): boolean
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
Checks whether the system language matches the specified region.
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Description |
| -------- | ------ | ----- |
| language | string | Language ID.|
| Name | Type | Mandatory | Description |
| -------- | ------ | ---- | ------------- |
| language | string | Yes | Valid language ID, for example, **zh**.|
| region | string | No | Valid region ID, for example, **CN**. |
**Return value**
| Type | Description |
| ------- | ------------------------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the system language matches the specified region; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 890001 | Unspported para value. |
**Example**
```js
i18n.setSystemLanguage('zh');
try {
var res = i18n.System.isSuggested('zh', 'CN');
} catch(error) {
console.error(`call System.isSuggested failed, error code: ${error.code}, message: ${error.message}.`)
}
```
### getSystemLanguage<sup>9+</sup>
## i18n.getSystemLanguages<sup>9+</sup>
getSystemLanguages(): Array&lt;string&gt;
static getSystemLanguage(): string
Obtains the list of system languages.
Obtains the system language.
**System capability**: SystemCapability.Global.I18n
**System API**: This is a system API and cannot be called by third-party applications.
**Return value**
| Type | Description |
| ------------------- | ------------ |
| Array&lt;string&gt; | List of the IDs of system languages.|
| ------ | ------- |
| string | System language ID.|
**Error codes**
For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 890001 | Unspported para value. |
**Example**
```js
i18n.getSystemLanguages();
try {
var systemLanguage = i18n.System.getSystemLanguage();
} catch(error) {
console.error(`call System.getSystemLanguage failed, error code: ${error.code}, message: ${error.message}.`)
}
```
### setSystemLanguage<sup>9+</sup>
## i18n.getSystemCountries<sup>9+</sup>
static setSystemLanguage(language: string): void
getSystemCountries(language: string): Array&lt;string&gt;
Sets the system language. Currently, this API does not support real-time updating of the system language.
Obtains the list of countries and regions supported for the specified language.
This is a system API.
**System capability**: SystemCapability.Global.I18n
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
**System API**: This is a system API and cannot be called by third-party applications.
**System capability**: SystemCapability.Global.I18n
**Parameters**
......@@ -190,21 +251,26 @@ Obtains the list of countries and regions supported for the specified language.
| -------- | ------ | ----- |
| language | string | Language ID.|
**Return value**
**Error codes**
| Type | Description |
| ------------------- | ------------ |
| Array&lt;string&gt; | List of the IDs of the countries and regions supported for the specified language.|
For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 890001 | Unspported para value. |
**Example**
```js
i18n.getSystemCountries('zh');
try {
i18n.System.setSystemLanguage('zh');
} catch(error) {
console.error(`call System.setSystemLanguage failed, error code: ${error.code}, message: ${error.message}.`)
}
```
### getSystemRegion<sup>9+</sup>
## i18n.getSystemRegion
getSystemRegion(): string
static getSystemRegion(): string
Obtains the system region.
......@@ -216,15 +282,26 @@ Obtains the system region.
| ------ | ------- |
| string | System region ID.|
**Error codes**
For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 890001 | Unspported para value. |
**Example**
```js
i18n.getSystemRegion();
try {
var systemRegion = i18n.System.getSystemRegion();
} catch(error) {
console.error(`call System.getSystemRegion failed, error code: ${error.code}, message: ${error.message}.`)
}
```
### setSystemRegion<sup>9+</sup>
## i18n.setSystemRegion
setSystemRegion(region: string): boolean
static setSystemRegion(region: string): void
Sets the system region.
......@@ -240,21 +317,26 @@ This is a system API.
| ------ | ------ | ----- |
| region | string | Region ID.|
**Return value**
**Error codes**
| Type | Description |
| ------- | ------------------------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 890001 | Unspported para value. |
**Example**
```js
i18n.setSystemRegion('CN');
try {
i18n.System.setSystemRegion('CN');
} catch(error) {
console.error(`call System.setSystemRegion failed, error code: ${error.code}, message: ${error.message}.`)
}
```
### getSystemLocale<sup>9+</sup>
## i18n.getSystemLocale
getSystemLocale(): string
static getSystemLocale(): string
Obtains the system locale.
......@@ -266,15 +348,26 @@ Obtains the system locale.
| ------ | ------- |
| string | System locale ID.|
**Error codes**
For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 890001 | Unspported para value. |
**Example**
```js
i18n.getSystemLocale();
try {
var systemLocale = i18n.System.getSystemLocale();
} catch(error) {
console.error(`call System.getSystemLocale failed, error code: ${error.code}, message: ${error.message}.`)
}
```
### setSystemLocale<sup>9+</sup>
## i18n.setSystemLocale
setSystemLocale(locale: string): boolean
static setSystemLocale(locale: string): void
Sets the system locale.
......@@ -290,182 +383,488 @@ This is a system API.
| ------ | ------ | --------------- |
| locale | string | System locale ID, for example, **zh-CN**.|
**Return value**
**Error codes**
| Type | Description |
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the operation is successful; returns **false** otherwise.|
For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 890001 | Unspported para value. |
**Example**
```js
i18n.setSystemLocale('zh-CN');
try {
i18n.System.setSystemLocale('zh-CN');
} catch(error) {
console.error(`call System.setSystemLocale failed, error code: ${error.code}, message: ${error.message}.`)
}
```
### is24HourClock<sup>9+</sup>
## i18n.isSuggested<sup>9+</sup>
isSuggested(language: string, region?: string): boolean
static is24HourClock(): boolean
Checks whether the system language matches the specified region.
Checks whether the 24-hour clock is used.
**System capability**: SystemCapability.Global.I18n
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------ | ---- | ------------- |
| language | string | Yes | Valid language ID, for example, **zh**.|
| region | string | No | Valid region ID, for example, **CN**. |
**Return value**
| Type | Description |
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the system language matches the specified region; returns **false** otherwise.|
| boolean | Returns **true** if the 24-hour clock is used; returns **false** otherwise.|
**Error codes**
For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 890001 | Unspported para value. |
**Example**
```js
i18n.isSuggested('zh', 'CN');
try {
var is24HourClock = i18n.System.is24HourClock();
} catch(error) {
console.error(`call System.is24HourClock failed, error code: ${error.code}, message: ${error.message}.`)
}
```
### set24HourClock<sup>9+</sup>
## i18n.getCalendar<sup>8+</sup>
static set24HourClock(option: boolean): void
getCalendar(locale: string, type? : string): Calendar
Sets the 24-hour clock.
Obtains a **Calendar** object.
This is a system API.
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ---------------------------------------- |
| locale | string | Yes | Valid locale value, for example, **zh-Hans-CN**. |
| type | string | No | Valid calendar type. Currently, the valid types are as follows: **buddhist**, **chinese**, **coptic**, **ethiopic**, **hebrew**, **gregory**, **indian**, **islamic\_civil**, **islamic\_tbla**, **islamic\_umalqura**, **japanese**, and **persian**. If this parameter is left unspecified, the default calendar type of the specified locale is used.|
| ------ | ------- | ---- | ---------------------------------------- |
| 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.|
**Return value**
**Error codes**
| Type | Description |
| ---------------------- | ----- |
| [Calendar](#calendar8) | **Calendar** object.|
For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 890001 | Unspported para value. |
**Example**
```js
i18n.getCalendar("zh-Hans", "gregory");
// Set the system time to the 24-hour clock.
try {
i18n.System.set24HourClock(true);
} catch(error) {
console.error(`call System.set24HourClock failed, error code: ${error.code}, message: ${error.message}.`)
}
```
### addPreferredLanguage<sup>9+</sup>
## Calendar<sup>8+</sup>
static addPreferredLanguage(language: string, index?: number): void
### setTime<sup>8+</sup>
Adds a preferred language to the specified position on the preferred language list.
setTime(date: Date): void
This is a system API.
Sets the date for this **Calendar** object.
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ---- | ---- | ----------------- |
| date | Date | Yes | Date to be set for the **Calendar** object.|
| -------- | ------ | ---- | ---------- |
| language | string | Yes | Preferred language to add. |
| index | number | No | Position to which the preferred language is added.|
**Error codes**
For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 890001 | Unspported para value. |
**Example**
```js
var calendar = i18n.getCalendar("en-US", "gregory");
var date = new Date(2021, 10, 7, 8, 0, 0, 0);
calendar.setTime(date);
// Add zh-CN to the preferred language list.
var language = 'zh-CN';
var index = 0;
try {
i18n.System.addPreferredLanguage(language, index);
} catch(error) {
console.error(`call System.addPreferredLanguage failed, error code: ${error.code}, message: ${error.message}.`)
}
```
### removePreferredLanguage<sup>9+</sup>
### setTime<sup>8+</sup>
static removePreferredLanguage(index: number): void
setTime(time: number): void
Deletes a preferred language from the specified position on the preferred language list.
Sets the date and time for this **Calendar** object. The value is represented by the number of milliseconds that have elapsed since the Unix epoch (00:00:00 UTC on January 1, 1970).
This is a system API.
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- |
| time | number | Yes | Number of milliseconds that have elapsed since the Unix epoch.|
| ----- | ------ | ---- | --------------------- |
| index | number | Yes | Position of the preferred language to delete.|
**Error codes**
For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 890001 | Unspported para value. |
**Example**
```js
var calendar = i18n.getCalendar("en-US", "gregory");
calendar.setTime(10540800000);
// Delete the first preferred language from the preferred language list.
var index = 0;
try {
i18n.System.removePreferredLanguage(index);
} catch(error) {
console.error(`call System.removePreferredLanguage failed, error code: ${error.code}, message: ${error.message}.`)
}
```
### getPreferredLanguageList<sup>9+</sup>
### set<sup>8+</sup>
set(year: number, month: number, date:number, hour?: number, minute?: number, second?: number): void
static getPreferredLanguageList(): Array&lt;string&gt;
Sets the year, month, day, hour, minute, and second for this **Calendar** object.
Obtains the list of preferred languages.
**System capability**: SystemCapability.Global.I18n
**Parameters**
**Return value**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------ |
| year | number | Yes | Year to set. |
| month | number | Yes | Month to set. |
| date | number | Yes | Day to set. |
| hour | number | No | Hour to set.|
| minute | number | No | Minute to set.|
| second | number | No | Second to set. |
| Type | Description |
| ------------------- | --------- |
| Array&lt;string&gt; | List of preferred languages.|
**Error codes**
For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 890001 | Unspported para value. |
**Example**
```js
var calendar = i18n.getCalendar("zh-Hans");
calendar.set(2021, 10, 1, 8, 0, 0); // set time to 2021.10.1 08:00:00
try {
var preferredLanguageList = i18n.System.getPreferredLanguageList();
} catch(error) {
console.error(`call System.getPreferredLanguageList failed, error code: ${error.code}, message: ${error.message}.`)
}
```
### getFirstPreferredLanguage<sup>9+</sup>
### setTimeZone<sup>8+</sup>
setTimeZone(timezone: string): void
static getFirstPreferredLanguage(): string
Sets the time zone of this **Calendar** object.
Obtains the first language in the preferred language list.
**System capability**: SystemCapability.Global.I18n
**Parameters**
**Return value**
| Name | Type | Mandatory | Description |
| -------- | ------ | ---- | ------------------------- |
| timezone | string | Yes | Time zone, for example, **Asia/Shanghai**.|
| Type | Description |
| ------ | -------------- |
| string | First language in the preferred language list.|
**Error codes**
For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 890001 | Unspported para value. |
**Example**
```js
var calendar = i18n.getCalendar("zh-Hans");
calendar.setTimeZone("Asia/Shanghai");
try {
var firstPreferredLanguage = i18n.System.getFirstPreferredLanguage();
} catch(error) {
console.error(`call System.getFirstPreferredLanguage failed, error code: ${error.code}, message: ${error.message}.`)
}
```
### getAppPreferredLanguage<sup>9+</sup>
### getTimeZone<sup>8+</sup>
getTimeZone(): string
static getAppPreferredLanguage(): string
Obtains the time zone of this **Calendar** object.
Obtains the preferred language of an application.
**System capability**: SystemCapability.Global.I18n
**Return value**
| Type | Description |
| ------ | ---------- |
| string | Time zone of the **Calendar** object.|
| ------ | -------- |
| string | Preferred language of the application.|
**Example**
**Error codes**
For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 890001 | Unspported para value. |
**Example**
```js
try {
var appPreferredLanguage = i18n.System.getAppPreferredLanguage();
} catch(error) {
console.error(`call System.getAppPreferredLanguage failed, error code: ${error.code}, message: ${error.message}.`)
}
```
### setUsingLocalDigit<sup>9+</sup>
static setUsingLocalDigit(flag: boolean): void
Sets whether to turn on the local digit switch.
This is a system API.
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------- | ---- | ------------------------------- |
| 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.|
**Error codes**
For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 890001 | Unspported para value. |
**Example**
```ts
try {
i18n.System.setUsingLocalDigit(true);
} catch(error) {
console.error(`call System.setUsingLocalDigit failed, error code: ${error.code}, message: ${error.message}.`)
}
```
### getUsingLocalDigit<sup>9+</sup>
static getUsingLocalDigit(): boolean
Checks whether the local digit switch is turned on.
**System capability**: SystemCapability.Global.I18n
**Return value**
| Type | Description |
| ------- | ---------------------------------------- |
| boolean | Result indicating whether the local digit switch is turned on. The value **true** indicates that the local digit switch is turned on, and the value **false** indicates the opposite.|
**Error codes**
For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
| ID| Error Message|
| -------- | ---------------------------------------- |
| 890001 | Unspported para value. |
**Example**
```ts
try {
var status = i18n.System.getUsingLocalDigit();
} catch(error) {
console.error(`call System.getUsingLocalDigit failed, error code: ${error.code}, message: ${error.message}.`)
}
```
## i18n.isRTL<sup>7+</sup>
isRTL(locale: string): boolean
Checks whether the localized script for the specified language is displayed from right to left.
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Description |
| ------ | ------ | ------- |
| locale | string | Locale ID.|
**Return value**
| Type | Description |
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the localized script is displayed from right to left; returns **false** otherwise.|
**Example**
```js
i18n.isRTL("zh-CN");// Since Chinese is not written from right to left, false is returned.
i18n.isRTL("ar-EG");// Since Arabic is written from right to left, true is returned.
```
## i18n.getCalendar<sup>8+</sup>
getCalendar(locale: string, type? : string): Calendar
Obtains a **Calendar** object.
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ---------------------------------------- |
| locale | string | Yes | Valid locale value, for example, **zh-Hans-CN**. |
| type | string | No | Valid calendar type. Currently, the valid types are as follows: **buddhist**, **chinese**, **coptic**, **ethiopic**, **hebrew**, **gregory**, **indian**, **islamic\_civil**, **islamic\_tbla**, **islamic\_umalqura**, **japanese**, and **persian**. If this parameter is left unspecified, the default calendar type of the specified locale is used.|
**Return value**
| Type | Description |
| ---------------------- | ----- |
| [Calendar](#calendar8) | **Calendar** object.|
**Example**
```js
i18n.getCalendar("zh-Hans", "gregory");
```
## Calendar<sup>8+</sup>
### setTime<sup>8+</sup>
setTime(date: Date): void
Sets the date for this **Calendar** object.
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ---- | ---- | ----------------- |
| date | Date | Yes | Date to be set for the **Calendar** object.|
**Example**
```js
var calendar = i18n.getCalendar("en-US", "gregory");
var date = new Date(2021, 10, 7, 8, 0, 0, 0);
calendar.setTime(date);
```
### setTime<sup>8+</sup>
setTime(time: number): void
Sets the date and time for this **Calendar** object. The value is represented by the number of milliseconds that have elapsed since the Unix epoch (00:00:00 UTC on January 1, 1970).
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ---------------------------------------- |
| time | number | Yes | Number of milliseconds that have elapsed since the Unix epoch.|
**Example**
```js
var calendar = i18n.getCalendar("en-US", "gregory");
calendar.setTime(10540800000);
```
### set<sup>8+</sup>
set(year: number, month: number, date:number, hour?: number, minute?: number, second?: number): void
Sets the year, month, day, hour, minute, and second for this **Calendar** object.
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------ |
| year | number | Yes | Year to set. |
| month | number | Yes | Month to set. |
| date | number | Yes | Day to set. |
| hour | number | No | Hour to set.|
| minute | number | No | Minute to set.|
| second | number | No | Second to set. |
**Example**
```js
var calendar = i18n.getCalendar("zh-Hans");
calendar.set(2021, 10, 1, 8, 0, 0); // set time to 2021.10.1 08:00:00
```
### setTimeZone<sup>8+</sup>
setTimeZone(timezone: string): void
Sets the time zone of this **Calendar** object.
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------ | ---- | ------------------------- |
| timezone | string | Yes | Time zone, for example, **Asia/Shanghai**.|
**Example**
```js
var calendar = i18n.getCalendar("zh-Hans");
calendar.setTimeZone("Asia/Shanghai");
```
### getTimeZone<sup>8+</sup>
getTimeZone(): string
Obtains the time zone of this **Calendar** object.
**System capability**: SystemCapability.Global.I18n
**Return value**
| Type | Description |
| ------ | ---------- |
| string | Time zone of the **Calendar** object.|
**Example**
```js
var calendar = i18n.getCalendar("zh-Hans");
calendar.setTimeZone("Asia/Shanghai");
......@@ -589,7 +988,7 @@ Obtains the value of the specified field in the **Calendar** object.
getDisplayName(locale: string): string
Obtains the name of the **Calendar** object displayed for the specified locale.
Obtains the **Calendar** object name displayed for the specified locale.
**System capability**: SystemCapability.Global.I18n
......@@ -603,7 +1002,7 @@ Obtains the name of the **Calendar** object displayed for the specified locale.
| Type | Description |
| ------ | ------------------- |
| string | Name of the **Calendar** object displayed for the specified locale.|
| string | **Calendar** object name displayed for the specified locale.|
**Example**
```js
......@@ -653,7 +1052,8 @@ Creates a **PhoneNumberFormat** object.
**System capability**: SystemCapability.Global.I18n
Parameters
**Parameters**
| Name | Type | Mandatory | Description |
| ------- | ---------------------------------------- | ---- | ---------------- |
| country | string | Yes | Country or region to which the phone number to be formatted belongs.|
......@@ -715,9 +1115,10 @@ Formats a phone number.
**Example**
```js
var phonenumberfmt = new i18n.PhoneNumberFormat("CN");
phonenumberfmt.isValidNumber("15812312312");
phonenumberfmt.format("15812312312");
```
### getLocationName<sup>9+</sup>
getLocationName(number: string, locale: string): string
......@@ -729,20 +1130,20 @@ Obtains the home location of a phone number.
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ---------- |
| ------ | ------ | ---- | ---- |
| number | string | Yes | Phone number.|
| locale | string | Yes | Locale ID.|
**Return value**
| Type | Description |
| ------ | ---------- |
| ------ | -------- |
| string | Home location of the phone number.|
**Example**
```js
var phonenumberfmt = new i18n.PhoneNumberFormat("CN");
phonenumberfmt.isValidNumber("15812312312");
phonenumberfmt.getLocationName("15812312345", "zh-CN");
```
......@@ -769,39 +1170,6 @@ Defines the measurement unit information.
| measureSystem | string | Yes | Yes | Measurement system. The value can be **SI**,&nbsp;**US**, or&nbsp;**UK**.|
## Util<sup>(deprecated)</sup>
### unitConvert<sup>(deprecated)</sup>
static unitConvert(fromUnit: UnitInfo, toUnit: UnitInfo, value: number, locale: string, style?: string): string
Converts one measurement unit into another and formats the unit based on the specified locale and style.
> **NOTE**
> This API is deprecated since API version 9. You are advised to use [unitConvert](#unitconvert9) instead.
>
> This API is supported since API version 8.
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------- | ---- | ---------------------------------------- |
| fromUnit | [UnitInfo](#unitinfo8) | Yes | Measurement unit to be converted. |
| toUnit | [UnitInfo](#unitinfo8) | Yes | Measurement unit to be converted to. |
| value | number | Yes | Value of the measurement unit to be converted. |
| locale | string | Yes | Locale used for formatting, for example, **zh-Hans-CN**. |
| style | string | No | Style used for formatting. The value can be **long**, **short**, or **narrow**.|
**Return value**
| Type | Description |
| ------ | ----------------------- |
| string | Character string obtained after formatting based on the measurement unit specified by **toUnit**.|
## getInstance<sup>8+</sup>
getInstance(locale?:string): IndexUtil
......@@ -896,265 +1264,19 @@ Obtains the index of a text object.
**Example**
```js
var indexUtil= i18n.getInstance("zh-CN");
indexUtil.getIndex("hi"); // Return h.
indexUtil.getIndex("hi"); // Return hi.
```
## Character<sup>(deprecated)</sup>
## i18n.getLineInstance<sup>8+</sup>
getLineInstance(locale: string): BreakIterator
### isDigit<sup>(deprecated)</sup>
Obtains a [BreakIterator](#breakiterator8) object for text segmentation.
static isDigit(char: string): boolean
**System capability**: SystemCapability.Global.I18n
Checks whether the input character string is composed of digits.
> **NOTE**
> This API is deprecated since API version 9. You are advised to use [isDigit](#isdigit9) instead.
>
> This API is supported since API version 8.
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ----- |
| char | string | Yes | Input character.|
**Return value**
| Type | Description |
| ------- | ------------------------------------ |
| boolean | Returns **true** if the input character is a digit; returns **false** otherwise.|
### isSpaceChar<sup>(deprecated)</sup>
static isSpaceChar(char: string): boolean
Checks whether the input character is a space.
> **NOTE**
> This API is deprecated since API version 9. You are advised to use [isSpaceChar](#isspacechar9) instead.
>
> This API is supported since API version 8.
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ----- |
| char | string | Yes | Input character.|
**Return value**
| Type | Description |
| ------- | -------------------------------------- |
| boolean | Returns **true** if the input character is a space; returns **false** otherwise.|
### isWhitespace<sup>(deprecated)</sup>
static isWhitespace(char: string): boolean
Checks whether the input character is a white space.
> **NOTE**
> This API is deprecated since API version 9. You are advised to use [isWhitespace](#iswhitespace9) instead.
>
> This API is supported since API version 8.
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ----- |
| char | string | Yes | Input character.|
**Return value**
| Type | Description |
| ------- | -------------------------------------- |
| boolean | Returns **true** if the input character is a white space; returns **false** otherwise.|
### isRTL<sup>(deprecated)</sup>
static isRTL(char: string): boolean
Checks whether the input character is of the right to left (RTL) language.
> **NOTE**
> This API is deprecated since API version 9. You are advised to use [isRTL](#isrtl9) instead.
>
> This API is supported since API version 8.
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ----- |
| char | string | Yes | Input character.|
**Return value**
| Type | Description |
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the input character is of the RTL language; returns **false** otherwise.|
### isIdeograph<sup>(deprecated)</sup>
static isIdeograph(char: string): boolean
Checks whether the input character is an ideographic character.
> **NOTE**
> This API is deprecated since API version 9. You are advised to use [isIdeograph](#isideograph9) instead.
>
> This API is supported since API version 8.
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ----- |
| char | string | Yes | Input character.|
**Return value**
| Type | Description |
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the input character is an ideographic character; returns **false** otherwise.|
### isLetter<sup>(deprecated)</sup>
static isLetter(char: string): boolean
Checks whether the input character is a letter.
> **NOTE**
> This API is deprecated since API version 9. You are advised to use [isLetter](#isletter9) instead.
>
> This API is supported since API version 8.
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ----- |
| char | string | Yes | Input character.|
**Return value**
| Type | Description |
| ------- | ------------------------------------ |
| boolean | Returns **true** if the input character is a letter; returns **false** otherwise.|
### isLowerCase<sup>(deprecated)</sup>
static isLowerCase(char: string): boolean
Checks whether the input character is a lowercase letter.
> **NOTE**
> This API is deprecated since API version 9. You are advised to use [isLowerCase](#islowercase9) instead.
>
> This API is supported since API version 8.
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ----- |
| char | string | Yes | Input character.|
**Return value**
| Type | Description |
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the input character is a lowercase letter; returns **false** otherwise.|
### isUpperCase<sup>(deprecated)</sup>
static isUpperCase(char: string): boolean
Checks whether the input character is an uppercase letter.
> **NOTE**
> This API is deprecated since API version 9. You are advised to use [isUpperCase](#isuppercase9) instead.
>
> This API is supported since API version 8.
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ----- |
| char | string | Yes | Input character.|
**Return value**
| Type | Description |
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the input character is an uppercase letter; returns **false** otherwise.|
### getType<sup>(deprecated)</sup>
static getType(char: string): string
Obtains the type of the input character string.
> **NOTE**
> This API is deprecated since API version 9. You are advised to use [getType](#gettype9) instead.
>
> This API is supported since API version 8.
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ----- |
| char | string | Yes | Input character.|
**Return value**
| Type | Description |
| ------ | ----------- |
| string | Type of the input character.|
## i18n.getLineInstance<sup>8+</sup>
getLineInstance(locale: string): BreakIterator
Obtains a [BreakIterator](#breakiterator8) object for text segmentation.
**System capability**: SystemCapability.Global.I18n
**Parameters**
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ---------------------------------------- |
......@@ -1274,7 +1396,7 @@ Puts the [BreakIterator](#breakiterator8) object to the last text boundary, whic
| Type | Description |
| ------ | ------------------ |
| number | Offset of the last text boundary of the processed text.|
| number | Offset to the last text boundary of the processed text.|
**Example**
```js
......@@ -1397,395 +1519,779 @@ Checks whether the position specified by the offset is a text boundary. If **tru
```
## i18n.is24HourClock<sup>7+</sup>
## i18n.getTimeZone<sup>7+</sup>
is24HourClock(): boolean
getTimeZone(zoneID?: string): TimeZone
Checks whether the 24-hour clock is used.
Obtains the **TimeZone** object corresponding to the specified time zone ID.
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ----- |
| zondID | string | No | Time zone ID.|
**Return value**
| Type | Description |
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the 24-hour clock is used; returns **false** otherwise.|
| -------- | ------------ |
| TimeZone | **TimeZone** object corresponding to the time zone ID.|
**Example**
```js
var is24HourClock = i18n.is24HourClock();
var timezone = i18n.getTimeZone();
```
## i18n.set24HourClock<sup>7+</sup>
## TimeZone
set24HourClock(option: boolean): boolean
Sets the 24-hour clock.
### getID
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
getID(): string
Obtains the ID of the specified **TimeZone** object.
**System capability**: SystemCapability.Global.I18n
**Parameters**
**Return value**
| Type | Description |
| ------ | ------------ |
| string | Time zone ID corresponding to the **TimeZone** object.|
**Example**
```js
var timezone = i18n.getTimeZone();
timezone.getID();
```
### getDisplayName
getDisplayName(locale?: string, isDST?: boolean): string
Obtains the representation of a **TimeZone** object in the specified locale.
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------- | ---- | -------------------- |
| locale | string | No | Locale ID. |
| isDST | boolean | No | Whether to consider DST when obtaining the representation of the **TimeZone** object.|
**Return value**
| Type | Description |
| ------ | ------------- |
| string | Representation of the **TimeZone** object in the specified locale.|
**Example**
```js
var timezone = i18n.getTimeZone();
timezone.getDisplayName("zh-CN", false);
```
### getRawOffset
getRawOffset(): number
Obtains the offset between the time zone represented by a **TimeZone** object and the UTC time zone.
**System capability**: SystemCapability.Global.I18n
**Return value**
| Type | Description |
| ------ | ------------------- |
| number | Offset between the time zone represented by the **TimeZone** object and the UTC time zone.|
**Example**
```js
var timezone = i18n.getTimeZone();
timezone.getRawOffset();
```
### getOffset
getOffset(date?: number): number
Obtains the offset between the time zone represented by a **TimeZone** object and the UTC time zone at a certain time point.
**System capability**: SystemCapability.Global.I18n
**Return value**
| Type | Description |
| ------ | ----------------------- |
| number | Offset between the time zone represented by the **TimeZone** object and the UTC time zone at a certain time point.|
**Example**
```js
var timezone = i18n.getTimeZone();
timezone.getOffset(1234567890);
```
### getAvailableIDs<sup>9+</sup>
static getAvailableIDs(): Array&lt;string&gt;
Obtains the list of time zone IDs supported by the system.
**System capability**: SystemCapability.Global.I18n
**Return value**
| Type | Description |
| ------------------- | ----------- |
| Array&lt;string&gt; | List of time zone IDs supported by the system.|
**Example**
```ts
var ids = i18n.TimeZone.getAvailableIDs();
```
### getAvailableZoneCityIDs<sup>9+</sup>
static getAvailableZoneCityIDs(): Array&lt;string&gt;
Obtains the list of time zone city IDs supported by the system.
**System capability**: SystemCapability.Global.I18n
**Return value**
| Type | Description |
| ------------------- | ------------- |
| Array&lt;string&gt; | List of time zone city IDs supported by the system.|
**Example**
```ts
var cityIDs = i18n.TimeZone.getAvailableZoneCityIDs();
```
### getCityDisplayName<sup>9+</sup>
static getCityDisplayName(cityID: string, locale: string): string
Obtains the localized display of a time zone city in the specified locale.
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------ |
| cityID | string | Yes | Time zone city ID.|
| locale | string | Yes | Locale ID. |
**Return value**
| Type | Description |
| ------ | ------------------ |
| string | Localized display of the time zone city in the specified locale.|
**Example**
```ts
var displayName = i18n.TimeZone.getCityDisplayName("Shanghai", "zh-CN");
```
### getTimezoneFromCity<sup>9+</sup>
static getTimezoneFromCity(cityID: string): TimeZone
Obtains the **TimeZone** object corresponding to the specified time zone city ID.
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------ |
| cityID | string | Yes | Time zone city ID.|
**Return value**
| Type | Description |
| -------- | ----------- |
| TimeZone | **TimeZone** object corresponding to the specified time zone city ID.|
**Example**
```ts
var timezone = i18n.TimeZone.getTimezoneFromCity("Shanghai");
```
## Transliterator<sup>9+</sup>
### getAvailableIDs<sup>9+</sup>
static getAvailableIDs(): string[]
Obtains a list of IDs supported by the **Transliterator** object.
**System capability**: SystemCapability.Global.I18n
**Return value**
| Type | Description |
| -------- | ---------- |
| string[] | List of IDs supported by the **Transliterator** object.|
**Example**
```ts
i18n.Transliterator.getAvailableIDs();
```
### getInstance<sup>9+</sup>
static getInstance(id: string): Transliterator
Creates a **Transliterator** object.
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | -------- |
| id | string | Yes | ID supported by the **Transliterator** object.|
**Return value**
| Type | Description |
| ---------------------------------- | ----- |
| [Transliterator](#transliterator9) | **Transliterator** object.|
**Example**
```ts
var transliterator = i18n.Transliterator.getInstance("Any-Latn");
```
### transform<sup>9+</sup>
transform(text: string): string
Converts the input string from the source format to the target format.
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ------ |
| text | string | Yes | Input string.|
**Return value**
| Type | Description |
| ------ | -------- |
| string | Target string.|
**Example**
```ts
var transliterator = i18n.Transliterator.getInstance("Any-Latn");
transliterator.transform ("China");
```
## Unicode<sup>9+</sup>
### isDigit<sup>9+</sup>
static isDigit(char: string): boolean
Checks whether the input character string is composed of digits.
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ----- |
| char | string | Yes | Input character.|
**Return value**
| Type | Description |
| ------- | ------------------------------------ |
| boolean | Returns **true** if the input character is a digit; returns **false** otherwise.|
**Example**
```js
var isdigit = i18n.Unicode.isDigit("1"); // Return true.
```
### isSpaceChar<sup>9+</sup>
static isSpaceChar(char: string): boolean
Checks whether the input character is a space.
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ----- |
| char | string | Yes | Input character.|
**Return value**
| Type | Description |
| ------- | -------------------------------------- |
| boolean | Returns **true** if the input character is a space; returns **false** otherwise.|
**Example**
```js
var isspacechar = i18n.Unicode.isSpaceChar("a"); // Return false.
```
### isWhitespace<sup>9+</sup>
static isWhitespace(char: string): boolean
Checks whether the input character is a white space.
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------- | ---- | ---------------------------------------- |
| 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.|
| ---- | ------ | ---- | ----- |
| char | string | Yes | Input character.|
**Return value**
| Type | Description |
| ------- | ----------------------------- |
| boolean | Returns **true** if the 24-hour clock is enabled; returns **false** otherwise.|
| ------- | -------------------------------------- |
| boolean | Returns **true** if the input character is a white space; returns **false** otherwise.|
**Example**
```js
// Set the system time to the 24-hour clock.
var success = i18n.set24HourClock(true);
var iswhitespace = i18n.Unicode.isWhitespace("a"); // Return false.
```
## i18n.addPreferredLanguage<sup>8+</sup>
addPreferredLanguage(language: string, index?: number): boolean
### isRTL<sup>9+</sup>
Adds a preferred language to the specified position on the preferred language list.
static isRTL(char: string): boolean
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
Checks whether the input character is of the right to left (RTL) language.
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ------ | ---- | ---------- |
| language | string | Yes | Preferred language to add. |
| index | number | No | Position to which the preferred language is added.|
| ---- | ------ | ---- | ----- |
| char | string | Yes | Input character.|
**Return value**
| Type | Description |
| ------- | ----------------------------- |
| boolean | Returns **true** if the preferred language is successfully added; returns **false** otherwise.|
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the input character is of the RTL language; returns **false** otherwise.|
**Example**
```js
// Add zh-CN to the preferred language list.
var language = 'zh-CN';
var index = 0;
var success = i18n.addPreferredLanguage(language, index);
var isrtl = i18n.Unicode.isRTL("a"); // Return false.
```
## i18n.removePreferredLanguage<sup>8+</sup>
removePreferredLanguage(index: number): boolean
### isIdeograph<sup>9+</sup>
Deletes a preferred language from the specified position on the preferred language list.
static isIdeograph(char: string): boolean
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
Checks whether the input character is an ideographic character.
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| ----- | ------ | ---- | --------------------- |
| index | number | Yes | Position of the preferred language to delete.|
| ---- | ------ | ---- | ----- |
| char | string | Yes | Input character.|
**Return value**
| Type | Description |
| ------- | ----------------------------- |
| boolean | Returns **true** if the preferred language is deleted; returns **false** otherwise.|
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the input character is an ideographic character; returns **false** otherwise.|
**Example**
```js
// Delete the first preferred language from the preferred language list.
var index = 0;
var success = i18n.removePreferredLanguage(index);
var isideograph = i18n.Unicode.isIdeograph("a"); // Return false.
```
## i18n.getPreferredLanguageList<sup>8+</sup>
### isLetter<sup>9+</sup>
getPreferredLanguageList(): Array&lt;string&gt;
static isLetter(char: string): boolean
Obtains the list of preferred languages.
Checks whether the input character is a letter.
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ----- |
| char | string | Yes | Input character.|
**Return value**
| Type | Description |
| ------------------- | --------- |
| Array&lt;string&gt; | List of preferred languages.|
| ------- | ------------------------------------ |
| boolean | Returns **true** if the input character is a letter; returns **false** otherwise.|
**Example**
```js
var preferredLanguageList = i18n.getPreferredLanguageList();
var isletter = i18n.Unicode.isLetter("a"); // Return true.
```
## i18n.getFirstPreferredLanguage<sup>8+</sup>
### isLowerCase<sup>9+</sup>
getFirstPreferredLanguage(): string
static isLowerCase(char: string): boolean
Obtains the first language in the preferred language list.
Checks whether the input character is a lowercase letter.
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ----- |
| char | string | Yes | Input character.|
**Return value**
| Type | Description |
| ------ | -------------- |
| string | First language in the preferred language list.|
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the input character is a lowercase letter; returns **false** otherwise.|
**Example**
```js
var firstPreferredLanguage = i18n.getFirstPreferredLanguage();
var islowercase = i18n.Unicode.isLowerCase("a"); // Return true.
```
## i18n.getAppPreferredLanguage<sup>9+</sup>
### isUpperCase<sup>9+</sup>
getAppPreferredLanguage(): string
static isUpperCase(char: string): boolean
Obtains the preferred language of an application.
Checks whether the input character is an uppercase letter.
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| ---- | ------ | ---- | ----- |
| char | string | Yes | Input character.|
**Return value**
| Type | Description |
| ------ | -------------- |
| string | Preferred language of the application.|
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the input character is an uppercase letter; returns **false** otherwise.|
**Example**
```js
var appPreferredLanguage = i18n.getAppPreferredLanguage();
var isuppercase = i18n.Unicode.isUpperCase("a"); // Return false.
```
## i18n.getTimeZone<sup>7+</sup>
### getType<sup>9+</sup>
getTimeZone(zoneID?: string): TimeZone
static getType(char: string): string
Obtains the **TimeZone** object corresponding to the specified time zone ID.
Obtains the type of the input character string.
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ----- |
| zondID | string | No | Time zone ID.|
| ---- | ------ | ---- | ----- |
| char | string | Yes | Input character.|
**Return value**
| Type | Description |
| -------- | ------------ |
| TimeZone | **TimeZone** object corresponding to the time zone ID.|
| ------ | ----------- |
| string | Type of the input character.|
**Example**
```js
var timezone = i18n.getTimeZone();
var type = i18n.Unicode.getType("a");
```
## TimeZone
## I18NUtil<sup>9+</sup>
### getID
### unitConvert<sup>9+</sup>
getID(): string
static unitConvert(fromUnit: UnitInfo, toUnit: UnitInfo, value: number, locale: string, style?: string): string
Obtains the ID of the specified **TimeZone** object.
Converts one measurement unit into another and formats the unit based on the specified locale and style.
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------- | ---- | ---------------------------------------- |
| fromUnit | [UnitInfo](#unitinfo8) | Yes | Measurement unit to be converted. |
| toUnit | [UnitInfo](#unitinfo8) | Yes | Measurement unit to be converted to. |
| value | number | Yes | Value of the measurement unit to be converted. |
| locale | string | Yes | Locale used for formatting, for example, **zh-Hans-CN**. |
| style | string | No | Style used for formatting. The value can be **long**, **short**, or **narrow**.|
**Return value**
| Type | Description |
| ------ | ------------ |
| string | Time zone ID corresponding to the **TimeZone** object.|
| ------ | ----------------------- |
| string | Character string obtained after formatting based on the measurement unit specified by **toUnit**.|
**Example**
```js
var timezone = i18n.getTimeZone();
timezone.getID();
i18n.I18NUtil.unitConvert({unit: "cup", measureSystem: "US"}, {unit: "liter", measureSystem: "SI"}, 1000, "en-US", "long");
```
### getDisplayName
### getDateOrder<sup>9+</sup>
getDisplayName(locale?: string, isDST?: boolean): string
static getDateOrder(locale: string): string
Obtains the representation of a **TimeZone** object in the specified locale.
Obtains the sequence of the year, month, and day in the specified locale.
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------- | ---- | -------------------- |
| locale | string | No | System locale ID. |
| isDST | boolean | No | Whether to consider DST when obtaining the representation of the **TimeZone** object.|
| ------ | ------ | ---- | ------------------------- |
| locale | string | Yes | Locale used for formatting, for example, **zh-Hans-CN**.|
**Return value**
| Type | Description |
| ------ | ------------- |
| string | Representation of the **TimeZone** object in the specified locale.|
| ------ | ------------------- |
| string | Sequence of the year, month, and day.|
**Example**
```js
var timezone = i18n.getTimeZone();
timezone.getDisplayName("zh-CN", false);
i18n.I18NUtil.getDateOrder("zh-CN");
```
### getRawOffset
## i18n.getDisplayCountry<sup>(deprecated)</sup>
getRawOffset(): number
getDisplayCountry(country: string, locale: string, sentenceCase?: boolean): string
Obtains the offset between the time zone represented by a **TimeZone** object and the UTC time zone.
Obtains the localized script for the specified country.
This API is deprecated since API version 9. You are advised to use [System.getDisplayCountry](#getdisplaycountry9) instead.
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| ------------ | ------- | ---- | ---------------- |
| country | string | Yes | Specified country. |
| locale | string | Yes | Locale ID. |
| sentenceCase | boolean | No | Whether to use sentence case for the localized script.|
**Return value**
| Type | Description |
| ------ | ------------------- |
| number | Offset between the time zone represented by the **TimeZone** object and the UTC time zone.|
| ------ | ------------- |
| string | Localized script for the specified country.|
**Example**
```js
var timezone = i18n.getTimeZone();
timezone.getRawOffset();
i18n.getDisplayCountry("zh-CN", "en-GB", true);
i18n.getDisplayCountry("zh-CN", "en-GB");
```
### getOffset
## i18n.getDisplayLanguage<sup>(deprecated)</sup>
getOffset(date?: number): number
getDisplayLanguage(language: string, locale: string, sentenceCase?: boolean): string
Obtains the offset between the time zone represented by a **TimeZone** object and the UTC time zone at a certain time point.
Obtains the localized script for the specified language.
This API is deprecated since API version 9. You are advised to use [System.getDisplayLanguage](#getdisplaylanguage9) instead.
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| ------------ | ------- | ---- | ---------------- |
| language | string | Yes | Specified language. |
| locale | string | Yes | Locale ID. |
| sentenceCase | boolean | No | Whether to use sentence case for the localized script.|
**Return value**
| Type | Description |
| ------ | ----------------------- |
| number | Offset between the time zone represented by the **TimeZone** object and the UTC time zone at a certain time point.|
| ------ | ------------- |
| string | Localized script for the specified language.|
**Example**
```js
var timezone = i18n.getTimeZone();
timezone.getOffset(1234567890);
i18n.getDisplayLanguage("zh", "en-GB", true);
i18n.getDisplayLanguage("zh", "en-GB");
```
### getAvailableIDs<sup>9+</sup>
static getAvailableIDs(): Array&lt;string&gt;
## i18n.getSystemLanguage<sup>(deprecated)</sup>
Obtains the list of time zone IDs supported by the system.
getSystemLanguage(): string
Obtains the system language.
This API is deprecated since API version 9. You are advised to use [System.getSystemLanguage](#getsystemlanguage9) instead.
**System capability**: SystemCapability.Global.I18n
**Return value**
| Type | Description |
| ------ | ----------------------- |
| Array&lt;string&gt; | List of time zone IDs supported by the system.|
| ------ | ------- |
| string | System language ID.|
**Example**
```js
var ids = i18n.TimeZone.getAvailableIDs();
i18n.getSystemLanguage();
```
### getAvailableZoneCityIDs<sup>9+</sup>
## i18n.getSystemRegion<sup>(deprecated)</sup>
static getAvailableZoneCityIDs(): Array&lt;string&gt;
getSystemRegion(): string
Obtains the list of time zone city IDs supported by the system.
Obtains the system region.
This API is deprecated since API version 9. You are advised to use [System.getSystemRegion](#getsystemregion9) instead.
**System capability**: SystemCapability.Global.I18n
**Return value**
| Type | Description |
| ------ | ----------------------- |
| Array&lt;string&gt; | List of time zone city IDs supported by the system.|
| ------ | ------- |
| string | System region ID.|
**Example**
```js
var cityIDs = i18n.TimeZone.getAvailableZoneCityIDs();
i18n.getSystemRegion();
```
### getCityDisplayName<sup>9+</sup>
## i18n.getSystemLocale<sup>(deprecated)</sup>
static getCityDisplayName(cityID: string, locale: string): string
getSystemLocale(): string
Obtains the localized display of a time zone city in the specified locale.
Obtains the system locale.
This API is deprecated since API version 9. You are advised to use [System.getSystemLocale](#getsystemlocale9) instead.
**System capability**: SystemCapability.Global.I18n
**Parameters**
**Return value**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ----- |
| cityID | string | Yes | Time zone city ID.|
| locale | string | Yes | Locale ID.|
| Type | Description |
| ------ | ------- |
| string | System locale ID.|
**Example**
```js
i18n.getSystemLocale();
```
## i18n.is24HourClock<sup>(deprecated)</sup>
is24HourClock(): boolean
Checks whether the 24-hour clock is used.
This API is deprecated since API version 9. You are advised to use [System.is24HourClock](#is24hourclock9) instead.
**System capability**: SystemCapability.Global.I18n
**Return value**
| Type | Description |
| ------ | ----------------------- |
| string | Localized display of the time zone city in the specified locale.|
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the 24-hour clock is used; returns **false** otherwise.|
**Example**
```js
var displayName = i18n.TimeZone.getCityDisplayName("Shanghai", "zh-CN");
var is24HourClock = i18n.is24HourClock();
```
### getTimezoneFromCity<sup>9+</sup>
## i18n.set24HourClock<sup>(deprecated)</sup>
static getTimezoneFromCity(cityID: string): TimeZone
set24HourClock(option: boolean): boolean
Obtains the **TimeZone** object corresponding to the specified time zone city ID.
Sets the 24-hour clock.
This API is deprecated since API version 9. You are advised to use [System.set24HourClock](#set24hourclock9) instead.
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ----- |
| cityID | string | Yes | Time zone city ID.|
| ------ | ------- | ---- | ---------------------------------------- |
| 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.|
**Return value**
| Type | Description |
| ------ | ----------------------- |
| TimeZone | **TimeZone** object corresponding to the specified time zone city ID.|
| ------- | ----------------------------- |
| boolean | Returns **true** if the 24-hour clock is enabled; returns **false** otherwise.|
**Example**
```js
var timezone = i18n.TimeZone.getTimezoneFromCity("Shanghai");
// Set the system time to the 24-hour clock.
var success = i18n.set24HourClock(true);
```
## i18n.setUsingLocalDigit<sup>9+</sup>
## i18n.addPreferredLanguage<sup>(deprecated)</sup>
setUsingLocalDigit(flag: boolean): boolean
addPreferredLanguage(language: string, index?: number): boolean
Sets whether to turn on the local digit switch.
This is a system API.
Adds a preferred language to the specified position on the preferred language list.
This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [System.addPreferredLanguage](#addpreferredlanguage9) instead.
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
......@@ -1794,124 +2300,142 @@ This is a system API.
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ----- |
| 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.|
| -------- | ------ | ---- | ---------- |
| language | string | Yes | Preferred language to add. |
| index | number | No | Position to which the preferred language is added.|
**Return value**
| Type | Description |
| -------- | ------------ |
| boolean | Result indicating whether the local digit switch is successfully set. The value **true** indicates that the local digit switch is successfully set, and the value **false** indicates the opposite.|
| ------- | ----------------------------- |
| boolean | Returns **true** if the preferred language is successfully added; returns **false** otherwise.|
**Example**
```js
var status = i18n.setUsingLocalDigit(true);
// Add zh-CN to the preferred language list.
var language = 'zh-CN';
var index = 0;
var success = i18n.addPreferredLanguage(language, index);
```
## i18n.getUsingLocalDigit<sup>9+</sup>
## i18n.removePreferredLanguage<sup>(deprecated)</sup>
getUsingLocalDigit(): boolean
removePreferredLanguage(index: number): boolean
Checks whether the local digit switch is turned on.
Deletes a preferred language from the specified position on the preferred language list.
This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [System.removePreferredLanguage](#removepreferredlanguage9) instead.
**Permission required**: ohos.permission.UPDATE_CONFIGURATION
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| ----- | ------ | ---- | --------------------- |
| index | number | Yes | Position of the preferred language to delete.|
**Return value**
| Type | Description |
| -------- | ------------ |
| boolean | Result indicating whether the local digit switch is turned on. The value **true** indicates that the local digit switch is turned on, and the value **false** indicates the opposite.|
| ------- | ----------------------------- |
| boolean | Returns **true** if the preferred language is deleted; returns **false** otherwise.|
**Example**
```js
var status = i18n.getUsingLocalDigit();
// Delete the first preferred language from the preferred language list.
var index = 0;
var success = i18n.removePreferredLanguage(index);
```
## Transliterator<sup>9+</sup>
## i18n.getPreferredLanguageList<sup>(deprecated)</sup>
### getAvailableIDs<sup>9+</sup>
getPreferredLanguageList(): Array&lt;string&gt;
static getAvailableIDs(): string[]
Obtains the list of preferred languages.
Obtains a list of IDs supported by the **Transliterator** object.
This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [System.getPreferredLanguageList](#getpreferredlanguagelist9) instead.
**System capability**: SystemCapability.Global.I18n
**Return value**
| Type | Description |
| ------ | ------------ |
| string[] | List of IDs supported by the **Transliterator** object.|
| ------------------- | --------- |
| Array&lt;string&gt; | List of preferred languages.|
**Example**
```
i18n.Transliterator.getAvailableIDs();
```js
var preferredLanguageList = i18n.getPreferredLanguageList();
```
### getInstance<sup>9+</sup>
static getInstance(id: string): Transliterator
## i18n.getFirstPreferredLanguage<sup>(deprecated)</sup>
Creates a **Transliterator** object.
getFirstPreferredLanguage(): string
**System capability**: SystemCapability.Global.I18n
Obtains the first language in the preferred language list.
**Parameters**
This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [System.getFirstPreferredLanguage](#getfirstpreferredlanguage9) instead.
| Name | Type | Mandatory | Description |
| ------ | ------- | ---- | -------------------- |
| id | string | Yes | ID supported by the **Transliterator** object. |
**System capability**: SystemCapability.Global.I18n
**Return value**
| Type | Description |
| ------ | ------------- |
| [Transliterator](#transliterator9) | **Transliterator** object.|
| ------ | -------------- |
| string | First language in the preferred language list.|
**Example**
```
var transliterator = i18n.Transliterator.getInstance("Any-Latn");
```js
var firstPreferredLanguage = i18n.getFirstPreferredLanguage();
```
### transform<sup>9+</sup>
## Util<sup>(deprecated)</sup>
transform(text: string): string
Converts the input string from the source format to the target format.
### unitConvert<sup>(deprecated)</sup>
static unitConvert(fromUnit: UnitInfo, toUnit: UnitInfo, value: number, locale: string, style?: string): string
Converts one measurement unit into another and formats the unit based on the specified locale and style.
This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [unitConvert](#unitconvert9) instead.
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------- | ---- | -------------------- |
| text | string | Yes | Input string. |
| -------- | ---------------------- | ---- | ---------------------------------------- |
| fromUnit | [UnitInfo](#unitinfo8) | Yes | Measurement unit to be converted. |
| toUnit | [UnitInfo](#unitinfo8) | Yes | Measurement unit to be converted to. |
| value | number | Yes | Value of the measurement unit to be converted. |
| locale | string | Yes | Locale used for formatting, for example, **zh-Hans-CN**. |
| style | string | No | Style used for formatting. The value can be **long**, **short**, or **narrow**.|
**Return value**
| Type | Description |
| ------ | ------------- |
| string | Target string.|
| ------ | ----------------------- |
| string | Character string obtained after formatting based on the measurement unit specified by **toUnit**.|
**Example**
```
var transliterator = i18n.Transliterator.getInstance("Any-Latn");
transliterator.transform ("China");
```
## Unicode<sup>9+</sup>
## Character<sup>(deprecated)</sup>
### isDigit<sup>9+</sup>
### isDigit<sup>(deprecated)</sup>
static isDigit(char: string): boolean
Checks whether the input character string is composed of digits.
This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [isDigit](#isdigit9) instead.
**System capability**: SystemCapability.Global.I18n
**Parameters**
......@@ -1926,18 +2450,15 @@ Checks whether the input character string is composed of digits.
| ------- | ------------------------------------ |
| boolean | Returns **true** if the input character is a digit; returns **false** otherwise.|
**Example**
```js
var isdigit = i18n.Unicode.isDigit("1"); // Return true.
```
### isSpaceChar<sup>9+</sup>
### isSpaceChar<sup>(deprecated)</sup>
static isSpaceChar(char: string): boolean
Checks whether the input character is a space.
This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [isSpaceChar](#isspacechar9) instead.
**System capability**: SystemCapability.Global.I18n
**Parameters**
......@@ -1952,18 +2473,15 @@ Checks whether the input character is a space.
| ------- | -------------------------------------- |
| boolean | Returns **true** if the input character is a space; returns **false** otherwise.|
**Example**
```js
var isspacechar = i18n.Unicode.isSpaceChar("a"); // Return false.
```
### isWhitespace<sup>9+</sup>
### isWhitespace<sup>(deprecated)</sup>
static isWhitespace(char: string): boolean
Checks whether the input character is a white space.
This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [isWhitespace](#iswhitespace9) instead.
**System capability**: SystemCapability.Global.I18n
**Parameters**
......@@ -1978,18 +2496,15 @@ Checks whether the input character is a white space.
| ------- | -------------------------------------- |
| boolean | Returns **true** if the input character is a white space; returns **false** otherwise.|
**Example**
```js
var iswhitespace = i18n.Unicode.isWhitespace("a"); // Return false.
```
### isRTL<sup>9+</sup>
### isRTL<sup>(deprecated)</sup>
static isRTL(char: string): boolean
Checks whether the input character is of the right to left (RTL) language.
This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [isRTL](#isrtl9) instead.
**System capability**: SystemCapability.Global.I18n
**Parameters**
......@@ -2004,18 +2519,15 @@ Checks whether the input character is of the right to left (RTL) language.
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the input character is of the RTL language; returns **false** otherwise.|
**Example**
```js
var isrtl = i18n.Unicode.isRTL("a"); // Return false.
```
### isIdeograph<sup>9+</sup>
### isIdeograph<sup>(deprecated)</sup>
static isIdeograph(char: string): boolean
Checks whether the input character is an ideographic character.
This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [isIdeograph](#isideograph9) instead.
**System capability**: SystemCapability.Global.I18n
**Parameters**
......@@ -2030,18 +2542,15 @@ Checks whether the input character is an ideographic character.
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the input character is an ideographic character; returns **false** otherwise.|
**Example**
```js
var isideograph = i18n.Unicode.isIdeograph("a"); // Return false.
```
### isLetter<sup>9+</sup>
### isLetter<sup>(deprecated)</sup>
static isLetter(char: string): boolean
Checks whether the input character is a letter.
This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [isLetter](#isletter9) instead.
**System capability**: SystemCapability.Global.I18n
**Parameters**
......@@ -2056,18 +2565,15 @@ Checks whether the input character is a letter.
| ------- | ------------------------------------ |
| boolean | Returns **true** if the input character is a letter; returns **false** otherwise.|
**Example**
```js
var isletter = i18n.Unicode.isLetter("a"); // Return true.
```
### isLowerCase<sup>9+</sup>
### isLowerCase<sup>(deprecated)</sup>
static isLowerCase(char: string): boolean
Checks whether the input character is a lowercase letter.
This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [isLowerCase](#islowercase9) instead.
**System capability**: SystemCapability.Global.I18n
**Parameters**
......@@ -2082,18 +2588,15 @@ Checks whether the input character is a lowercase letter.
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the input character is a lowercase letter; returns **false** otherwise.|
**Example**
```js
var islowercase = i18n.Unicode.isLowerCase("a"); // Return true.
```
### isUpperCase<sup>9+</sup>
### isUpperCase<sup>(deprecated)</sup>
static isUpperCase(char: string): boolean
Checks whether the input character is an uppercase letter.
This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [isUpperCase](#isuppercase9) instead.
**System capability**: SystemCapability.Global.I18n
**Parameters**
......@@ -2108,18 +2611,15 @@ Checks whether the input character is an uppercase letter.
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the input character is an uppercase letter; returns **false** otherwise.|
**Example**
```js
var isuppercase = i18n.Unicode.isUpperCase("a"); // Return false.
```
### getType<sup>9+</sup>
### getType<sup>(deprecated)</sup>
static getType(char: string): string
Obtains the type of the input character string.
This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [getType](#gettype9) instead.
**System capability**: SystemCapability.Global.I18n
**Parameters**
......@@ -2133,67 +2633,3 @@ Obtains the type of the input character string.
| Type | Description |
| ------ | ----------- |
| string | Type of the input character.|
**Example**
```js
var type = i18n.Unicode.getType("a");
```
## I18NUtil<sup>9+</sup>
### unitConvert<sup>9+</sup>
static unitConvert(fromUnit: UnitInfo, toUnit: UnitInfo, value: number, locale: string, style?: string): string
Converts one measurement unit into another and formats the unit based on the specified locale and style.
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| -------- | ---------------------- | ---- | ---------------------------------------- |
| fromUnit | [UnitInfo](#unitinfo8) | Yes | Measurement unit to be converted. |
| toUnit | [UnitInfo](#unitinfo8) | Yes | Measurement unit to be converted to. |
| value | number | Yes | Value of the measurement unit to be converted. |
| locale | string | Yes | Locale used for formatting, for example, **zh-Hans-CN**. |
| style | string | No | Style used for formatting. The value can be **long**, **short**, or **narrow**.|
**Return value**
| Type | Description |
| ------ | ----------------------- |
| string | Character string obtained after formatting based on the measurement unit specified by **toUnit**.|
**Example**
```js
i18n.I18NUtil.unitConvert({unit: "cup", measureSystem: "US"}, {unit: "liter", measureSystem: "SI"}, 1000, "en-US", "long");
```
### getDateOrder<sup>9+</sup>
static getDateOrder(locale: string): string
Obtains the sequence of the year, month, and day in the specified locale.
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| ------ | ------ | ---- | ------------------------- |
| locale | string | Yes | Locale used for formatting, for example, **zh-Hans-CN**.|
**Return value**
| Type | Description |
| ------ | ------------------- |
| string | Sequence of the year, month, and day.|
**Example**
```js
i18n.I18NUtil.getDateOrder("zh-CN");
```
# I18N Error Codes
## 890001 Incorrect Parameter Type
**Error Message**
Unspported para value.
**Description**
This error code is reported if an I18N API is called with invalid parameter values specified.
**Possible Causes**
Invalid parameter values are probably due to incorrect parameter types.
**Solution**
Check whether the parameter type is correct.
## 890002 Incorrect Configuration Option
**Error Message**
Unspported option value.
**Description**
This error code is reported if an I18N API is called with invalid option values specified.
**Possible Causes**
Invalid option values are probably due to incorrect option types.
**Solution**
Check whether the option type is correct.
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册