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

!9366 翻译已完成8932+8855+8850+8932

Merge pull request !9366 from shawn_he/8855-a
# 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
......@@ -49,15 +53,15 @@ Obtains the localized script for the specified country.
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Mandatory | Description |
| ------------ | ------- | ---- | ---------------- |
| 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 |
| ------ | ------------- |
| Type | Description |
| ------ | ------------------------------------------ |
| string | Localized script for the specified country.|
**Example**
......@@ -76,12 +80,12 @@ Checks whether the localized script for the specified language is displayed from
**System capability**: SystemCapability.Global.I18n
**Parameters**
| Name | Type | Description |
| ------ | ------ | ------- |
| locale | string | Locale ID.|
| Name | Type | Description |
| ------ | ------ | ----------- |
| locale | string | Locale ID. |
**Return Value**
| Type | Description |
| Type | Description |
| ------- | ---------------------------------------- |
| boolean | Returns **true** if the localized script is displayed from right to left; returns **false** otherwise.|
......@@ -115,7 +119,9 @@ Obtains the system language.
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
......@@ -145,9 +151,9 @@ getSystemLanguages(): Array<string>
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**
| Type | Description |
......@@ -166,9 +172,9 @@ getSystemCountries(language: string): Array<string>
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**
| Name | Type | Description |
......@@ -211,12 +217,12 @@ setSystemRegion(region: string): boolean
Sets the system region.
**System API**: This is a system API.
**Required permission**: ohos.permission.UPDATE_CONFIGURATION
**System capability**: SystemCapability.Global.I18n
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Description |
| ------ | ------ | ----- |
......@@ -258,12 +264,12 @@ setSystemLocale(locale: string): boolean
Sets the system locale.
**System API**: This is a system API.
**Required permission**: ohos.permission.UPDATE_CONFIGURATION
**System capability**: SystemCapability.Global.I18n
**System API**: This is a system API and cannot be called by third-party applications.
**Parameters**
| Name | Type | Description |
| ------ | ------ | --------------- |
......@@ -286,9 +292,9 @@ isSuggested(language: string, region?: string): boolean
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**
| Name | Type | Mandatory | Description |
......@@ -673,6 +679,31 @@ Formats a phone number.
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>
......@@ -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");
```
### 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>
......@@ -816,7 +869,7 @@ Obtains the index of a text object.
**Example**
```
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.
```
## RelativeTimeFormat<sup>8+</sup>
## TimeZone
### getID<sup>8+</sup>
### getID
getID(): string
......@@ -1465,7 +1518,7 @@ Obtains the ID of the specified **TimeZone** object.
```
### getDisplayName<sup>8+</sup>
### getDisplayName
getDisplayName(locale?: string, isDST?: boolean): string
......@@ -1491,7 +1544,7 @@ Obtains the representation of a **TimeZone** object in the specified locale.
```
### getRawOffset<sup>8+</sup>
### getRawOffset
getRawOffset(): number
......@@ -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
......@@ -1529,3 +1582,207 @@ Obtains the offset between the time zone represented by a **TimeZone** object an
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");
```
## 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**
> - 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.
>
> - This module contains standard i18n APIs, which are defined in ECMA 402.
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 [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.
> **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
```
```js
import Intl from '@ohos.intl';
```
......@@ -43,7 +46,7 @@ Creates a Locale object.
**System capability**: SystemCapability.Global.I18n
**Example**
```
```js
var locale = new Intl.Locale();
```
......@@ -63,7 +66,7 @@ Creates a Locale object.
| options | LocaleOptions | No | Options for creating the **Locale** object. |
**Example**
```
```js
var locale = new Intl.Locale("zh-CN");
```
......@@ -82,7 +85,7 @@ Converts locale information to a string.
| string | String containing locale information.|
**Example**
```
```js
var locale = new Intl.Locale("zh-CN");
locale.toString();
```
......@@ -102,7 +105,7 @@ Maximizes information of the **Locale** object. If the script and locale informa
| [Locale](#locale) | **Locale** object with the maximized information.|
**Example**
```
```js
var locale = new Intl.Locale("zh-CN");
locale.maximize();
```
......@@ -122,7 +125,7 @@ Minimizes information of the **Locale** object. If the script and locale informa
| [Locale](#locale) | **Locale** object with the minimized information.|
**Example**
```
```js
var locale = new Intl.Locale("zh-CN");
locale.minimize();
```
......@@ -156,7 +159,7 @@ Creates a **DateTimeOptions** object for the specified locale.
**System capability**: SystemCapability.Global.I18n
**Example**
```
```js
var datefmt= new Intl.DateTimeFormat();
```
......@@ -176,13 +179,13 @@ Creates a **DateTimeOptions** object for the specified locale.
| options | [DateTimeOptions](#datetimeoptions) | No | Options for creating a **DateTimeFormat** object. |
**Example**
```
```js
var datefmt= new Intl.DateTimeFormat("zh-CN", { dateStyle: 'full', timeStyle: 'medium' });
```
**Example**
```
```js
var datefmt= new Intl.DateTimeFormat(["ban", "zh"], { dateStyle: 'full', timeStyle: 'medium' });
```
......@@ -206,7 +209,7 @@ Formats the specified date and time.
| string | A string containing the formatted date and time.|
**Example**
```
```js
var date = new Date(2021, 11, 17, 3, 24, 0);
var datefmt = new Intl.DateTimeFormat("en-GB");
datefmt.format(date);
......@@ -233,7 +236,7 @@ Formats the specified date range.
| string | A string containing the formatted date and time range.|
**Example**
```
```js
var startDate = new Date(2021, 11, 17, 3, 24, 0);
var endDate = new Date(2021, 11, 18, 3, 24, 0);
var datefmt = new Intl.DateTimeFormat("en-GB");
......@@ -255,7 +258,7 @@ Obtains the formatting options for **DateTimeFormat** object.
| [DateTimeOptions](#datetimeoptions) | Formatting options for **DateTimeFormat** objects.|
**Example**
```
```js
var datefmt = new Intl.DateTimeFormat("en-GB");
datefmt.resolvedOptions();
```
......@@ -302,7 +305,7 @@ Creates a **NumberFormat** object for the specified locale.
**System capability**: SystemCapability.Global.I18n
**Example**
```
```js
var numfmt = new Intl.NumberFormat();
```
......@@ -322,7 +325,7 @@ Parameters
| options | [NumberOptions](#numberoptions) | No | Options for creating a **NumberFormat** object. |
**Example**
```
```js
var numfmt = new Intl.NumberFormat("en-GB", {style:'decimal', notation:"scientific"});
```
......@@ -347,7 +350,7 @@ Formats a number.
**Example**
```
```js
var numfmt = new Intl.NumberFormat(["en-GB", "zh"], {style:'decimal', notation:"scientific"});
numfmt.format(1223);
```
......@@ -368,7 +371,7 @@ Obtains the options of the **NumberFormat** object.
**Example**
```
```js
var numfmt = new Intl.NumberFormat(["en-GB", "zh"], {style:'decimal', notation:"scientific"});
numfmt.resolvedOptions();
```
......@@ -388,7 +391,7 @@ Provides the device capability.
| 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**. |
| 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**.|
| 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**.|
......@@ -415,7 +418,7 @@ Creates a Collator object.
**System capability**: SystemCapability.Global.I18n
**Example**
```
```js
var collator = new Intl.Collator();
```
......@@ -436,7 +439,7 @@ Creates a Collator object.
| options | [CollatorOptions](#collatoroptions) | No | Options for creating a **Collator** object. |
**Example**
```
```js
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.
| 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**
```
```js
var collator = new Intl.Collator("zh-Hans");
collator.compare("first", "second");
```
......@@ -481,13 +484,13 @@ Returns properties reflecting the locale and collation options of a **Collator**
| [CollatorOptions](#collatoroptions) | Properties of the **Collator** object.|
**Example**
```
```js
var collator = new Intl.Collator("zh-Hans");
var options = collator.resolvedOptions();
```
## CollatorOptions<sup>8+</sup><a name=collatoroptions></a>
## CollatorOptions<sup>8+</sup>
Represents the properties of a **Collator** object.
......@@ -516,7 +519,7 @@ Create a **PluralRules** object.
**System capability**: SystemCapability.Global.I18n
**Example**
```
```js
var pluralRules = new Intl.PluralRules();
```
......@@ -536,8 +539,8 @@ Parameters
| options | [PluralRulesOptions](#pluralrulesoptions) | No | Options for creating a **PluralRules** object. |
**Example**
```
var pluralRules= new Intl.PluraRules("zh-CN", {"localeMatcher": "lookup", "type": "cardinal"});
```js
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
| string | Singular-plural type. The value can be any of the following: **one**, **two**, **few**, **many**, **others**.|
**Example**
```
```js
var pluralRules = new Intl.PluralRules("zh-Hans");
pluralRules.select(1);
```
## PluralRulesOptions<sup>8+</sup><a name=pluralrulesoptions></a>
## PluralRulesOptions<sup>8+</sup>
Represents the properties of a **PluralRules** object.
......@@ -595,7 +598,7 @@ Creates a **RelativeTimeFormat** object.
**System capability**: SystemCapability.Global.I18n
**Example**
```
```js
var relativetimefmt = new Intl.RelativeTimeFormat();
```
......@@ -615,7 +618,7 @@ Parameters
| options | [RelativeTimeFormatInputOptions](#relativetimeformatinputoptions) | No | Options for creating a **RelativeTimeFormat** object. |
**Example**
```
```js
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.
| string | Relative time after formatting.|
**Example**
```
```js
var relativetimefmt = new Intl.RelativeTimeFormat("zh-CN");
relativetimefmt.format(3, "quarter")
```
......@@ -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.|
**Example**
```
```js
var relativetimefmt = new Intl.RelativeTimeFormat("en", {"numeric": "auto"});
var parts = relativetimefmt.format(10, "seconds");
```
......@@ -686,13 +689,13 @@ Obtains the formatting options for **RelativeTimeFormat** objects.
| [RelativeTimeFormatResolvedOptions](#relativetimeformatresolvedoptions) | Formatting options for **RelativeTimeFormat** objects.|
**Example**
```
```js
var relativetimefmt= new Intl.RelativeTimeFormat("en-GB");
relativetimefmt.resolvedOptions();
```
## RelativeTimeFormatInputOptions<sup>8+</sup><a name=relativetimeformatinputoptions></a>
## RelativeTimeFormatInputOptions<sup>8+</sup>
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**.|
## RelativeTimeFormatResolvedOptions<sup>8+</sup><a name=relativetimeformatresolvedoptions></a>
## RelativeTimeFormatResolvedOptions<sup>8+</sup>
Represents the properties of a **RelativeTimeFormat** object.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册