提交 579d38b4 编写于 作者: S shawn_he

update doc

Signed-off-by: Nshawn_he <shawn.he@huawei.com>
上级 a8c2a3f7
......@@ -28,7 +28,7 @@ You can use APIs provided in the following table to obtain the system language a
```js
var language = i18n.getSystemLanguage();
let language = i18n.getSystemLanguage();
```
2. Obtain the system region.
......@@ -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.
```js
var region = i18n.getSystemRegion();
let region = i18n.getSystemRegion();
```
3. Obtain the system locale.
......@@ -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.
```js
var locale = i18n.getSystemLocale();
let locale = i18n.getSystemLocale();
```
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
```js
var rtl = i18n.isRTL("zh-CN");
let rtl = i18n.isRTL("zh-CN");
```
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
Call the **is24HourClock** method to check whether the system uses a 24-hour clock.
```js
var hourClock = i18n.is24HourClock();
let hourClock = i18n.is24HourClock();
```
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
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
var language = "en";
var locale = "zh-CN";
var sentenceCase = false;
var localizedLanguage = i18n.getDisplayLanguage(language, locale, sentenceCase);
let language = "en";
let locale = "zh-CN";
let sentenceCase = false;
let localizedLanguage = i18n.getDisplayLanguage(language, locale, sentenceCase);
```
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
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
var country = "US";
var locale = "zh-CN";
var sentenceCase = false;
var localizedCountry = i18n.getDisplayCountry(country, locale, sentenceCase);
let country = "US";
let locale = "zh-CN";
let sentenceCase = false;
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
```js
var calendar = i18n.getCalendar("zh-CN", "gregory");
let calendar = i18n.getCalendar("zh-CN", "gregory");
```
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
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
var date1 = new Date();
let date1 = new Date();
calendar.setTime(date1);
var date2 = 1000;
let date2 = 1000;
calendar.setTime(date2);
```
......@@ -147,7 +147,7 @@ You can use APIs provided in the following table to obtain the system language a
```js
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.
......@@ -157,7 +157,7 @@ You can use APIs provided in the following table to obtain the system language a
```js
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.
......@@ -166,7 +166,7 @@ You can use APIs provided in the following table to obtain the system language a
```js
calendar.setMinimalDaysInFirstWeek(3);
var minimalDaysInFirstWeek = calendar.getMinimalDaysInFirstWeek();
let minimalDaysInFirstWeek = calendar.getMinimalDaysInFirstWeek();
```
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
```js
var localizedName = calendar.getDisplayName("zh-CN");
let localizedName = calendar.getDisplayName("zh-CN");
```
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
```js
var date = new Date();
var weekend = calendar.isWeekend(date);
let date = new Date();
let weekend = calendar.isWeekend(date);
```
......@@ -211,21 +211,21 @@ You can use APIs provided in the following table to obtain the system language a
```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.
Call the **isValidNumber** method to check whether the format of the input phone number is correct.
```js
var validNumber = phoneNumberFormat.isValidNumber("15812341234");
let validNumber = phoneNumberFormat.isValidNumber("15812341234");
```
3. Format a phone number.
Call the **format** method of **PhoneNumberFormat** to format the input phone number.
```js
var formattedNumber = phoneNumberFormat.format("15812341234");
let formattedNumber = phoneNumberFormat.format("15812341234");
```
......@@ -248,11 +248,11 @@ The **unitConvert** API is provided to help you implement measurement conversion
```js
var fromUnit = {unit: "cup", measureSystem: "US"};
var toUnit = {unit: "liter", measureSystem: "SI"};
var number = 1000;
var locale = "en-US";
var style = "long";
let fromUnit = {unit: "cup", measureSystem: "US"};
let toUnit = {unit: "liter", measureSystem: "SI"};
let number = 1000;
let locale = "en-US";
let style = "long";
i18n.Util.unitConvert(fromUtil, toUtil, number, locale, style);
```
......@@ -280,7 +280,7 @@ The **unitConvert** API is provided to help you implement measurement conversion
```js
var indexUtil = i18n.getInstance("zh-CN");
let indexUtil = i18n.getInstance("zh-CN");
```
2. Obtain the index list.
......@@ -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.
```js
var indexList = indexUtil.getIndexList();
let indexList = indexUtil.getIndexList();
```
3. Add an index.
......@@ -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.
```js
var text = "access index";
let text = "access index";
indexUtil.getIndex(text);
```
......@@ -338,8 +338,8 @@ When a text is displayed in more than one line, [BreakIterator8](../reference/ap
```js
var locale = "en-US"
var breakIterator = i18n.getLineInstance(locale);
let locale = "en-US"
let breakIterator = i18n.getLineInstance(locale);
```
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
```js
var text = "Apple is my favorite fruit";
let text = "Apple is my favorite fruit";
breakIterator.setLineBreakText(text);
var breakText = breakIterator.getLineBreakText();
let breakText = breakIterator.getLineBreakText();
```
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
```js
var pos = breakIterator.current();
let pos = breakIterator.current();
```
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
```js
var 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 firstPos = breakIterator.first(); // Set a BreakIterator object to the first break point, that is, the start position of the text.
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.
// 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.
var 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 nextPos = breakIterator.next(-2);
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.
var followingPos = breakIterator.following(10);
let followingPos = breakIterator.following(10);
```
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
```js
var isboundary = breakIterator.isBoundary(5);
let isboundary = breakIterator.isBoundary(5);
```
```
\ No newline at end of file
......@@ -44,9 +44,9 @@ Use [Locale](../reference/apis/js-apis-intl.md#locale) APIs to maximize or minim
```js
var locale = "zh-CN";
var options = {caseFirst: "false", calendar: "chinese", collation: "pinyin"};
var localeObj = new intl.Locale(locale, options);
let locale = "zh-CN";
let options = {caseFirst: "false", calendar: "chinese", collation: "pinyin"};
let localeObj = new intl.Locale(locale, options);
```
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
Call the **toString** method to obtain the string representing a **Locale** object, which includes the language, region, and other options.
```js
var localeStr = localeObj.toString();
let localeStr = localeObj.toString();
```
3. Maximize locale information.
......@@ -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.
```js
var maximizedLocale = localeObj.maximize();
let maximizedLocale = localeObj.maximize();
```
4. Minimize locale information.
......@@ -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.
```js
var minimizedLocale = localeObj.minimize();
let minimizedLocale = localeObj.minimize();
```
......@@ -98,14 +98,14 @@ Use [DateTimeFormat](../reference/apis/js-apis-intl.md#datetimeformat) APIs to f
```js
var dateTimeFormat = new intl.DateTimeFormat();
let dateTimeFormat = new intl.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).
```js
var options = {dateStyle: "full", timeStyle: "full"};
var dateTimeFormat = new intl.DateTimeFormat("zh-CN", options);
let options = {dateStyle: "full", timeStyle: "full"};
let dateTimeFormat = new intl.DateTimeFormat("zh-CN", options);
```
2. Format the date and time.
......@@ -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.
```js
var date = new Date();
var formatResult = dateTimeFormat.format(date);
let date = new Date();
let formatResult = dateTimeFormat.format(date);
```
3. Format a period.
......@@ -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.
```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");
let startDate = new Date(2021, 11, 17, 3, 24, 0);
let endDate = new Date(2021, 11, 18, 3, 24, 0);
let datefmt = new Intl.DateTimeFormat("en-GB");
datefmt.formatRange(startDate, endDate);
```
......@@ -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.
```js
var options = dateTimeFormat.resolvedOptions();
let options = dateTimeFormat.resolvedOptions();
```
......@@ -160,14 +160,14 @@ Use [NumberFormat](../reference/apis/js-apis-intl.md#numberformat) APIs to forma
```js
var numberFormat = new intl.NumberFormat();
let numberFormat = new intl.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).
```js
var options = {compactDisplay: "short", notation: "compact"};
var numberFormat = new intl.NumberFormat("zh-CN", options);
let options = {compactDisplay: "short", notation: "compact"};
let numberFormat = new intl.NumberFormat("zh-CN", options);
```
2. Format a number.
......@@ -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.
```js
var number = 1234.5678
var formatResult = numberFormat.format(number);
let number = 1234.5678
let formatResult = numberFormat.format(number);
```
3. Obtain attributes of the **NumberFormat** object.
......@@ -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.
```js
var options = numberFormat.resolvedOptions();
let options = numberFormat.resolvedOptions();
```
......@@ -211,13 +211,13 @@ Use [Collator](../reference/apis/js-apis-intl.md#collator8) APIs to sort strings
```js
var collator = new intl.Collator();
let collator = new intl.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).
```js
var collator= new intl.Collator("zh-CN", {localeMatcher: "best fit", usage: "sort"});
let collator= new intl.Collator("zh-CN", {localeMatcher: "best fit", usage: "sort"});
```
2. Compare two 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.
```js
var str1 = "first string";
var str2 = "second string";
var compareResult = collator.compare(str1, str2);
let str1 = "first string";
let str2 = "second string";
let compareResult = collator.compare(str1, str2);
```
3. Obtain attributes of the **Collator** object.
......@@ -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.
```js
var options = collator.resolvedOptions();
let options = collator.resolvedOptions();
```
......@@ -261,13 +261,13 @@ Use [PluralRules](../reference/apis/js-apis-intl.md#pluralrules8) APIs to determ
```js
var pluralRules = new intl.PluralRules();
let pluralRules = new intl.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).
```js
var pluralRules = new intl.PluralRules("zh-CN", {localeMatcher: "best fit", type: "cardinal"});
let pluralRules = new intl.PluralRules("zh-CN", {localeMatcher: "best fit", type: "cardinal"});
```
2. Determine the singular-plural type.
......@@ -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**.
```js
var number = 1234.5678
var categoryResult = plurals.select(number);
let number = 1234.5678
let categoryResult = plurals.select(number);
```
......@@ -304,13 +304,13 @@ Use [RelativeTimeFormat](../reference/apis/js-apis-intl.md#relativetimeformat8)
```js
var relativeTimeFormat = new intl.RelativeTimeFormat();
let relativeTimeFormat = new intl.RelativeTimeFormat();
```
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).
```js
var relativeTimeFormat = new intl.RelativeTimeFormat("zh-CN", {numeric: "always", style: "long"});
let relativeTimeFormat = new intl.RelativeTimeFormat("zh-CN", {numeric: "always", style: "long"});
```
2. Format the relative time.
......@@ -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.
```js
var number = 2;
var unit = "year"
var formatResult = relativeTimeFormat.format(number, unit);
let number = 2;
let unit = "year"
let formatResult = relativeTimeFormat.format(number, unit);
```
3. Obtain each part of the relative time format.
......@@ -328,9 +328,9 @@ Use [RelativeTimeFormat](../reference/apis/js-apis-intl.md#relativetimeformat8)
Upon obtaining each part of the relative time format, customize the relative time formatting result.
```js
var number = 2;
var unit = "year"
var formatResult = relativeTimeFormat.formatToParts(number, unit);
let number = 2;
let unit = "year"
let formatResult = relativeTimeFormat.formatToParts(number, unit);
```
4. Obtain attributes of the **RelativeTimeFormat** object.
......@@ -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).
```js
var options = numberFormat.resolvedOptions();
let options = numberFormat.resolvedOptions();
```
## Samples
......
# I18N Error Codes
# i18n Error Codes
## 890001 Incorrect Parameter Type
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册