提交 b8c7a4fe 编写于 作者: S shawn_he

update doc

Signed-off-by: Nshawn_he <shawn.he@huawei.com>
上级 56ab6d24
# Internationalization – i18n # 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.
The [Intl](intl-guidelines.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.
> ![icon-note.gif](public_sys-resources/icon-note.gif) **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.
>
> - This module contains enhanced i18n APIs, which are not defined in ECMA 402.
## Modules to Import ## Modules to Import
...@@ -49,15 +53,15 @@ Obtains the localized script for the specified country. ...@@ -49,15 +53,15 @@ Obtains the localized script for the specified country.
**System capability**: SystemCapability.Global.I18n **System capability**: SystemCapability.Global.I18n
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| ------------ | ------- | ---- | ---------------- | | ------------ | ------- | ---- | ----------------------------- |
| country | string | Yes | Specified country. | | country | string | Yes | Specified country. |
| locale | string | Yes | Locale ID. | | locale | string | Yes | Locale ID. |
| sentenceCase | boolean | No | Whether to use sentence case for the localized script.| | sentenceCase | boolean | No | Whether to use sentence case for the localized script.|
**Return Value** **Return Value**
| Type | Description | | Type | Description |
| ------ | ------------- | | ------ | ------------------------------------------ |
| string | Localized script for the specified country.| | string | Localized script for the specified country.|
**Example** **Example**
...@@ -76,12 +80,12 @@ Checks whether the localized script for the specified language is displayed from ...@@ -76,12 +80,12 @@ Checks whether the localized script for the specified language is displayed from
**System capability**: SystemCapability.Global.I18n **System capability**: SystemCapability.Global.I18n
**Parameters** **Parameters**
| Name | Type | Description | | Name | Type | Description |
| ------ | ------ | ------- | | ------ | ------ | ----------- |
| locale | string | Locale ID.| | locale | string | Locale ID. |
**Return Value** **Return Value**
| Type | Description | | Type | Description |
| ------- | ---------------------------------------- | | ------- | ---------------------------------------- |
| boolean | Returns **true** if the localized script is displayed from right to left; returns **false** otherwise.| | boolean | Returns **true** if the localized script is displayed from right to left; returns **false** otherwise.|
...@@ -115,7 +119,9 @@ Obtains the system language. ...@@ -115,7 +119,9 @@ Obtains the system language.
setSystemLanguage(language: string): boolean setSystemLanguage(language: string): boolean
Sets the system language. Sets the system language. Currently, this API does not support real-time updating of the system language.
**System API**: This is a system API.
**Required permission**: ohos.permission.UPDATE_CONFIGURATION **Required permission**: ohos.permission.UPDATE_CONFIGURATION
...@@ -145,9 +151,9 @@ getSystemLanguages(): Array&lt;string&gt; ...@@ -145,9 +151,9 @@ getSystemLanguages(): Array&lt;string&gt;
Obtains the list of system languages. Obtains the list of system languages.
**System capability**: SystemCapability.Global.I18n **System API**: This is a system API.
**System API**: This is a system API and cannot be called by third-party applications. **System capability**: SystemCapability.Global.I18n
**Return Value** **Return Value**
| Type | Description | | Type | Description |
...@@ -166,9 +172,9 @@ getSystemCountries(language: string): Array&lt;string&gt; ...@@ -166,9 +172,9 @@ getSystemCountries(language: string): Array&lt;string&gt;
Obtains the list of countries and regions supported for the specified language. Obtains the list of countries and regions supported for the specified language.
**System capability**: SystemCapability.Global.I18n **System API**: This is a system API.
**System API**: This is a system API and cannot be called by third-party applications. **System capability**: SystemCapability.Global.I18n
**Parameters** **Parameters**
| Name | Type | Description | | Name | Type | Description |
...@@ -211,12 +217,12 @@ setSystemRegion(region: string): boolean ...@@ -211,12 +217,12 @@ setSystemRegion(region: string): boolean
Sets the system region. Sets the system region.
**System API**: This is a system API.
**Required permission**: ohos.permission.UPDATE_CONFIGURATION **Required permission**: ohos.permission.UPDATE_CONFIGURATION
**System capability**: SystemCapability.Global.I18n **System capability**: SystemCapability.Global.I18n
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
| Name | Type | Description | | Name | Type | Description |
| ------ | ------ | ----- | | ------ | ------ | ----- |
...@@ -258,12 +264,12 @@ setSystemLocale(locale: string): boolean ...@@ -258,12 +264,12 @@ setSystemLocale(locale: string): boolean
Sets the system locale. Sets the system locale.
**System API**: This is a system API.
**Required permission**: ohos.permission.UPDATE_CONFIGURATION **Required permission**: ohos.permission.UPDATE_CONFIGURATION
**System capability**: SystemCapability.Global.I18n **System capability**: SystemCapability.Global.I18n
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters** **Parameters**
| Name | Type | Description | | Name | Type | Description |
| ------ | ------ | --------------- | | ------ | ------ | --------------- |
...@@ -286,9 +292,9 @@ isSuggested(language: string, region?: string): boolean ...@@ -286,9 +292,9 @@ isSuggested(language: string, region?: string): boolean
Checks whether the system language matches the specified region. Checks whether the system language matches the specified region.
**System capability**: SystemCapability.Global.I18n **System API**: This is a system API.
**System API**: This is a system API and cannot be called by third-party applications. **System capability**: SystemCapability.Global.I18n
**Parameters** **Parameters**
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
...@@ -673,6 +679,31 @@ Formats a phone number. ...@@ -673,6 +679,31 @@ Formats a phone number.
phonenumberfmt.format("15812312312"); phonenumberfmt.format("15812312312");
``` ```
### getLocationName<sup>9+</sup>
getLocationName(number: string, locale: string): string
Obtains the home location of a phone number.
**System capability**: SystemCapability.Global.I18n
**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");
```
## PhoneNumberFormatOptions<sup>8+</sup> ## PhoneNumberFormatOptions<sup>8+</sup>
...@@ -727,6 +758,28 @@ Converts one measurement unit into another and formats the unit based on the spe ...@@ -727,6 +758,28 @@ Converts one measurement unit into another and formats the unit based on the spe
i18n.Util.unitConvert({unit: "cup", measureSystem: "US"}, {unit: "liter", measureSystem: "SI"}, 1000, "en-US", "long"); i18n.Util.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**
```
i18n.Util.getDateOrder("zh-CN");
```
## getInstance<sup>8+</sup> ## getInstance<sup>8+</sup>
...@@ -816,7 +869,7 @@ Obtains the index of a text object. ...@@ -816,7 +869,7 @@ Obtains the index of a text object.
**Example** **Example**
``` ```
var indexUtil= i18n.getInstance("zh-CN"); var indexUtil= i18n.getInstance("zh-CN");
indexUtil.getIndex("hi"); // Return h. indexUtil.getIndex("hi"); // Return hi.
``` ```
...@@ -1442,10 +1495,10 @@ Obtains the **TimeZone** object corresponding to the specified time zone ID. ...@@ -1442,10 +1495,10 @@ Obtains the **TimeZone** object corresponding to the specified time zone ID.
``` ```
## RelativeTimeFormat<sup>8+</sup> ## TimeZone
### getID<sup>8+</sup> ### getID
getID(): string getID(): string
...@@ -1465,7 +1518,7 @@ Obtains the ID of the specified **TimeZone** object. ...@@ -1465,7 +1518,7 @@ Obtains the ID of the specified **TimeZone** object.
``` ```
### getDisplayName<sup>8+</sup> ### getDisplayName
getDisplayName(locale?: string, isDST?: boolean): string getDisplayName(locale?: string, isDST?: boolean): string
...@@ -1491,7 +1544,7 @@ Obtains the representation of a **TimeZone** object in the specified locale. ...@@ -1491,7 +1544,7 @@ Obtains the representation of a **TimeZone** object in the specified locale.
``` ```
### getRawOffset<sup>8+</sup> ### getRawOffset
getRawOffset(): number getRawOffset(): number
...@@ -1511,7 +1564,7 @@ Obtains the offset between the time zone represented by a **TimeZone** object an ...@@ -1511,7 +1564,7 @@ Obtains the offset between the time zone represented by a **TimeZone** object an
``` ```
### getOffset<sup>8+</sup> ### getOffset
getOffset(date?: number): number getOffset(date?: number): number
...@@ -1529,3 +1582,207 @@ Obtains the offset between the time zone represented by a **TimeZone** object an ...@@ -1529,3 +1582,207 @@ Obtains the offset between the time zone represented by a **TimeZone** object an
var timezone = i18n.getTimeZone(); var timezone = i18n.getTimeZone();
timezone.getOffset(1234567890); 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");
```
## i18n.setUsingLocalDigit<sup>9+</sup>
setUsingLocalDigit(flag: boolean): boolean
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.|
**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.|
**Example**
```ts
var status = i18n.setUsingLocalDigit(true);
```
## i18n.getUsingLocalDigit<sup>9+</sup>
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.|
**Example**
```ts
var status = i18n.getUsingLocalDigit();
```
## 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");
```
# Internationalization – intl # Internationalization – Intl
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** This module provides basic I18N capabilities, such as time and date formatting, number formatting, and string sorting, through the standard I18N APIs defined in ECMA 402.
> - The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
> The [I18N](i18n-guidelines.md) module provides enhanced I18N capabilities through supplementary APIs that are not defined in ECMA 402. It works with the Intl module to provide a complete suite of I18N capabilities.
> - This module contains standard i18n APIs, which are defined in ECMA 402.
> **NOTE**
>
> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version.
## Modules to Import ## Modules to Import
``` ```js
import Intl from '@ohos.intl'; import Intl from '@ohos.intl';
``` ```
...@@ -43,7 +46,7 @@ Creates a Locale object. ...@@ -43,7 +46,7 @@ Creates a Locale object.
**System capability**: SystemCapability.Global.I18n **System capability**: SystemCapability.Global.I18n
**Example** **Example**
``` ```js
var locale = new Intl.Locale(); var locale = new Intl.Locale();
``` ```
...@@ -63,7 +66,7 @@ Creates a Locale object. ...@@ -63,7 +66,7 @@ Creates a Locale object.
| options | LocaleOptions | No | Options for creating the **Locale** object. | | options | LocaleOptions | No | Options for creating the **Locale** object. |
**Example** **Example**
``` ```js
var locale = new Intl.Locale("zh-CN"); var locale = new Intl.Locale("zh-CN");
``` ```
...@@ -82,7 +85,7 @@ Converts locale information to a string. ...@@ -82,7 +85,7 @@ Converts locale information to a string.
| string | String containing locale information.| | string | String containing locale information.|
**Example** **Example**
``` ```js
var locale = new Intl.Locale("zh-CN"); var locale = new Intl.Locale("zh-CN");
locale.toString(); locale.toString();
``` ```
...@@ -102,7 +105,7 @@ Maximizes information of the **Locale** object. If the script and locale informa ...@@ -102,7 +105,7 @@ Maximizes information of the **Locale** object. If the script and locale informa
| [Locale](#locale) | **Locale** object with the maximized information.| | [Locale](#locale) | **Locale** object with the maximized information.|
**Example** **Example**
``` ```js
var locale = new Intl.Locale("zh-CN"); var locale = new Intl.Locale("zh-CN");
locale.maximize(); locale.maximize();
``` ```
...@@ -122,7 +125,7 @@ Minimizes information of the **Locale** object. If the script and locale informa ...@@ -122,7 +125,7 @@ Minimizes information of the **Locale** object. If the script and locale informa
| [Locale](#locale) | **Locale** object with the minimized information.| | [Locale](#locale) | **Locale** object with the minimized information.|
**Example** **Example**
``` ```js
var locale = new Intl.Locale("zh-CN"); var locale = new Intl.Locale("zh-CN");
locale.minimize(); locale.minimize();
``` ```
...@@ -156,7 +159,7 @@ Creates a **DateTimeOptions** object for the specified locale. ...@@ -156,7 +159,7 @@ Creates a **DateTimeOptions** object for the specified locale.
**System capability**: SystemCapability.Global.I18n **System capability**: SystemCapability.Global.I18n
**Example** **Example**
``` ```js
var datefmt= new Intl.DateTimeFormat(); var datefmt= new Intl.DateTimeFormat();
``` ```
...@@ -176,13 +179,13 @@ Creates a **DateTimeOptions** object for the specified locale. ...@@ -176,13 +179,13 @@ Creates a **DateTimeOptions** object for the specified locale.
| options | [DateTimeOptions](#datetimeoptions) | No | Options for creating a **DateTimeFormat** object. | | options | [DateTimeOptions](#datetimeoptions) | No | Options for creating a **DateTimeFormat** object. |
**Example** **Example**
``` ```js
var datefmt= new Intl.DateTimeFormat("zh-CN", { dateStyle: 'full', timeStyle: 'medium' }); var datefmt= new Intl.DateTimeFormat("zh-CN", { dateStyle: 'full', timeStyle: 'medium' });
``` ```
**Example** **Example**
``` ```js
var datefmt= new Intl.DateTimeFormat(["ban", "zh"], { dateStyle: 'full', timeStyle: 'medium' }); var datefmt= new Intl.DateTimeFormat(["ban", "zh"], { dateStyle: 'full', timeStyle: 'medium' });
``` ```
...@@ -206,7 +209,7 @@ Formats the specified date and time. ...@@ -206,7 +209,7 @@ Formats the specified date and time.
| string | A string containing the formatted date and time.| | string | A string containing the formatted date and time.|
**Example** **Example**
``` ```js
var date = new Date(2021, 11, 17, 3, 24, 0); var date = new Date(2021, 11, 17, 3, 24, 0);
var datefmt = new Intl.DateTimeFormat("en-GB"); var datefmt = new Intl.DateTimeFormat("en-GB");
datefmt.format(date); datefmt.format(date);
...@@ -233,7 +236,7 @@ Formats the specified date range. ...@@ -233,7 +236,7 @@ Formats the specified date range.
| string | A string containing the formatted date and time range.| | string | A string containing the formatted date and time range.|
**Example** **Example**
``` ```js
var startDate = new Date(2021, 11, 17, 3, 24, 0); var startDate = new Date(2021, 11, 17, 3, 24, 0);
var endDate = new Date(2021, 11, 18, 3, 24, 0); var endDate = new Date(2021, 11, 18, 3, 24, 0);
var datefmt = new Intl.DateTimeFormat("en-GB"); var datefmt = new Intl.DateTimeFormat("en-GB");
...@@ -255,7 +258,7 @@ Obtains the formatting options for **DateTimeFormat** object. ...@@ -255,7 +258,7 @@ Obtains the formatting options for **DateTimeFormat** object.
| [DateTimeOptions](#datetimeoptions) | Formatting options for **DateTimeFormat** objects.| | [DateTimeOptions](#datetimeoptions) | Formatting options for **DateTimeFormat** objects.|
**Example** **Example**
``` ```js
var datefmt = new Intl.DateTimeFormat("en-GB"); var datefmt = new Intl.DateTimeFormat("en-GB");
datefmt.resolvedOptions(); datefmt.resolvedOptions();
``` ```
...@@ -302,7 +305,7 @@ Creates a **NumberFormat** object for the specified locale. ...@@ -302,7 +305,7 @@ Creates a **NumberFormat** object for the specified locale.
**System capability**: SystemCapability.Global.I18n **System capability**: SystemCapability.Global.I18n
**Example** **Example**
``` ```js
var numfmt = new Intl.NumberFormat(); var numfmt = new Intl.NumberFormat();
``` ```
...@@ -322,7 +325,7 @@ Parameters ...@@ -322,7 +325,7 @@ Parameters
| options | [NumberOptions](#numberoptions) | No | Options for creating a **NumberFormat** object. | | options | [NumberOptions](#numberoptions) | No | Options for creating a **NumberFormat** object. |
**Example** **Example**
``` ```js
var numfmt = new Intl.NumberFormat("en-GB", {style:'decimal', notation:"scientific"}); var numfmt = new Intl.NumberFormat("en-GB", {style:'decimal', notation:"scientific"});
``` ```
...@@ -347,7 +350,7 @@ Formats a number. ...@@ -347,7 +350,7 @@ Formats a number.
**Example** **Example**
``` ```js
var numfmt = new Intl.NumberFormat(["en-GB", "zh"], {style:'decimal', notation:"scientific"}); var numfmt = new Intl.NumberFormat(["en-GB", "zh"], {style:'decimal', notation:"scientific"});
numfmt.format(1223); numfmt.format(1223);
``` ```
...@@ -368,7 +371,7 @@ Obtains the options of the **NumberFormat** object. ...@@ -368,7 +371,7 @@ Obtains the options of the **NumberFormat** object.
**Example** **Example**
``` ```js
var numfmt = new Intl.NumberFormat(["en-GB", "zh"], {style:'decimal', notation:"scientific"}); var numfmt = new Intl.NumberFormat(["en-GB", "zh"], {style:'decimal', notation:"scientific"});
numfmt.resolvedOptions(); numfmt.resolvedOptions();
``` ```
...@@ -388,7 +391,7 @@ Provides the device capability. ...@@ -388,7 +391,7 @@ Provides the device capability.
| currencyDisplay | string | Yes | Yes | Currency display mode. The value can be **symbol**, **narrowSymbol**, **code**, or **name**.| | currencyDisplay | string | Yes | Yes | Currency display mode. The value can be **symbol**, **narrowSymbol**, **code**, or **name**.|
| unit | string | Yes | Yes | Unit name, for example, **meter**, **inch**, or **hectare**. | | unit | string | Yes | Yes | Unit name, for example, **meter**, **inch**, or **hectare**. |
| unitDisplay | string | Yes | Yes | Unit display format. The value can be **long**, **short**, or **medium**.| | unitDisplay | string | Yes | Yes | Unit display format. The value can be **long**, **short**, or **medium**.|
| unitUsage<sup>8+</sup> | string | Yes | Yes | Unit usage scenario. The value can be any of the following: **default**, **area-land-agricult**, **area-land-commercl**, **area-land-residntl**, **length-person**, **length-person-small**, **length-rainfall**, **length-road**, **length-road-small**, **length-snowfall**, **length-vehicle**, **length-visiblty**, **length-visiblty-small**, **length-person-informal**, **length-person-small-informal**, **length-road-informal**, **speed-road-travel**, **speed-wind**, **temperature-person**, **temperature-weather**, **volume-vehicle-fuel**.| | unitUsage<sup>8+</sup> | string | Yes | Yes | Unit usage scenario. The value can be any of the following: **default**, **area-land-agricult**, **area-land-commercl**, **area-land-residntl**, **length-person**, **length-person-small**, **length-rainfall**, **length-road**, **length-road-small**, **length-snowfall**, **length-vehicle**, **length-visiblty**, **length-visiblty-small**, **length-person-informal**, **length-person-small-informal**, **length-road-informal**, **speed-road-travel**, **speed-wind**, **temperature-person**, **temperature-weather**, **volume-vehicle-fuel**.|
| signDisplay | string | Yes | Yes | Number sign display format. The value can be **auto**, **never**, **always**, or **expectZero**.| | signDisplay | string | Yes | Yes | Number sign display format. The value can be **auto**, **never**, **always**, or **expectZero**.|
| compactDisplay | string | Yes | Yes | Compact display format. The value can be **long** or **short**. | | compactDisplay | string | Yes | Yes | Compact display format. The value can be **long** or **short**. |
| notation | string | Yes | Yes | Number formatting specification. The value can be **standard**, **scientific**, **engineering**, or **compact**.| | notation | string | Yes | Yes | Number formatting specification. The value can be **standard**, **scientific**, **engineering**, or **compact**.|
...@@ -415,7 +418,7 @@ Creates a Collator object. ...@@ -415,7 +418,7 @@ Creates a Collator object.
**System capability**: SystemCapability.Global.I18n **System capability**: SystemCapability.Global.I18n
**Example** **Example**
``` ```js
var collator = new Intl.Collator(); var collator = new Intl.Collator();
``` ```
...@@ -436,7 +439,7 @@ Creates a Collator object. ...@@ -436,7 +439,7 @@ Creates a Collator object.
| options | [CollatorOptions](#collatoroptions) | No | Options for creating a **Collator** object. | | options | [CollatorOptions](#collatoroptions) | No | Options for creating a **Collator** object. |
**Example** **Example**
``` ```js
var collator = new Intl.Collator("zh-CN", {localeMatcher: "lookup", usage: "sort"}); var collator = new Intl.Collator("zh-CN", {localeMatcher: "lookup", usage: "sort"});
``` ```
...@@ -461,7 +464,7 @@ Compares two strings based on the sorting policy of the **Collator** object. ...@@ -461,7 +464,7 @@ Compares two strings based on the sorting policy of the **Collator** object.
| number | Comparison result. If the value is a negative number, the first string is before the second string. If the value of number is **0**, the first string is equal to the second string. If the value of number is a positive number, the first string is after the second string.| | number | Comparison result. If the value is a negative number, the first string is before the second string. If the value of number is **0**, the first string is equal to the second string. If the value of number is a positive number, the first string is after the second string.|
**Example** **Example**
``` ```js
var collator = new Intl.Collator("zh-Hans"); var collator = new Intl.Collator("zh-Hans");
collator.compare("first", "second"); collator.compare("first", "second");
``` ```
...@@ -481,13 +484,13 @@ Returns properties reflecting the locale and collation options of a **Collator** ...@@ -481,13 +484,13 @@ Returns properties reflecting the locale and collation options of a **Collator**
| [CollatorOptions](#collatoroptions) | Properties of the **Collator** object.| | [CollatorOptions](#collatoroptions) | Properties of the **Collator** object.|
**Example** **Example**
``` ```js
var collator = new Intl.Collator("zh-Hans"); var collator = new Intl.Collator("zh-Hans");
var options = collator.resolvedOptions(); var options = collator.resolvedOptions();
``` ```
## CollatorOptions<sup>8+</sup><a name=collatoroptions></a> ## CollatorOptions<sup>8+</sup>
Represents the properties of a **Collator** object. Represents the properties of a **Collator** object.
...@@ -516,7 +519,7 @@ Create a **PluralRules** object. ...@@ -516,7 +519,7 @@ Create a **PluralRules** object.
**System capability**: SystemCapability.Global.I18n **System capability**: SystemCapability.Global.I18n
**Example** **Example**
``` ```js
var pluralRules = new Intl.PluralRules(); var pluralRules = new Intl.PluralRules();
``` ```
...@@ -536,8 +539,8 @@ Parameters ...@@ -536,8 +539,8 @@ Parameters
| options | [PluralRulesOptions](#pluralrulesoptions) | No | Options for creating a **PluralRules** object. | | options | [PluralRulesOptions](#pluralrulesoptions) | No | Options for creating a **PluralRules** object. |
**Example** **Example**
``` ```js
var pluralRules= new Intl.PluraRules("zh-CN", {"localeMatcher": "lookup", "type": "cardinal"}); var pluralRules= new Intl.PluralRules("zh-CN", {"localeMatcher": "lookup", "type": "cardinal"});
``` ```
...@@ -560,13 +563,13 @@ Obtains a string that represents the singular-plural type of the specified numbe ...@@ -560,13 +563,13 @@ Obtains a string that represents the singular-plural type of the specified numbe
| string | Singular-plural type. The value can be any of the following: **one**, **two**, **few**, **many**, **others**.| | string | Singular-plural type. The value can be any of the following: **one**, **two**, **few**, **many**, **others**.|
**Example** **Example**
``` ```js
var pluralRules = new Intl.PluralRules("zh-Hans"); var pluralRules = new Intl.PluralRules("zh-Hans");
pluralRules.select(1); pluralRules.select(1);
``` ```
## PluralRulesOptions<sup>8+</sup><a name=pluralrulesoptions></a> ## PluralRulesOptions<sup>8+</sup>
Represents the properties of a **PluralRules** object. Represents the properties of a **PluralRules** object.
...@@ -595,7 +598,7 @@ Creates a **RelativeTimeFormat** object. ...@@ -595,7 +598,7 @@ Creates a **RelativeTimeFormat** object.
**System capability**: SystemCapability.Global.I18n **System capability**: SystemCapability.Global.I18n
**Example** **Example**
``` ```js
var relativetimefmt = new Intl.RelativeTimeFormat(); var relativetimefmt = new Intl.RelativeTimeFormat();
``` ```
...@@ -615,7 +618,7 @@ Parameters ...@@ -615,7 +618,7 @@ Parameters
| options | [RelativeTimeFormatInputOptions](#relativetimeformatinputoptions) | No | Options for creating a **RelativeTimeFormat** object. | | options | [RelativeTimeFormatInputOptions](#relativetimeformatinputoptions) | No | Options for creating a **RelativeTimeFormat** object. |
**Example** **Example**
``` ```js
var relativeTimeFormat = new Intl.RelativeTimeFormat("zh-CN", {"localeMatcher": "lookup", "numeric": "always", "style": "long"}); var relativeTimeFormat = new Intl.RelativeTimeFormat("zh-CN", {"localeMatcher": "lookup", "numeric": "always", "style": "long"});
``` ```
...@@ -640,7 +643,7 @@ Formats the value and unit based on the specified locale and formatting options. ...@@ -640,7 +643,7 @@ Formats the value and unit based on the specified locale and formatting options.
| string | Relative time after formatting.| | string | Relative time after formatting.|
**Example** **Example**
``` ```js
var relativetimefmt = new Intl.RelativeTimeFormat("zh-CN"); var relativetimefmt = new Intl.RelativeTimeFormat("zh-CN");
relativetimefmt.format(3, "quarter") relativetimefmt.format(3, "quarter")
``` ```
...@@ -666,7 +669,7 @@ Returns an array of RelativeTimeFormat objects in parts for locale-aware formatt ...@@ -666,7 +669,7 @@ Returns an array of RelativeTimeFormat objects in parts for locale-aware formatt
| Array&lt;object&gt; | An array of **RelativeTimeFormat** objects in parts.| | Array&lt;object&gt; | An array of **RelativeTimeFormat** objects in parts.|
**Example** **Example**
``` ```js
var relativetimefmt = new Intl.RelativeTimeFormat("en", {"numeric": "auto"}); var relativetimefmt = new Intl.RelativeTimeFormat("en", {"numeric": "auto"});
var parts = relativetimefmt.format(10, "seconds"); var parts = relativetimefmt.format(10, "seconds");
``` ```
...@@ -686,13 +689,13 @@ Obtains the formatting options for **RelativeTimeFormat** objects. ...@@ -686,13 +689,13 @@ Obtains the formatting options for **RelativeTimeFormat** objects.
| [RelativeTimeFormatResolvedOptions](#relativetimeformatresolvedoptions) | Formatting options for **RelativeTimeFormat** objects.| | [RelativeTimeFormatResolvedOptions](#relativetimeformatresolvedoptions) | Formatting options for **RelativeTimeFormat** objects.|
**Example** **Example**
``` ```js
var relativetimefmt= new Intl.RelativeTimeFormat("en-GB"); var relativetimefmt= new Intl.RelativeTimeFormat("en-GB");
relativetimefmt.resolvedOptions(); relativetimefmt.resolvedOptions();
``` ```
## RelativeTimeFormatInputOptions<sup>8+</sup><a name=relativetimeformatinputoptions></a> ## RelativeTimeFormatInputOptions<sup>8+</sup>
Represents the properties of a **RelativeTimeFormat** object. Represents the properties of a **RelativeTimeFormat** object.
...@@ -705,7 +708,7 @@ Represents the properties of a **RelativeTimeFormat** object. ...@@ -705,7 +708,7 @@ Represents the properties of a **RelativeTimeFormat** object.
| style | string | Yes | Yes | Length of an internationalized message. The value can be **long**, **short**, or **narrow**.| | style | string | Yes | Yes | Length of an internationalized message. The value can be **long**, **short**, or **narrow**.|
## RelativeTimeFormatResolvedOptions<sup>8+</sup><a name=relativetimeformatresolvedoptions></a> ## RelativeTimeFormatResolvedOptions<sup>8+</sup>
Represents the properties of a **RelativeTimeFormat** object. Represents the properties of a **RelativeTimeFormat** object.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册