@@ -28,7 +28,7 @@ You can use APIs provided in the following table to obtain the system language a
...
@@ -28,7 +28,7 @@ You can use APIs provided in the following table to obtain the system language a
```js
```js
var language = i18n.getSystemLanguage();
let language = i18n.getSystemLanguage();
```
```
2. Obtain the system region.
2. Obtain the system region.
...
@@ -36,7 +36,7 @@ You can use APIs provided in the following table to obtain the system language a
...
@@ -36,7 +36,7 @@ You can use APIs provided in the following table to obtain the system language a
Call the **getSystemRegion** method to obtain the system region.
Call the **getSystemRegion** method to obtain the system region.
```js
```js
var region = i18n.getSystemRegion();
let region = i18n.getSystemRegion();
```
```
3. Obtain the system locale.
3. Obtain the system locale.
...
@@ -44,7 +44,7 @@ You can use APIs provided in the following table to obtain the system language a
...
@@ -44,7 +44,7 @@ You can use APIs provided in the following table to obtain the system language a
Call the **getSystemLocale** method to obtain the system locale.
Call the **getSystemLocale** method to obtain the system locale.
```js
```js
var locale = i18n.getSystemLocale();
let locale = i18n.getSystemLocale();
```
```
4. Check whether the locale's language is RTL.
4. Check whether the locale's language is RTL.
...
@@ -53,7 +53,7 @@ You can use APIs provided in the following table to obtain the system language a
...
@@ -53,7 +53,7 @@ You can use APIs provided in the following table to obtain the system language a
```js
```js
var rtl = i18n.isRTL("zh-CN");
let rtl = i18n.isRTL("zh-CN");
```
```
5. Check whether the system uses a 24-hour clock.
5. Check whether the system uses a 24-hour clock.
...
@@ -61,7 +61,7 @@ You can use APIs provided in the following table to obtain the system language a
...
@@ -61,7 +61,7 @@ You can use APIs provided in the following table to obtain the system language a
Call the **is24HourClock** method to check whether the system uses a 24-hour clock.
Call the **is24HourClock** method to check whether the system uses a 24-hour clock.
```js
```js
var hourClock = i18n.is24HourClock();
let hourClock = i18n.is24HourClock();
```
```
6. Obtain the localized display of a language.
6. Obtain the localized display of a language.
...
@@ -69,10 +69,10 @@ You can use APIs provided in the following table to obtain the system language a
...
@@ -69,10 +69,10 @@ You can use APIs provided in the following table to obtain the system language a
Call the **getDisplayLanguage** method to obtain the localized display of a language. **language** indicates the language to be localized, **locale** indicates the locale, and **sentenceCase** indicates whether the first letter of the result must be capitalized.
Call the **getDisplayLanguage** method to obtain the localized display of a language. **language** indicates the language to be localized, **locale** indicates the locale, and **sentenceCase** indicates whether the first letter of the result must be capitalized.
```js
```js
var language = "en";
let language = "en";
var locale = "zh-CN";
let locale = "zh-CN";
var sentenceCase = false;
let sentenceCase = false;
var localizedLanguage = i18n.getDisplayLanguage(language, locale, sentenceCase);
let localizedLanguage = i18n.getDisplayLanguage(language, locale, sentenceCase);
```
```
7. Obtain the localized display of a country.
7. Obtain the localized display of a country.
...
@@ -80,10 +80,10 @@ You can use APIs provided in the following table to obtain the system language a
...
@@ -80,10 +80,10 @@ You can use APIs provided in the following table to obtain the system language a
Call the **getDisplayCountry** method to obtain the localized display of a country name. **country** indicates the country code (a two-letter code in compliance with ISO-3166, for example, CN), **locale** indicates the locale, and **sentenceCase** indicates whether the first letter of the result must be capitalized.
Call the **getDisplayCountry** method to obtain the localized display of a country name. **country** indicates the country code (a two-letter code in compliance with ISO-3166, for example, CN), **locale** indicates the locale, and **sentenceCase** indicates whether the first letter of the result must be capitalized.
```js
```js
var country = "US";
let country = "US";
var locale = "zh-CN";
let locale = "zh-CN";
var sentenceCase = false;
let sentenceCase = false;
var localizedCountry = i18n.getDisplayCountry(country, locale, sentenceCase);
let localizedCountry = i18n.getDisplayCountry(country, locale, sentenceCase);
```
```
...
@@ -118,7 +118,7 @@ You can use APIs provided in the following table to obtain the system language a
...
@@ -118,7 +118,7 @@ You can use APIs provided in the following table to obtain the system language a
```js
```js
var calendar = i18n.getCalendar("zh-CN", "gregory");
let calendar = i18n.getCalendar("zh-CN", "gregory");
```
```
2. Set the time for the **Calendar** object.
2. Set the time for the **Calendar** object.
...
@@ -126,9 +126,9 @@ You can use APIs provided in the following table to obtain the system language a
...
@@ -126,9 +126,9 @@ You can use APIs provided in the following table to obtain the system language a
Call the **setTime** method to set the time of the **Calendar** object. This method receives two types of parameters. One is a **Date** object, and the other is a value indicating the number of milliseconds elapsed since January 1, 1970, 00:00:00 GMT.
Call the **setTime** method to set the time of the **Calendar** object. This method receives two types of parameters. One is a **Date** object, and the other is a value indicating the number of milliseconds elapsed since January 1, 1970, 00:00:00 GMT.
```js
```js
var date1 = new Date();
let date1 = new Date();
calendar.setTime(date1);
calendar.setTime(date1);
var date2 = 1000;
let date2 = 1000;
calendar.setTime(date2);
calendar.setTime(date2);
```
```
...
@@ -147,7 +147,7 @@ You can use APIs provided in the following table to obtain the system language a
...
@@ -147,7 +147,7 @@ You can use APIs provided in the following table to obtain the system language a
```js
```js
calendar.setTimeZone("Asia/Shanghai");
calendar.setTimeZone("Asia/Shanghai");
var timezone = calendar.getTimeZone();
let timezone = calendar.getTimeZone();
```
```
5. Set and obtain the first day of a week for the **Calendar** object.
5. Set and obtain the first day of a week for the **Calendar** object.
...
@@ -157,7 +157,7 @@ You can use APIs provided in the following table to obtain the system language a
...
@@ -157,7 +157,7 @@ You can use APIs provided in the following table to obtain the system language a
```js
```js
calendar.setFirstDayOfWeek(1);
calendar.setFirstDayOfWeek(1);
var firstDayOfWeek = calendar.getFirstDayOfWeek();
let firstDayOfWeek = calendar.getFirstDayOfWeek();
```
```
6. Set and obtain the minimum count of days in the first week for the **Calendar** object.
6. Set and obtain the minimum count of days in the first week for the **Calendar** object.
...
@@ -166,7 +166,7 @@ You can use APIs provided in the following table to obtain the system language a
...
@@ -166,7 +166,7 @@ You can use APIs provided in the following table to obtain the system language a
```js
```js
calendar.setMinimalDaysInFirstWeek(3);
calendar.setMinimalDaysInFirstWeek(3);
var minimalDaysInFirstWeek = calendar.getMinimalDaysInFirstWeek();
let minimalDaysInFirstWeek = calendar.getMinimalDaysInFirstWeek();
```
```
7. Obtain the localized display of the **Calendar** object.
7. Obtain the localized display of the **Calendar** object.
...
@@ -175,7 +175,7 @@ You can use APIs provided in the following table to obtain the system language a
...
@@ -175,7 +175,7 @@ You can use APIs provided in the following table to obtain the system language a
```js
```js
var localizedName = calendar.getDisplayName("zh-CN");
let localizedName = calendar.getDisplayName("zh-CN");
```
```
8. Check whether a date is a weekend.
8. Check whether a date is a weekend.
...
@@ -184,8 +184,8 @@ You can use APIs provided in the following table to obtain the system language a
...
@@ -184,8 +184,8 @@ You can use APIs provided in the following table to obtain the system language a
```js
```js
vardate=newDate();
letdate=newDate();
varweekend=calendar.isWeekend(date);
letweekend=calendar.isWeekend(date);
```
```
...
@@ -211,21 +211,21 @@ You can use APIs provided in the following table to obtain the system language a
...
@@ -211,21 +211,21 @@ You can use APIs provided in the following table to obtain the system language a
```js
```js
var phoneNumberFormat = new i18n.PhoneNumberFormat("CN", {type: "E164"});
let phoneNumberFormat = new i18n.PhoneNumberFormat("CN", {type: "E164"});
```
```
2. Check whether the phone number format is correct.
2. Check whether the phone number format is correct.
Call the **isValidNumber** method to check whether the format of the input phone number is correct.
Call the **isValidNumber** method to check whether the format of the input phone number is correct.
```js
```js
var validNumber = phoneNumberFormat.isValidNumber("15812341234");
let validNumber = phoneNumberFormat.isValidNumber("15812341234");
```
```
3. Format a phone number.
3. Format a phone number.
Call the **format** method of **PhoneNumberFormat** to format the input phone number.
Call the **format** method of **PhoneNumberFormat** to format the input phone number.
@@ -280,7 +280,7 @@ The **unitConvert** API is provided to help you implement measurement conversion
...
@@ -280,7 +280,7 @@ The **unitConvert** API is provided to help you implement measurement conversion
```js
```js
var indexUtil = i18n.getInstance("zh-CN");
let indexUtil = i18n.getInstance("zh-CN");
```
```
2. Obtain the index list.
2. Obtain the index list.
...
@@ -288,7 +288,7 @@ The **unitConvert** API is provided to help you implement measurement conversion
...
@@ -288,7 +288,7 @@ The **unitConvert** API is provided to help you implement measurement conversion
Call the **getIndexList** method to obtain the alphabet index list of the current locale.
Call the **getIndexList** method to obtain the alphabet index list of the current locale.
```js
```js
var indexList = indexUtil.getIndexList();
let indexList = indexUtil.getIndexList();
```
```
3. Add an index.
3. Add an index.
...
@@ -304,7 +304,7 @@ The **unitConvert** API is provided to help you implement measurement conversion
...
@@ -304,7 +304,7 @@ The **unitConvert** API is provided to help you implement measurement conversion
Call the **getIndex** method to obtain the alphabet index of a string.
Call the **getIndex** method to obtain the alphabet index of a string.
```js
```js
var text = "access index";
let text = "access index";
indexUtil.getIndex(text);
indexUtil.getIndex(text);
```
```
...
@@ -338,8 +338,8 @@ When a text is displayed in more than one line, [BreakIterator8](../reference/ap
...
@@ -338,8 +338,8 @@ When a text is displayed in more than one line, [BreakIterator8](../reference/ap
```js
```js
var locale = "en-US"
let locale = "en-US"
var breakIterator = i18n.getLineInstance(locale);
let breakIterator = i18n.getLineInstance(locale);
```
```
2. Set and access the text that requires line breaking.
2. Set and access the text that requires line breaking.
...
@@ -348,9 +348,9 @@ When a text is displayed in more than one line, [BreakIterator8](../reference/ap
...
@@ -348,9 +348,9 @@ When a text is displayed in more than one line, [BreakIterator8](../reference/ap
```js
```js
var text = "Apple is my favorite fruit";
let text = "Apple is my favorite fruit";
breakIterator.setLineBreakText(text);
breakIterator.setLineBreakText(text);
var breakText = breakIterator.getLineBreakText();
let breakText = breakIterator.getLineBreakText();
```
```
3. Obtain the current position of the **BreakIterator** object.
3. Obtain the current position of the **BreakIterator** object.
...
@@ -359,7 +359,7 @@ When a text is displayed in more than one line, [BreakIterator8](../reference/ap
...
@@ -359,7 +359,7 @@ When a text is displayed in more than one line, [BreakIterator8](../reference/ap
```js
```js
var pos = breakIterator.current();
let pos = breakIterator.current();
```
```
4. Set the position of a **BreakIterator** object.
4. Set the position of a **BreakIterator** object.
...
@@ -368,15 +368,15 @@ When a text is displayed in more than one line, [BreakIterator8](../reference/ap
...
@@ -368,15 +368,15 @@ When a text is displayed in more than one line, [BreakIterator8](../reference/ap
```js
```js
var firstPos = breakIterator.first(); // Set a BreakIterator object to the first break point, that is, the start position of the text.
let firstPos = breakIterator.first(); // Set a BreakIterator object to the first break point, that is, the start position of the text.
var lastPos = breakIterator.last(); // Set a BreakIterator object to the last break point, that is, the position after the text end.
let lastPos = breakIterator.last(); // Set a BreakIterator object to the last break point, that is, the position after the text end.
// Move a BreakIterator object forward or backward by a certain number of break points.
// Move a BreakIterator object forward or backward by a certain number of break points.
// If a positive number is input, move backward. If a negative number is input, move forward. If no value is input, move one position backward.
// If a positive number is input, move backward. If a negative number is input, move forward. If no value is input, move one position backward.
// When the object is moved out of the text length range, -1 is returned.
// When the object is moved out of the text length range, -1 is returned.
var nextPos = breakIterator.next(-2);
let nextPos = breakIterator.next(-2);
var previousPos = breakIterator.previous(); // Move a BreakIterator object to the previous break point. When the text length is out of the range, -1 is returned.
let previousPos = breakIterator.previous(); // Move a BreakIterator object to the previous break point. When the text length is out of the range, -1 is returned.
// Move a BreakIterator object to the break point following the position specified by offset. If the object is moved out of the text length range, -1 is returned.
// Move a BreakIterator object to the break point following the position specified by offset. If the object is moved out of the text length range, -1 is returned.
var followingPos = breakIterator.following(10);
let followingPos = breakIterator.following(10);
```
```
5. Determine whether a position is a break point.
5. Determine whether a position is a break point.
...
@@ -385,7 +385,7 @@ When a text is displayed in more than one line, [BreakIterator8](../reference/ap
...
@@ -385,7 +385,7 @@ When a text is displayed in more than one line, [BreakIterator8](../reference/ap
2. Obtain the string representing a **Locale** object.
2. Obtain the string representing a **Locale** object.
...
@@ -54,7 +54,7 @@ Use [Locale](../reference/apis/js-apis-intl.md#locale) APIs to maximize or minim
...
@@ -54,7 +54,7 @@ Use [Locale](../reference/apis/js-apis-intl.md#locale) APIs to maximize or minim
Call the **toString** method to obtain the string representing a **Locale** object, which includes the language, region, and other options.
Call the **toString** method to obtain the string representing a **Locale** object, which includes the language, region, and other options.
```js
```js
varlocaleStr=localeObj.toString();
letlocaleStr=localeObj.toString();
```
```
3. Maximize locale information.
3. Maximize locale information.
...
@@ -62,7 +62,7 @@ Use [Locale](../reference/apis/js-apis-intl.md#locale) APIs to maximize or minim
...
@@ -62,7 +62,7 @@ Use [Locale](../reference/apis/js-apis-intl.md#locale) APIs to maximize or minim
Call the **maximize** method to maximize locale information; that is, supplement the missing script and region information.
Call the **maximize** method to maximize locale information; that is, supplement the missing script and region information.
```js
```js
varmaximizedLocale=localeObj.maximize();
letmaximizedLocale=localeObj.maximize();
```
```
4. Minimize locale information.
4. Minimize locale information.
...
@@ -70,7 +70,7 @@ Use [Locale](../reference/apis/js-apis-intl.md#locale) APIs to maximize or minim
...
@@ -70,7 +70,7 @@ Use [Locale](../reference/apis/js-apis-intl.md#locale) APIs to maximize or minim
Call the **minimize** method to minimize locale information; that is, delete the unnecessary script and region information.
Call the **minimize** method to minimize locale information; that is, delete the unnecessary script and region information.
```js
```js
varminimizedLocale=localeObj.minimize();
letminimizedLocale=localeObj.minimize();
```
```
...
@@ -98,14 +98,14 @@ Use [DateTimeFormat](../reference/apis/js-apis-intl.md#datetimeformat) APIs to f
...
@@ -98,14 +98,14 @@ Use [DateTimeFormat](../reference/apis/js-apis-intl.md#datetimeformat) APIs to f
```js
```js
vardateTimeFormat=newintl.DateTimeFormat();
letdateTimeFormat=newintl.DateTimeFormat();
```
```
Alternatively, use your own locale and formatting parameters to create a **DateTimeFormat** object. Formatting parameters are optional. For a full list of formatting parameters, see [DateTimeOptions](../reference/apis/js-apis-intl.md#datetimeoptions).
Alternatively, use your own locale and formatting parameters to create a **DateTimeFormat** object. Formatting parameters are optional. For a full list of formatting parameters, see [DateTimeOptions](../reference/apis/js-apis-intl.md#datetimeoptions).
@@ -113,8 +113,8 @@ Use [DateTimeFormat](../reference/apis/js-apis-intl.md#datetimeformat) APIs to f
...
@@ -113,8 +113,8 @@ Use [DateTimeFormat](../reference/apis/js-apis-intl.md#datetimeformat) APIs to f
Call the **format** method to format the date and time in the **DateTimeFormat** object. This method returns a string representing the formatting result.
Call the **format** method to format the date and time in the **DateTimeFormat** object. This method returns a string representing the formatting result.
```js
```js
vardate=newDate();
letdate=newDate();
varformatResult=dateTimeFormat.format(date);
letformatResult=dateTimeFormat.format(date);
```
```
3. Format a period.
3. Format a period.
...
@@ -122,9 +122,9 @@ Use [DateTimeFormat](../reference/apis/js-apis-intl.md#datetimeformat) APIs to f
...
@@ -122,9 +122,9 @@ Use [DateTimeFormat](../reference/apis/js-apis-intl.md#datetimeformat) APIs to f
Call the **formatRange** method to format the period in the **DateTimeFormat** object. This method requires input of two **Date** objects, which respectively indicate the start date and end date of a period. This method returns a string representing the formatting result.
Call the **formatRange** method to format the period in the **DateTimeFormat** object. This method requires input of two **Date** objects, which respectively indicate the start date and end date of a period. This method returns a string representing the formatting result.
```js
```js
varstartDate=newDate(2021,11,17,3,24,0);
letstartDate=newDate(2021,11,17,3,24,0);
varendDate=newDate(2021,11,18,3,24,0);
letendDate=newDate(2021,11,18,3,24,0);
vardatefmt=newIntl.DateTimeFormat("en-GB");
letdatefmt=newIntl.DateTimeFormat("en-GB");
datefmt.formatRange(startDate,endDate);
datefmt.formatRange(startDate,endDate);
```
```
...
@@ -133,7 +133,7 @@ Use [DateTimeFormat](../reference/apis/js-apis-intl.md#datetimeformat) APIs to f
...
@@ -133,7 +133,7 @@ Use [DateTimeFormat](../reference/apis/js-apis-intl.md#datetimeformat) APIs to f
Call the **resolvedOptions** method to obtain attributes of the **DateTimeFormat** object. This method will return an array that contains all attributes and values of the object.
Call the **resolvedOptions** method to obtain attributes of the **DateTimeFormat** object. This method will return an array that contains all attributes and values of the object.
```js
```js
varoptions=dateTimeFormat.resolvedOptions();
letoptions=dateTimeFormat.resolvedOptions();
```
```
...
@@ -160,14 +160,14 @@ Use [NumberFormat](../reference/apis/js-apis-intl.md#numberformat) APIs to forma
...
@@ -160,14 +160,14 @@ Use [NumberFormat](../reference/apis/js-apis-intl.md#numberformat) APIs to forma
```js
```js
varnumberFormat=newintl.NumberFormat();
letnumberFormat=newintl.NumberFormat();
```
```
Alternatively, use your own locale and formatting parameters to create a **NumberFormat** object. Formatting parameters are optional. For a full list of formatting parameters, see [NumberOptions](../reference/apis/js-apis-intl.md#numberoptions).
Alternatively, use your own locale and formatting parameters to create a **NumberFormat** object. Formatting parameters are optional. For a full list of formatting parameters, see [NumberOptions](../reference/apis/js-apis-intl.md#numberoptions).
@@ -175,8 +175,8 @@ Use [NumberFormat](../reference/apis/js-apis-intl.md#numberformat) APIs to forma
...
@@ -175,8 +175,8 @@ Use [NumberFormat](../reference/apis/js-apis-intl.md#numberformat) APIs to forma
Call the **format** method to format a number. A string is returned as the formatting result.
Call the **format** method to format a number. A string is returned as the formatting result.
```js
```js
varnumber=1234.5678
letnumber=1234.5678
varformatResult=numberFormat.format(number);
letformatResult=numberFormat.format(number);
```
```
3. Obtain attributes of the **NumberFormat** object.
3. Obtain attributes of the **NumberFormat** object.
...
@@ -184,7 +184,7 @@ Use [NumberFormat](../reference/apis/js-apis-intl.md#numberformat) APIs to forma
...
@@ -184,7 +184,7 @@ Use [NumberFormat](../reference/apis/js-apis-intl.md#numberformat) APIs to forma
Call the **resolvedOptions** method to obtain attributes of the **NumberFormat** object. This method will return an array that contains all attributes and values of the object.
Call the **resolvedOptions** method to obtain attributes of the **NumberFormat** object. This method will return an array that contains all attributes and values of the object.
```js
```js
varoptions=numberFormat.resolvedOptions();
letoptions=numberFormat.resolvedOptions();
```
```
...
@@ -211,13 +211,13 @@ Use [Collator](../reference/apis/js-apis-intl.md#collator8) APIs to sort strings
...
@@ -211,13 +211,13 @@ Use [Collator](../reference/apis/js-apis-intl.md#collator8) APIs to sort strings
```js
```js
varcollator=newintl.Collator();
letcollator=newintl.Collator();
```
```
Alternatively, use your own locale and formatting parameters to create a **Collator** object. For a full list of parameters, see [CollatorOptions](../reference/apis/js-apis-intl.md#collatoroptions9).
Alternatively, use your own locale and formatting parameters to create a **Collator** object. For a full list of parameters, see [CollatorOptions](../reference/apis/js-apis-intl.md#collatoroptions9).
@@ -225,9 +225,9 @@ Use [Collator](../reference/apis/js-apis-intl.md#collator8) APIs to sort strings
...
@@ -225,9 +225,9 @@ Use [Collator](../reference/apis/js-apis-intl.md#collator8) APIs to sort strings
Call the **compare** method to compare two input strings. This method returns a value as the comparison result. The return value **-1** indicates that the first string is shorter than the second string, the return value **1** indicates that the first string is longer than the second string, and the return value **0** indicates that the two strings are of equal lengths. This allows you to sort character strings based on the comparison result.
Call the **compare** method to compare two input strings. This method returns a value as the comparison result. The return value **-1** indicates that the first string is shorter than the second string, the return value **1** indicates that the first string is longer than the second string, and the return value **0** indicates that the two strings are of equal lengths. This allows you to sort character strings based on the comparison result.
```js
```js
varstr1="first string";
letstr1="first string";
varstr2="second string";
letstr2="second string";
varcompareResult=collator.compare(str1,str2);
letcompareResult=collator.compare(str1,str2);
```
```
3. Obtain attributes of the **Collator** object.
3. Obtain attributes of the **Collator** object.
...
@@ -235,7 +235,7 @@ Use [Collator](../reference/apis/js-apis-intl.md#collator8) APIs to sort strings
...
@@ -235,7 +235,7 @@ Use [Collator](../reference/apis/js-apis-intl.md#collator8) APIs to sort strings
Call the **resolvedOptions** method to obtain attributes of the **Collator** object. This method will return an array that contains all attributes and values of the object.
Call the **resolvedOptions** method to obtain attributes of the **Collator** object. This method will return an array that contains all attributes and values of the object.
```js
```js
varoptions=collator.resolvedOptions();
letoptions=collator.resolvedOptions();
```
```
...
@@ -261,13 +261,13 @@ Use [PluralRules](../reference/apis/js-apis-intl.md#pluralrules8) APIs to determ
...
@@ -261,13 +261,13 @@ Use [PluralRules](../reference/apis/js-apis-intl.md#pluralrules8) APIs to determ
```js
```js
varpluralRules=newintl.PluralRules();
letpluralRules=newintl.PluralRules();
```
```
Alternatively, use your own locale and formatting parameters to create a **PluralRules** object. For a full list of parameters, see [PluralRulesOptions](../reference/apis/js-apis-intl.md#pluralrulesoptions9).
Alternatively, use your own locale and formatting parameters to create a **PluralRules** object. For a full list of parameters, see [PluralRulesOptions](../reference/apis/js-apis-intl.md#pluralrulesoptions9).
@@ -275,8 +275,8 @@ Use [PluralRules](../reference/apis/js-apis-intl.md#pluralrules8) APIs to determ
...
@@ -275,8 +275,8 @@ Use [PluralRules](../reference/apis/js-apis-intl.md#pluralrules8) APIs to determ
Call the **select** method to determine the singular-plural type of an input number. This method will return a string representing the singular-plural type, which can be any of the following: **zero**, **one**, **two**, **few**, **many**, and **other**.
Call the **select** method to determine the singular-plural type of an input number. This method will return a string representing the singular-plural type, which can be any of the following: **zero**, **one**, **two**, **few**, **many**, and **other**.
```js
```js
varnumber=1234.5678
letnumber=1234.5678
varcategoryResult=plurals.select(number);
letcategoryResult=plurals.select(number);
```
```
...
@@ -304,13 +304,13 @@ Use [RelativeTimeFormat](../reference/apis/js-apis-intl.md#relativetimeformat8)
...
@@ -304,13 +304,13 @@ Use [RelativeTimeFormat](../reference/apis/js-apis-intl.md#relativetimeformat8)
Alternatively, use your own locale and formatting parameters to create a **RelativeTimeFormat** object. Formatting parameters are optional. For a full list of formatting parameters, see [RelativeTimeFormatInputOptions](../reference/apis/js-apis-intl.md#relativetimeformatinputoptions9).
Alternatively, use your own locale and formatting parameters to create a **RelativeTimeFormat** object. Formatting parameters are optional. For a full list of formatting parameters, see [RelativeTimeFormatInputOptions](../reference/apis/js-apis-intl.md#relativetimeformatinputoptions9).
@@ -318,9 +318,9 @@ Use [RelativeTimeFormat](../reference/apis/js-apis-intl.md#relativetimeformat8)
...
@@ -318,9 +318,9 @@ Use [RelativeTimeFormat](../reference/apis/js-apis-intl.md#relativetimeformat8)
Call the **format** method to format the relative time. This method receives a numeric value representing the time length and a string-form unit, like **year**, **quarter**, **month**, **week**, **day**, **hour**, **minute**, and **second**. This method returns a string representing the formatting result.
Call the **format** method to format the relative time. This method receives a numeric value representing the time length and a string-form unit, like **year**, **quarter**, **month**, **week**, **day**, **hour**, **minute**, and **second**. This method returns a string representing the formatting result.
4. Obtain attributes of the **RelativeTimeFormat** object.
4. Obtain attributes of the **RelativeTimeFormat** object.
...
@@ -338,7 +338,7 @@ Use [RelativeTimeFormat](../reference/apis/js-apis-intl.md#relativetimeformat8)
...
@@ -338,7 +338,7 @@ Use [RelativeTimeFormat](../reference/apis/js-apis-intl.md#relativetimeformat8)
Call the **resolvedOptions** method to obtain attributes of the **RelativeTimeFormat** object. This method will return an array that contains all attributes and values of the object. For a full list of attributes, see [RelativeTimeFormatResolvedOptions](../reference/apis/js-apis-intl.md#relativetimeformatresolvedoptions8).
Call the **resolvedOptions** method to obtain attributes of the **RelativeTimeFormat** object. This method will return an array that contains all attributes and values of the object. For a full list of attributes, see [RelativeTimeFormatResolvedOptions](../reference/apis/js-apis-intl.md#relativetimeformatresolvedoptions8).
The I18N 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 **i18n** 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.
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**
> **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
## Modules to Import
```js
```js
importi18nfrom'@ohos.i18n';
importI18nfrom'@ohos.i18n';
```
```
...
@@ -39,16 +42,16 @@ Obtains the localized script for the specified country.
...
@@ -39,16 +42,16 @@ Obtains the localized script for the specified country.
**Error codes**
**Error codes**
For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
letsystemCountries=I18n.System.getSystemCountries('zh');// systemCountries = [ "ZW", "YT", "YE", ..., "ER", "CN", "DE" ], 240 countries or regions in total
| 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.|
| flag | boolean | Yes | Whether to enable the local digit switch. The value **true** means to enable the local digit switch, and the value **false** indicates the opposite.|
**Error codes**
**Error codes**
For details about the error codes, see [I18N Error Codes](../errorcodes/errorcode-i18n.md).
For details about the error codes, see [i18n Error Codes](../errorcodes/errorcode-i18n.md).
| type | string | Yes | Yes | Format type of a phone number. The available options are as follows: E164, INTERNATIONAL, NATIONAL, and RFC3966.|
| type | string | Yes | Yes | Format type of a phone number. The available options are as follows: E164, INTERNATIONAL, NATIONAL, and RFC3966.|
...
@@ -1161,7 +1166,7 @@ Defines the measurement unit information.
...
@@ -1161,7 +1166,7 @@ Defines the measurement unit information.
This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [System.getPreferredLanguageList](#getpreferredlanguagelist9) instead.
This API is supported since API version 8 and is deprecated since API version 9. You are advised to use [System.getPreferredLanguageList](#getpreferredlanguagelist9) instead.
...
@@ -2362,15 +2373,15 @@ This API is supported since API version 8 and is deprecated since API version 9.
...
@@ -2362,15 +2373,15 @@ This API is supported since API version 8 and is deprecated since API version 9.
| Type | Description |
| Type | Description |
| ------------------- | --------- |
| ------------------- | --------- |
| Array<string> | List of preferred languages.|
The Intl 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 **intl** 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 interfaces that are not defined in ECMA 402. It works with the intl module to provide a complete suite of i18n capabilities.
The [I18N](js-apis-i18n.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**
> **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.
> 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 provides basic i18n capabilities, such as time and date formatting, number formatting, and string sorting, through the standard i18n interfaces defined in ECMA 402. For details about the enhanced i18n capabilities, see [i18n](js-apis-i18n.md).
## Modules to Import
## Modules to Import
```
```js
importIntlfrom'@ohos.intl';
importIntlfrom'@ohos.intl';
```
```
Importing an incorrect bundle can lead to unexpected API behavior.
## Locale
## Locale
...
@@ -23,16 +23,16 @@ import Intl from '@ohos.intl';
...
@@ -23,16 +23,16 @@ import Intl from '@ohos.intl';
| language | string | Yes | No | Language associated with the locale, for example, **zh**. |
| language | string | Yes | No | Language associated with the locale, for example, **zh**. |
| script | string | Yes | No | Script type of the language, for example, **Hans**. |
| script | string | Yes | No | Script type of the language, for example, **Hans**. |
| region | string | Yes | No | Region associated with the locale, for example, **CN**. |
| region | string | Yes | No | Region associated with the locale, for example, **CN**. |
| baseName | string | Yes | No | Basic key information about the locale, which consists of the language, script, and region, for example, **zh-Hans-CN**. |
| baseName | string | Yes | No | Basic key information about the locale, which consists of the language, script, and region, for example, **zh-Hans-CN**. |
| caseFirst | string | Yes | No | Whether case is taken into account for the locale's collation rules. The value can be **upper**, **lower**, or **false**.|
| caseFirst | string | Yes | No | Whether case is taken into account for the locale's collation rules. The value can be **upper**, **lower**, or **false**.|
| calendar | string | Yes | No | Calendar for the locale. The value can be any of the following: **buddhist**, **chinese**, **coptic**, **dangi**, **ethioaa**, **ethiopic**, **gregory**, **hebrew**, **indian**, **islamic**, **islamic-umalqura**, **islamic-tbla**, **islamic-civil**, **islamic-rgsa**, **iso8601**, **japanese**, **persian**, **roc**, **islamicc**.|
| calendar | string | Yes | No | Calendar for the locale. The value can be any of the following: **buddhist**, **chinese**, **coptic**, **dangi**, **ethioaa**, **ethiopic**, **gregory**, **hebrew**, **indian**, **islamic**, **islamic-umalqura**, **islamic-tbla**, **islamic-civil**, **islamic-rgsa**, **iso8601**, **japanese**, **persian**, **roc**, or **islamicc**.|
| collation | string | Yes | No | Rule for sorting regions. The value can be any of the following: **big5han**, **compat**, **dict**, **direct**, **ducet**, **eor**, **gb2312**, **phonebk**, **phonetic**, **pinyin**, **reformed**, **searchjl**, **stroke**, **trad**, **unihan**, **zhuyin**.|
| collation | string | Yes | No | Rule for sorting regions. The value can be any of the following: **big5han**, **compat**, **dict**, **direct**, **ducet**, **eor**, **gb2312**, **phonebk**, **phonetic**, **pinyin**, **reformed**, **searchjl**, **stroke**, **trad**, **unihan**, **zhuyin**.|
| hourCycle | string | Yes | No | Time system for the locale. The value can be any of the following: **h12**, **h23**, **h11**, **h24**.|
| hourCycle | string | Yes | No | Time system for the locale. The value can be any of the following: **h12**, **h23**, **h11**, or **h24**.|
| numberingSystem | string | Yes | No | Numbering system for the locale. The value can be any of the following: **adlm**, **ahom**, **arab**, **arabext**, **bali**, **beng**, **bhks**, **brah**, **cakm**, **cham**, **deva**, **diak**, **fullwide**, **gong**, **gonm**, **gujr**, **guru**, **hanidec**, **hmng**, **hmnp**, **java**, **kali**, **khmr**, **knda**, **lana**, **lanatham**, **laoo**, **latn**, **lepc**, **limb**, **mathbold**, **mathdbl**, **mathmono**, **mathsanb**, **mathsans**, **mlym**, **modi**, **mong**, **mroo**, **mtei**, **mymr**, **mymrshan**, **mymrtlng**, **newa**, **nkoo**, **olck**, **orya**, **osma**, **rohg**, **saur**, **segment**, **shrd**, **sind**, **sinh**, **sora**, **sund**, **takr**, **talu**, **tamldec**, **telu**, **thai**, **tibt**, **tirh**, **vaii**, **wara**, **wcho**.|
| numberingSystem | string | Yes | No | Numbering system for the locale. The value can be any of the following: **adlm**, **ahom**, **arab**, **arabext**, **bali**, **beng**, **bhks**, **brah**, **cakm**, **cham**, **deva**, **diak**, **fullwide**, **gong**, **gonm**, **gujr**, **guru**, **hanidec**, **hmng**, **hmnp**, **java**, **kali**, **khmr**, **knda**, **lana**, **lanatham**, **laoo**, **latn**, **lepc**, **limb**, **mathbold**, **mathdbl**, **mathmono**, **mathsanb**, **mathsans**, **mlym**, **modi**, **mong**, **mroo**, **mtei**, **mymr**, **mymrshan**, **mymrtlng**, **newa**, **nkoo**, **olck**, **orya**, **osma**, **rohg**, **saur**, **segment**, **shrd**, **sind**, **sinh**, **sora**, **sund**, **takr**, **talu**, **tamldec**, **telu**, **thai**, **tibt**, **tirh**, **vaii**, **wara**, **wcho**.|
| numeric | boolean | Yes | No | Whether to apply special collation rules for numeric characters. |
| numeric | boolean | Yes | No | Whether to apply special collation rules for numeric characters. |
...
@@ -41,13 +41,16 @@ import Intl from '@ohos.intl';
...
@@ -41,13 +41,16 @@ import Intl from '@ohos.intl';
| locale | string | Yes | A string containing locale information, including the language, optional script, and region.|
| locale | string | Yes | A string containing locale information, including the language, optional script, and region. For details about the international standards and combination modes for the language, script, and country or region, see [intl Development](../../internationalization/intl-guidelines.md#setting-locale-information).|
| options<sup>9+</sup> | [LocaleOptions](#localeoptions9) | No | Options for creating the **Locale** object. |
| options<sup>9+</sup> | [LocaleOptions](#localeoptions6) | No | Options for creating the **Locale** object. |
| calendar | string | Yes | Yes | Calendar for the locale. The value can be any of the following: **buddhist**, **chinese**, **coptic**, **dangi**, **ethioaa**, **ethiopic**, **gregory**, **hebrew**, **indian**, **islamic**, **islamic-umalqura**, **islamic-tbla**, **islamic-civil**, **islamic-rgsa**, **iso8601**, **japanese**, **persian**, **roc**, **islamicc**.|
| calendar | string | Yes | Yes | Calendar for the locale. The value can be any of the following: **buddhist**, **chinese**, **coptic**, **dangi**, **ethioaa**, **ethiopic**, **gregory**, **hebrew**, **indian**, **islamic**, **islamic-umalqura**, **islamic-tbla**, **islamic-civil**, **islamic-rgsa**, **iso8601**, **japanese**, **persian**, **roc**, or **islamicc**.|
| collation | string | Yes | Yes | Collation rule. The value can be any of the following: **big5han**, **compat**, **dict**, **direct**, **ducet**, **emoji**, **eor**, **gb2312**, **phonebk**, **phonetic**, **pinyin**, **reformed**,**search**, **searchjl**, **standard**, **stroke**, **trad**, **unihan**, **zhuyin**.|
| collation | string | Yes | Yes | Collation rule. The value can be any of the following: **big5han**, **compat**, **dict**, **direct**, **ducet**, **emoji**, **eor**, **gb2312**, **phonebk**, **phonetic**, **pinyin**, **reformed**,**search**, **searchjl**, **standard**, **stroke**, **trad**, **unihan**, **zhuyin**.|
| hourCycle | string | Yes | Yes | Time system for the locale. The value can be any of the following: **h11**, **h12**, **h23**, **h24**.|
| hourCycle | string | Yes | Yes | Time system for the locale. The value can be any of the following: **h11**, **h12**, **h23**, or **h24**.|
| numberingSystem | string | Yes | Yes | Numbering system for the locale. The value can be any of the following: **adlm**, **ahom**, **arab**, **arabext**, **bali**, **beng**, **bhks**, **brah**, **cakm**, **cham**, **deva**, **diak**, **fullwide**, **gong**, **gonm**, **gujr**, **guru**, **hanidec**, **hmng**, **hmnp**, **java**, **kali**, **khmr**, **knda**, **lana**, **lanatham**, **laoo**, **latn**, **lepc**, **limb**, **mathbold**, **mathdbl**, **mathmono**, **mathsanb**, **mathsans**, **mlym**, **modi**, **mong**, **mroo**, **mtei**, **mymr**, **mymrshan**, **mymrtlng**, **newa**, **nkoo**, **olck**, **orya**, **osma**, **rohg**, **saur**, **segment**, **shrd**, **sind**, **sinh**, **sora**, **sund**, **takr**, **talu**, **tamldec**, **telu**, **thai**, **tibt**, **tirh**, **vaii**, **wara**, **wcho**.|
| numberingSystem | string | Yes | Yes | Numbering system for the locale. The value can be any of the following: **adlm**, **ahom**, **arab**, **arabext**, **bali**, **beng**, **bhks**, **brah**, **cakm**, **cham**, **deva**, **diak**, **fullwide**, **gong**, **gonm**, **gujr**, **guru**, **hanidec**, **hmng**, **hmnp**, **java**, **kali**, **khmr**, **knda**, **lana**, **lanatham**, **laoo**, **latn**, **lepc**, **limb**, **mathbold**, **mathdbl**, **mathmono**, **mathsanb**, **mathsans**, **mlym**, **modi**, **mong**, **mroo**, **mtei**, **mymr**, **mymrshan**, **mymrtlng**, **newa**, **nkoo**, **olck**, **orya**, **osma**, **rohg**, **saur**, **segment**, **shrd**, **sind**, **sinh**, **sora**, **sund**, **takr**, **talu**, **tamldec**, **telu**, **thai**, **tibt**, **tirh**, **vaii**, **wara**, **wcho**.|
| numeric | boolean | Yes | Yes | Whether to use the 12-hour clock. |
| numeric | boolean | Yes | Yes | Whether to use the 12-hour clock. |
| caseFirst | string | Yes | Yes | Whether upper case or lower case is sorted first. The value can be **upper**, **lower**, or **false**.|
| caseFirst | string | Yes | Yes | Whether upper case or lower case is sorted first. The value can be **upper**, **lower**, or **false**.|
...
@@ -163,8 +187,9 @@ Creates a **DateTimeOptions** object for the specified locale.
...
@@ -163,8 +187,9 @@ Creates a **DateTimeOptions** object for the specified locale.
var datefmt= new Intl.DateTimeFormat(["ban", "zh"], { dateStyle: 'full', timeStyle: 'medium' });
// Use the locale list ["ban", "zh"] to create a DateTimeFormat object. Because ban is an invalid locale ID, locale zh is used to create the DateTimeFormat 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");
// Use locale en-GB to create a Collator object.
collator.compare("first", "second");
letcollator=newIntl.Collator("en-GB");
// Compare the sequence of the first and second strings.
| localeMatcher | string | Yes | Yes | Locale matching algorithm. The value can be **lookup** or **best fit**.|
| localeMatcher | string | Yes | Yes | Locale matching algorithm. The value can be **lookup** or **best fit**.|
| usage | string | Yes | Yes | Whether the comparison is for sorting or for searching. The value can be **sort** or **search**. |
| usage | string | Yes | Yes | Whether the comparison is for sorting or for searching. The value can be **sort** or **search**. |
| sensitivity | string | Yes | Yes | Differences in the strings that lead to non-zero return values. The value can be **base**, **accent**, **case**, or **variant**.|
| sensitivity | string | Yes | Yes | Differences in the strings that lead to non-zero return values. The value can be **base**, **accent**, **case**, or **letiant**.|
| ignorePunctuation | boolean | Yes | Yes | Whether punctuation is ignored. The value can be **true** or **false**. |
| ignorePunctuation | boolean | Yes | Yes | Whether punctuation is ignored. The value can be **true** or **false**. |
| collation | string | Yes | Yes | Rule for sorting regions. The value can be any of the following: **big5han**, **compat**, **dict**, **direct**, **ducet**, **eor**, **gb2312**, **phonebk**, **phonetic**, **pinyin**, **reformed**, **searchjl**, **stroke**, **trad**, **unihan**, **zhuyin**.|
| collation | string | Yes | Yes | Rule for sorting regions. The value can be any of the following: **big5han**, **compat**, **dict**, **direct**, **ducet**, **eor**, **gb2312**, **phonebk**, **phonetic**, **pinyin**, **reformed**, **searchjl**, **stroke**, **trad**, **unihan**, **zhuyin**.|
| numeric | boolean | Yes | Yes | Whether numeric collation is used. The value can be **true** or **false**. |
| numeric | boolean | Yes | Yes | Whether numeric collation is used. The value can be **true** or **false**. |
...
@@ -531,13 +580,14 @@ Represents the properties of a **Collator** object.
...
@@ -531,13 +580,14 @@ Represents the properties of a **Collator** object.
constructor()
constructor()
Create a **PluralRules** object.
Creates a **PluralRules** object to obtain the singular-plural type of numbers.
| locale | string \| Array<string> | Yes | A string containing locale information, including the language, optional script, and region.|
| locale | string \| Array<string> | Yes | A string containing locale information, including the language, optional script, and region.|
| options<sup>9+</sup> | [RelativeTimeFormatInputOptions](#relativetimeformatinputoptions9) | No | Options for creating a **RelativeTimeFormat** object. |
| options<sup>9+</sup> | [RelativeTimeFormatInputOptions](#relativetimeformatinputoptions8) | No | Options for creating a **RelativeTimeFormat** object. |
**Example**
**Example**
```
```js
var relativeTimeFormat = new Intl.RelativeTimeFormat("zh-CN", {"localeMatcher": "lookup", "numeric": "always", "style": "long"});
// Use locale zh-CN to create a RelativeTimeFormat object. Set localeMatcher to lookup, numeric to always, and style to long.
@@ -658,16 +719,18 @@ Formats the value and unit based on the specified locale and formatting options.
...
@@ -658,16 +719,18 @@ Formats the value and unit based on the specified locale and formatting options.
| value | number | Yes | Value to format. |
| value | number | Yes | Value to format. |
| unit | string | Yes | Unit to format. The value can be any of the following: **year**, **quarter**, **month**, **week**, **day**, **hour**, **minute**, **second**.|
| unit | string | Yes | Unit to format. The value can be any of the following: **year**, **quarter**, **month**, **week**, **day**, **hour**, **minute**, **second**.|
**Return Value**
**Return value**
| Type | Description |
| Type | Description |
| ------ | ---------- |
| ------ | ---------- |
| string | Relative time after formatting.|
| string | Relative time after formatting.|
**Example**
**Example**
```
```js
var relativetimefmt = new Intl.RelativeTimeFormat("zh-CN");
// Use locale zh-CN to create a RelativeTimeFormat object.
@@ -686,16 +749,17 @@ Returns an array of RelativeTimeFormat objects in parts for locale-aware formatt
...
@@ -686,16 +749,17 @@ Returns an array of RelativeTimeFormat objects in parts for locale-aware formatt
| value | number | Yes | Value to format. |
| value | number | Yes | Value to format. |
| unit | string | Yes | Unit to format. The value can be any of the following: **year**, **quarter**, **month**, **week**, **day**, **hour**, **minute**, **second**.|
| unit | string | Yes | Unit to format. The value can be any of the following: **year**, **quarter**, **month**, **week**, **day**, **hour**, **minute**, **second**.|