> - 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 contains enhanced i18n APIs, which are not defined in ECMA 402.
> - This module contains enhanced i18n APIs, which are not defined in ECMA 402.
...
@@ -28,7 +28,7 @@ Obtains the localized script for the specified language.
...
@@ -28,7 +28,7 @@ Obtains the localized script for the specified language.
| 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 language.|
| string | Localized script for the specified language.|
...
@@ -55,7 +55,7 @@ Obtains the localized script for the specified country.
...
@@ -55,7 +55,7 @@ Obtains the localized script for the 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.|
...
@@ -80,7 +80,7 @@ Checks whether the localized script for the specified language is displayed from
...
@@ -80,7 +80,7 @@ Checks whether the localized script for the specified language is displayed from
| boolean | Returns **true** if the system language matches the specified region; returns **false** otherwise.|
| boolean | Returns **true** if the system language matches the specified region; returns **false** otherwise.|
...
@@ -309,7 +321,7 @@ Obtains a **Calendar** object.
...
@@ -309,7 +321,7 @@ Obtains a **Calendar** object.
| locale | string | Yes | Valid locale value, for example, **zh-Hans-CN**. |
| 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.|
| 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**
**Return value**
| Type | Description |
| Type | Description |
| ---------------------- | ----- |
| ---------------------- | ----- |
| [Calendar](#calendar8) | **Calendar** object.|
| [Calendar](#calendar8) | **Calendar** object.|
...
@@ -338,7 +350,7 @@ Sets the date for this **Calendar** object.
...
@@ -338,7 +350,7 @@ Sets the date for this **Calendar** object.
**Example**
**Example**
```
```
var calendar = I18n.getCalendar("en-US", "gregory");
var calendar = i18n.getCalendar("en-US", "gregory");
var date = new Date(2021, 10, 7, 8, 0, 0, 0);
var date = new Date(2021, 10, 7, 8, 0, 0, 0);
calendar.setTime(date);
calendar.setTime(date);
```
```
...
@@ -359,7 +371,7 @@ Sets the date and time for this **Calendar** object. The value is represented by
...
@@ -359,7 +371,7 @@ Sets the date and time for this **Calendar** object. The value is represented by
**Example**
**Example**
```
```
var calendar = I18n.getCalendar("en-US", "gregory");
var calendar = i18n.getCalendar("en-US", "gregory");
calendar.setTime(10540800000);
calendar.setTime(10540800000);
```
```
...
@@ -385,7 +397,7 @@ Sets the year, month, day, hour, minute, and second for this **Calendar** object
...
@@ -385,7 +397,7 @@ Sets the year, month, day, hour, minute, and second for this **Calendar** object
**Example**
**Example**
```
```
var calendar = i18n.getCalendar("zh-Hans");
var calendar = i18n.getCalendar("zh-Hans");
calendar.setTime(2021, 10, 1, 8, 0, 0); // set time to 2021.10.1 08:00:00
calendar.set(2021, 10, 1, 8, 0, 0); // set time to 2021.10.1 08:00:00
```
```
...
@@ -417,7 +429,7 @@ Obtains the time zone of this **Calendar** object.
...
@@ -417,7 +429,7 @@ Obtains the time zone of this **Calendar** object.
| field | string | Yes | Value of the specified field in the **Calendar** object. Currently, a valid field can be any of the following: **era**, **year**, **month**, **week\_of\_year**, **week\_of\_month**, **date**, **day\_of\_year**, **day\_of\_week**, **day\_of\_week\_in\_month**, **hour**, **hour\_of\_day**, **minute**, **second**, **millisecond**, **zone\_offset**, **dst\_offset**, **year\_woy**, **dow\_local**, **extended\_year**, **julian\_day**, **milliseconds\_in\_day**, **is\_leap\_month**.|
| field | string | Yes | Value of the specified field in the **Calendar** object. Currently, a valid field can be any of the following: **era**, **year**, **month**, **week\_of\_year**, **week\_of\_month**, **date**, **day\_of\_year**, **day\_of\_week**, **day\_of\_week\_in\_month**, **hour**, **hour\_of\_day**, **minute**, **second**, **millisecond**, **zone\_offset**, **dst\_offset**, **year\_woy**, **dow\_local**, **extended\_year**, **julian\_day**, **milliseconds\_in\_day**, **is\_leap\_month**.|
| number | Value of the specified field. For example, if the year in the internal date of this **Calendar** object is **1990**, the **get("year")** function will return **1990**.|
| number | Value of the specified field. For example, if the year in the internal date of this **Calendar** object is **1990**, the **get("year")** function will return **1990**.|
...
@@ -531,7 +543,7 @@ Obtains the value of the specified field in the **Calendar** object.
...
@@ -531,7 +543,7 @@ Obtains the value of the specified field in the **Calendar** object.
**Example**
**Example**
```
```
var calendar = i18n.getCalendar("zh-Hans");
var calendar = i18n.getCalendar("zh-Hans");
calendar.setTime(2021, 10, 1, 8, 0, 0); // set time to 2021.10.1 08:00:00
calendar.set(2021, 10, 1, 8, 0, 0); // set time to 2021.10.1 08:00:00
calendar.get("hour_of_day"); // 8
calendar.get("hour_of_day"); // 8
```
```
...
@@ -549,7 +561,7 @@ Obtains the name of the **Calendar** object displayed for the specified locale.
...
@@ -549,7 +561,7 @@ Obtains the name of the **Calendar** object displayed for the specified locale.
| locale | string | Yes | Locale for which the name of the **Calendar** object is displayed. For example, if **locale** is **en-US**, the name of the Buddhist calendar will be **Buddhist Calendar**.|
| locale | string | Yes | Locale for which the name of the **Calendar** object is displayed. For example, if **locale** is **en-US**, the name of the Buddhist calendar will be **Buddhist Calendar**.|
**Return Value**
**Return value**
| Type | Description |
| Type | Description |
| ------ | ------------------- |
| ------ | ------------------- |
| string | Name of the **Calendar** object displayed for the specified locale.|
| string | Name of the **Calendar** object displayed for the specified locale.|
...
@@ -574,7 +586,7 @@ Checks whether the specified date in this **Calendar** object is a weekend.
...
@@ -574,7 +586,7 @@ Checks whether the specified date in this **Calendar** object is a weekend.
| date | Date | No | Specified date in this **Calendar** object. If this parameter is left unspecified, the system checks whether the current date in the **Calendar** object is a weekend.|
| date | Date | No | Specified date in this **Calendar** object. If this parameter is left unspecified, the system checks whether the current date in the **Calendar** object is a weekend.|
**Return Value**
**Return value**
| Type | Description |
| Type | Description |
| ------- | ----------------------------------- |
| ------- | ----------------------------------- |
| boolean | Returns **true** if the date is a weekend; returns **false** if the date is a weekday.|
| boolean | Returns **true** if the date is a weekend; returns **false** if the date is a weekday.|
...
@@ -582,7 +594,7 @@ Checks whether the specified date in this **Calendar** object is a weekend.
...
@@ -582,7 +594,7 @@ Checks whether the specified date in this **Calendar** object is a weekend.
**Example**
**Example**
```
```
var calendar = i18n.getCalendar("zh-Hans");
var calendar = i18n.getCalendar("zh-Hans");
calendar.setTime(2021, 11, 11, 8, 0, 0); // set time to 2021.11.11 08:00:00
calendar.set(2021, 11, 11, 8, 0, 0); // set time to 2021.11.11 08:00:00
calendar.isWeekend(); // false
calendar.isWeekend(); // false
var date = new Date(2011, 11, 6, 9, 0, 0);
var date = new Date(2011, 11, 6, 9, 0, 0);
calendar.isWeekend(date); // true
calendar.isWeekend(date); // true
...
@@ -625,7 +637,7 @@ Checks whether the format of the specified phone number is valid.
...
@@ -625,7 +637,7 @@ Checks whether the format of the specified phone number is valid.
| ------ | ------ | ---- | --------- |
| ------ | ------ | ---- | --------- |
| number | string | Yes | Phone number to be checked.|
| number | string | Yes | Phone number to be checked.|
| type | string | Yes | Yes | Format type of a phone number. The value can be **E164**, **INTERNATIONAL**, **NATIONAL**, or **RFC3966**.|
| type | string | Yes | Yes | Format type of a phone number. The available options are as follows: E164, INTERNATIONAL, NATIONAL, and RFC3966.|
## UnitInfo<sup>8+</sup>
## UnitInfo<sup>8+</sup>
...
@@ -682,7 +694,7 @@ Defines the measurement unit information.
...
@@ -682,7 +694,7 @@ Defines the measurement unit information.
| Name | Type | Readable | Writable | Description |
| Name | Type | Readable | Writable | Description |
| locale | string | Yes | Valid locale value, for example, **zh-Hans-CN**. The [BreakIterator](#breakiterator8) object segments text according to the rules of the specified locale.|
| locale | string | Yes | Valid locale value, for example, **zh-Hans-CN**. The [BreakIterator](#breakiterator8) object segments text according to the rules of the specified locale.|
| index | number | No | Number of text boundaries by which the [BreakIterator](#breakiterator8) object is moved. A positive value indicates that the text boundary is moved backward, and a negative value indicates the opposite. If no index is specified, the index will be treated as **1**.|
| index | number | No | Number of text boundaries by which the [BreakIterator](#breakiterator8) object is moved. A positive value indicates that the text boundary is moved backward, and a negative value indicates the opposite. If no index is specified, the index will be treated as **1**.|
| number | Position of the [BreakIterator](#breakiterator8) object in the text after it is moved by the specified number of text boundaries. The value **-1** is returned if the position of the [BreakIterator](#breakiterator8) object is outside of the processed text after it is moved by the specified number of text boundaries.|
| number | Position of the [BreakIterator](#breakiterator8) object in the text after it is moved by the specified number of text boundaries. The value **-1** is returned if the position of the [BreakIterator](#breakiterator8) object is outside of the processed text after it is moved by the specified number of text boundaries.|
**Example**
**Example**
```
```
iterator = I18n.getLineInstance("en");
var iterator = i18n.getLineInstance("en");
iterator.setLineBreakText("Apple is my favorite fruit.");
iterator.setLineBreakText("Apple is my favorite fruit.");
iterator.first(); // 0
iterator.first(); // 0
iterator.next(); // 6
iterator.next(); // 6
...
@@ -1194,14 +1206,14 @@ Moves the [BreakIterator](#breakiterator8) object to the previous text boundary.
...
@@ -1194,14 +1206,14 @@ Moves the [BreakIterator](#breakiterator8) object to the previous text boundary.
| number | Position of the [BreakIterator](#breakiterator8) object in the text after it is moved to the previous text boundary. The value **-1** is returned if the position of the [BreakIterator](#breakiterator8) object is outside of the processed text after it is moved by the specified number of text boundaries.|
| number | Position of the [BreakIterator](#breakiterator8) object in the text after it is moved to the previous text boundary. The value **-1** is returned if the position of the [BreakIterator](#breakiterator8) object is outside of the processed text after it is moved by the specified number of text boundaries.|
**Example**
**Example**
```
```
iterator = I18n.getLineInstance("en");
var iterator = i18n.getLineInstance("en");
iterator.setLineBreakText("Apple is my favorite fruit.");
iterator.setLineBreakText("Apple is my favorite fruit.");
iterator.first(); // 0
iterator.first(); // 0
iterator.next(3); // 12
iterator.next(3); // 12
...
@@ -1222,14 +1234,14 @@ Moves the [BreakIterator](#breakiterator8) object to the text boundary after the
...
@@ -1222,14 +1234,14 @@ Moves the [BreakIterator](#breakiterator8) object to the text boundary after the
| number | The value **-1** is returned if the text boundary to which the [BreakIterator](#breakiterator8) object is moved is outside of the processed text.|
| number | The value **-1** is returned if the text boundary to which the [BreakIterator](#breakiterator8) object is moved is outside of the processed text.|
**Example**
**Example**
```
```
iterator = I18n.getLineInstance("en");
var iterator = i18n.getLineInstance("en");
iterator.setLineBreakText("Apple is my favorite fruit.");
iterator.setLineBreakText("Apple is my favorite fruit.");
iterator.following(0); // 6
iterator.following(0); // 6
iterator.following(100); // -1
iterator.following(100); // -1
...
@@ -1250,14 +1262,14 @@ Checks whether the position specified by the offset is a text boundary. If **tru
...
@@ -1250,14 +1262,14 @@ Checks whether the position specified by the offset is a text boundary. If **tru
| ------ | ------ | ---- | ----------- |
| ------ | ------ | ---- | ----------- |
| offset | number | Yes | Position to check.|
| offset | number | Yes | Position to check.|
**Return Value**
**Return value**
| Type | Description |
| Type | Description |
| ------- | ------------------------------- |
| ------- | ------------------------------- |
| boolean | Returns **true** if the position specified by the offset is a text boundary; returns **false** otherwise.|
| boolean | Returns **true** if the position specified by the offset is a text boundary; returns **false** otherwise.|
**Example**
**Example**
```
```
iterator = I18n.getLineInstance("en");
var iterator = i18n.getLineInstance("en");
iterator.setLineBreakText("Apple is my favorite fruit.");
iterator.setLineBreakText("Apple is my favorite fruit.");
iterator.isBoundary(0); // true;
iterator.isBoundary(0); // true;
iterator.isBoundary(5); // false;
iterator.isBoundary(5); // false;
...
@@ -1272,7 +1284,7 @@ Checks whether the 24-hour clock is used.
...
@@ -1272,7 +1284,7 @@ Checks whether the 24-hour clock 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.|
| 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**
**Return value**
| Type | Description |
| Type | Description |
| ------- | ----------------------------- |
| ------- | ----------------------------- |
| boolean | Returns **true** if the 24-hour clock is enabled; returns **false** otherwise.|
| boolean | Returns **true** if the 24-hour clock is enabled; returns **false** otherwise.|