提交 a17b2af4 编写于 作者: S sunyaozu

fixed 0502593b from https://gitee.com/sunyaozu/docs/pulls/14676

update i18n and intl docs
Signed-off-by: Nsunyaozu <sunyaozu@huawei.com>
上级 82ffe6a1
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
## 获取和设置系统国际化相关信息 ## 获取和设置系统国际化相关信息
调用接口访问和设置系统语言、偏好语言、地区、24小时制、本地数字开关等国际化信息。 调用接口访问和设置系统语言、偏好语言、地区、24小时制、本地数字等国际化信息。
### 接口说明 ### 接口说明
...@@ -30,15 +30,15 @@ ...@@ -30,15 +30,15 @@
| System | getPreferredLanguageList()<sup>9+</sup> | 获取系统偏好语言列表。 | | System | getPreferredLanguageList()<sup>9+</sup> | 获取系统偏好语言列表。 |
| System | getFirstPreferredLanguage()<sup>9+</sup> | 获取系统偏好语言列表中的第一个偏好语言。 | | System | getFirstPreferredLanguage()<sup>9+</sup> | 获取系统偏好语言列表中的第一个偏好语言。 |
| System | getAppPreferredLanguage()<sup>9+</sup> | 获取应用偏好语言。 | | System | getAppPreferredLanguage()<sup>9+</sup> | 获取应用偏好语言。 |
| System | setUsingLocalDigit(flag: boolean)<sup>9+</sup> | 设置是否打开本地数字开关。 | | System | setUsingLocalDigit(flag: boolean)<sup>9+</sup> | 设置系统是否使用本地数字。 |
| System | getUsingLocalDigit()<sup>9+</sup> | 获取系统当前是否打开本地数字开关。 | | System | getUsingLocalDigit()<sup>9+</sup> | 判断系统是否使用本地数字。 |
| | isRTL(locale:string):boolean<sup>9+</sup> | locale对应的语言是否为从右到左语言。 | | | isRTL(locale:string):boolean<sup>9+</sup> | locale对应的语言是否为从右到左语言。 |
### 开发步骤 ### 开发步骤
1. 导入I18n模块。 1. 导入I18n模块。
```js ```js
import I18n from '@ohos.i18n' import I18n from '@ohos.i18n';
``` ```
2. 获取和设置系统语言。 2. 获取和设置系统语言。
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
I18n.System.setSystemLanguage("en"); // 将系统语言设置为 "en" I18n.System.setSystemLanguage("en"); // 将系统语言设置为 "en"
let language = I18n.System.getSystemLanguage(); // language = "en" let language = I18n.System.getSystemLanguage(); // language = "en"
} catch(error) { } catch(error) {
console.error(`call i18n.System interface failed, error code: ${error.code}, message: ${error.message}`) console.error(`call i18n.System interface failed, error code: ${error.code}, message: ${error.message}`);
} }
``` ```
...@@ -65,7 +65,7 @@ ...@@ -65,7 +65,7 @@
I18n.System.setSystemRegion("CN"); // 将系统国家设置为 "CN" I18n.System.setSystemRegion("CN"); // 将系统国家设置为 "CN"
let region = I18n.System.getSystemRegion(); // region = "CN" let region = I18n.System.getSystemRegion(); // region = "CN"
} catch(error) { } catch(error) {
console.error(`call i18n.System interface failed, error code: ${error.code}, message: ${error.message}`) console.error(`call i18n.System interface failed, error code: ${error.code}, message: ${error.message}`);
} }
``` ```
...@@ -79,7 +79,7 @@ ...@@ -79,7 +79,7 @@
I18n.System.setSystemLocale("zh-Hans-CN"); // 将系统Locale设置为 "zh-Hans-CN" I18n.System.setSystemLocale("zh-Hans-CN"); // 将系统Locale设置为 "zh-Hans-CN"
let locale = I18n.System.getSystemLocale(); // locale = "zh-Hans-CN" let locale = I18n.System.getSystemLocale(); // locale = "zh-Hans-CN"
} catch(error) { } catch(error) {
console.error(`call i18n.System interface failed, error code: ${error.code}, message: ${error.message}`) console.error(`call i18n.System interface failed, error code: ${error.code}, message: ${error.message}`);
} }
``` ```
...@@ -92,7 +92,7 @@ ...@@ -92,7 +92,7 @@
let rtl = I18n.isRTL("zh-CN"); // rtl = false let rtl = I18n.isRTL("zh-CN"); // rtl = false
rtl = I18n.isRTL("ar"); // rtl = true rtl = I18n.isRTL("ar"); // rtl = true
} catch(error) { } catch(error) {
console.error(`call i18n.System interface failed, error code: ${error.code}, message: ${error.message}`) console.error(`call i18n.System interface failed, error code: ${error.code}, message: ${error.message}`);
} }
``` ```
...@@ -106,7 +106,7 @@ ...@@ -106,7 +106,7 @@
I18n.System.set24HourClock(true); I18n.System.set24HourClock(true);
let hourClock = I18n.System.is24HourClock(); // hourClock = true let hourClock = I18n.System.is24HourClock(); // hourClock = true
} catch(error) { } catch(error) {
console.error(`call i18n.System interface failed, error code: ${error.code}, message: ${error.message}`) console.error(`call i18n.System interface failed, error code: ${error.code}, message: ${error.message}`);
} }
``` ```
...@@ -121,7 +121,7 @@ ...@@ -121,7 +121,7 @@
let sentenceCase = false; let sentenceCase = false;
let localizedLanguage = I18n.System.getDisplayLanguage(language, locale, sentenceCase); // localizedLanguage = "英语" let localizedLanguage = I18n.System.getDisplayLanguage(language, locale, sentenceCase); // localizedLanguage = "英语"
} catch(error) { } catch(error) {
console.error(`call i18n.System interface failed, error code: ${error.code}, message: ${error.message}`) console.error(`call i18n.System interface failed, error code: ${error.code}, message: ${error.message}`);
} }
``` ```
...@@ -136,7 +136,7 @@ ...@@ -136,7 +136,7 @@
let sentenceCase = false; let sentenceCase = false;
let localizedCountry = I18n.System.getDisplayCountry(country, locale, sentenceCase); // localizedCountry = "美国" let localizedCountry = I18n.System.getDisplayCountry(country, locale, sentenceCase); // localizedCountry = "美国"
} catch(error) { } catch(error) {
console.error(`call i18n.System interface failed, error code: ${error.code}, message: ${error.message}`) console.error(`call i18n.System interface failed, error code: ${error.code}, message: ${error.message}`);
} }
``` ```
...@@ -150,7 +150,7 @@ ...@@ -150,7 +150,7 @@
let languageList = I18n.System.getSystemLanguages(); // languageList = ["en-Latn-US", "zh-Hans"] let languageList = I18n.System.getSystemLanguages(); // languageList = ["en-Latn-US", "zh-Hans"]
let countryList = I18n.System.getSystemCountries("zh"); // countryList = ["ZW", "YT", ..., "CN", "DE"], 共240个国家和地区 let countryList = I18n.System.getSystemCountries("zh"); // countryList = ["ZW", "YT", ..., "CN", "DE"], 共240个国家和地区
} catch(error) { } catch(error) {
console.error(`call i18n.System interface failed, error code: ${error.code}, message: ${error.message}`) console.error(`call i18n.System interface failed, error code: ${error.code}, message: ${error.message}`);
} }
``` ```
...@@ -162,7 +162,7 @@ ...@@ -162,7 +162,7 @@
try { try {
let isSuggest = I18n.System.isSuggested("zh", "CN"); // isSuggest = true let isSuggest = I18n.System.isSuggested("zh", "CN"); // isSuggest = true
} catch(error) { } catch(error) {
console.error(`call i18n.System interface failed, error code: ${error.code}, message: ${error.message}`) console.error(`call i18n.System interface failed, error code: ${error.code}, message: ${error.message}`);
} }
``` ```
...@@ -182,7 +182,7 @@ ...@@ -182,7 +182,7 @@
let firstPreferredLanguage = I18n.System.getFirstPreferredLanguage(); // firstPreferredLanguage = "en-GB" let firstPreferredLanguage = I18n.System.getFirstPreferredLanguage(); // firstPreferredLanguage = "en-GB"
let appPreferredLanguage = I18n.System.getAppPreferredLanguage(); // 当应用中包含 "en-GB"资源时,应用偏好语言为"en-GB" let appPreferredLanguage = I18n.System.getAppPreferredLanguage(); // 当应用中包含 "en-GB"资源时,应用偏好语言为"en-GB"
} catch(error) { } catch(error) {
console.error(`call i18n.System interface failed, error code: ${error.code}, message: ${error.message}`) console.error(`call i18n.System interface failed, error code: ${error.code}, message: ${error.message}`);
} }
``` ```
...@@ -190,14 +190,14 @@ ...@@ -190,14 +190,14 @@
调用setUsingLocalDigit接口打开本地化数字开关。(此接口为系统接口,只有具有UPDATE_CONFIGURATION权限的系统应用可以调用。) 调用setUsingLocalDigit接口打开本地化数字开关。(此接口为系统接口,只有具有UPDATE_CONFIGURATION权限的系统应用可以调用。)
调用getUsingLocalDigit接口访问本地化数字开关状态。 调用getUsingLocalDigit接口访问本地化数字开关状态。
当前只有 "ar", "as", "bn", "fa", "mr", "my", "ne", "ur" 8个语言支持打开本地数字开关 当前只有 "ar", "as", "bn", "fa", "mr", "my", "ne", "ur" 8个语言支持使用本地数字
```js ```js
try { try {
I18n.System.setUsingLocalDigit(true); // 打开本地化数字开关 I18n.System.setUsingLocalDigit(true); // 打开本地化数字开关
let status = I18n.System.getUsingLocalDigit(); // status = true let status = I18n.System.getUsingLocalDigit(); // status = true
} catch(error) { } catch(error) {
console.error(`call i18n.System interface failed, error code: ${error.code}, message: ${error.message}`) console.error(`call i18n.System interface failed, error code: ${error.code}, message: ${error.message}`);
} }
``` ```
...@@ -220,14 +220,14 @@ try { ...@@ -220,14 +220,14 @@ try {
| Calendar | getMinimalDaysInFirstWeek():number<sup>8+</sup> | 获取一年中第一周的最小天数。 | | Calendar | getMinimalDaysInFirstWeek():number<sup>8+</sup> | 获取一年中第一周的最小天数。 |
| Calendar | setMinimalDaysInFirstWeek(value:number): void<sup>8+</sup> | 设置一年中第一周的最小天数。 | | Calendar | setMinimalDaysInFirstWeek(value:number): void<sup>8+</sup> | 设置一年中第一周的最小天数。 |
| Calendar | getDisplayName(locale:string):string<sup>8+</sup> | 获取日历对象的本地化表示。 | | Calendar | getDisplayName(locale:string):string<sup>8+</sup> | 获取日历对象的本地化表示。 |
| Calendar | isWeekend(date?:Date):boolean<sup>8+</sup> | 判断给定的日期是否在日历中是周末。 | | Calendar | isWeekend(date?:Date):boolean<sup>8+</sup> | 判断给定的日期在日历中是否是周末。 |
### 开发步骤 ### 开发步骤
1. 导入I18n模块。 1. 导入I18n模块。
```js ```js
import I18n from '@ohos.i18n' import I18n from '@ohos.i18n';
``` ```
2. 实例化日历对象。 2. 实例化日历对象。
...@@ -254,7 +254,7 @@ try { ...@@ -254,7 +254,7 @@ try {
调用set接口设置日历对象的年、月、日、时、分、秒。 调用set接口设置日历对象的年、月、日、时、分、秒。
```js ```js
calendar.set(2021, 12, 21, 6, 0, 0) calendar.set(2021, 12, 21, 6, 0, 0);
``` ```
5. 设置、获取日历对象的时区。 5. 设置、获取日历对象的时区。
...@@ -317,7 +317,7 @@ try { ...@@ -317,7 +317,7 @@ try {
1. 导入I18n模块。 1. 导入I18n模块。
```js ```js
import I18n from '@ohos.i18n' import I18n from '@ohos.i18n';
``` ```
2. 实例化电话号码格式化对象。 2. 实例化电话号码格式化对象。
...@@ -359,7 +359,7 @@ try { ...@@ -359,7 +359,7 @@ try {
1. 导入I18n模块。 1. 导入I18n模块。
```js ```js
import I18n from '@ohos.i18n' import I18n from '@ohos.i18n';
``` ```
2. 度量衡单位转换。 2. 度量衡单位转换。
...@@ -393,7 +393,7 @@ try { ...@@ -393,7 +393,7 @@ try {
1. 导入I18n模块。 1. 导入I18n模块。
```js ```js
import I18n from '@ohos.i18n' import I18n from '@ohos.i18n';
``` ```
2. 实例化字母表索引对象。 2. 实例化字母表索引对象。
...@@ -418,7 +418,7 @@ try { ...@@ -418,7 +418,7 @@ try {
调用addLocale接口,将新的Locale对应的字母表索引添加到当前字母表索引列表中。 调用addLocale接口,将新的Locale对应的字母表索引添加到当前字母表索引列表中。
```js ```js
indexUtil.addLocale("ar") indexUtil.addLocale("ar");
``` ```
5. 获取字符串对应的索引。 5. 获取字符串对应的索引。
...@@ -454,7 +454,7 @@ try { ...@@ -454,7 +454,7 @@ try {
1. 导入I18n模块。 1. 导入I18n模块。
```js ```js
import I18n from '@ohos.i18n' import I18n from '@ohos.i18n';
``` ```
2. 实例化断行对象。 2. 实例化断行对象。
...@@ -462,7 +462,7 @@ try { ...@@ -462,7 +462,7 @@ try {
调用getLineInstance接口来实例化断行对象。 调用getLineInstance接口来实例化断行对象。
```js ```js
let locale = "en-US" let locale = "en-US";
let breakIterator = I18n.getLineInstance(locale); let breakIterator = I18n.getLineInstance(locale);
``` ```
...@@ -531,7 +531,7 @@ try { ...@@ -531,7 +531,7 @@ try {
1. 导入I18n模块。 1. 导入I18n模块。
```js ```js
import I18n from '@ohos.i18n' import I18n from '@ohos.i18n';
``` ```
2. 实例化时区对象,并获取相关时区信息。 2. 实例化时区对象,并获取相关时区信息。
...@@ -592,7 +592,7 @@ try { ...@@ -592,7 +592,7 @@ try {
1. 导入I18n模块。 1. 导入I18n模块。
```js ```js
import I18n from '@ohos.i18n' import I18n from '@ohos.i18n';
``` ```
2. 获取支持音译的ID列表。 2. 获取支持音译的ID列表。
...@@ -637,7 +637,7 @@ try { ...@@ -637,7 +637,7 @@ try {
1. 导入I18n模块。 1. 导入I18n模块。
```js ```js
import I18n from '@ohos.i18n' import I18n from '@ohos.i18n';
``` ```
2. 判断字符是否具有某种性质。 2. 判断字符是否具有某种性质。
...@@ -719,7 +719,7 @@ try { ...@@ -719,7 +719,7 @@ try {
1. 导入I18n模块。 1. 导入I18n模块。
```js ```js
import I18n from '@ohos.i18n' import I18n from '@ohos.i18n';
``` ```
2. 判断日期的年月日的排序顺序。 2. 判断日期的年月日的排序顺序。
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
未正确导入包可能会产生不明确的接口行为。 未正确导入包可能会产生不明确的接口行为。
```js ```js
import Intl from '@ohos.intl' import Intl from '@ohos.intl';
``` ```
2. 实例化Locale对象。 2. 实例化Locale对象。
...@@ -100,7 +100,7 @@ ...@@ -100,7 +100,7 @@
未正确导入包可能会产生不明确的接口行为。 未正确导入包可能会产生不明确的接口行为。
```js ```js
import Intl from '@ohos.intl' import Intl from '@ohos.intl';
``` ```
2. 实例化日期时间格式化对象。 2. 实例化日期时间格式化对象。
...@@ -170,7 +170,7 @@ ...@@ -170,7 +170,7 @@
未正确导入包可能会产生不明确的接口行为。 未正确导入包可能会产生不明确的接口行为。
```js ```js
import Intl from '@ohos.intl' import Intl from '@ohos.intl';
``` ```
2. 实例化数字格式化对象。 2. 实例化数字格式化对象。
...@@ -195,7 +195,7 @@ ...@@ -195,7 +195,7 @@
```js ```js
let options = {compactDisplay: "short", notation: "compact"}; let options = {compactDisplay: "short", notation: "compact"};
let numberFormat = new Intl.NumberFormat("zh-CN", options); let numberFormat = new Intl.NumberFormat("zh-CN", options);
let number = 1234.5678 let number = 1234.5678;
let formatResult = numberFormat.format(number); // formatResult = "1235" let formatResult = numberFormat.format(number); // formatResult = "1235"
``` ```
...@@ -229,7 +229,7 @@ ...@@ -229,7 +229,7 @@
未正确导入包可能会产生不明确的接口行为。 未正确导入包可能会产生不明确的接口行为。
```js ```js
import Intl from '@ohos.intl' import Intl from '@ohos.intl';
``` ```
2. 实例化排序对象。 2. 实例化排序对象。
...@@ -240,7 +240,7 @@ ...@@ -240,7 +240,7 @@
let collator = new Intl.Collator(); let collator = new Intl.Collator();
``` ```
另一种方法是使用开发者提供的Locale和其他相关参数来创建Collator对象,完整的参数列表参见[CollatorOptions](../reference/apis/js-apis-intl.md#collatoroptions9)。 另一种方法是使用开发者提供的Locale和其他相关参数来创建Collator对象,完整的参数列表参见[CollatorOptions](../reference/apis/js-apis-intl.md#collatoroptions8)。
其中,sensitivity参数用于控制哪些级别的差异会被用于比较两个字符串。取值"base"表示,仅比较字符本身,不考虑重音符号、大小写差异。例如,'a' != 'b','a' == 'á','a' == 'A'。取值"accent"表示考虑重音符号,不考虑大小写的差异。例如,'a' != 'b','a' != 'á','a' == 'A'。取值"case"表示考虑大小写的差异,不考虑重音符号的差异。例如,'a' != 'b','a' == 'á','a' != 'A'。取值"variant"表示考虑重音符号、大小写等方面差异。例如'a' != 'b','a' != 'á','a' != 'A'。 其中,sensitivity参数用于控制哪些级别的差异会被用于比较两个字符串。取值"base"表示,仅比较字符本身,不考虑重音符号、大小写差异。例如,'a' != 'b','a' == 'á','a' == 'A'。取值"accent"表示考虑重音符号,不考虑大小写的差异。例如,'a' != 'b','a' != 'á','a' == 'A'。取值"case"表示考虑大小写的差异,不考虑重音符号的差异。例如,'a' != 'b','a' == 'á','a' != 'A'。取值"variant"表示考虑重音符号、大小写等方面差异。例如'a' != 'b','a' != 'á','a' != 'A'。
```js ```js
...@@ -290,7 +290,7 @@ ...@@ -290,7 +290,7 @@
未正确导入包可能会产生不明确的接口行为。 未正确导入包可能会产生不明确的接口行为。
```js ```js
import Intl from '@ohos.intl' import Intl from '@ohos.intl';
``` ```
2. 实例化单复数对象。 2. 实例化单复数对象。
...@@ -301,7 +301,7 @@ ...@@ -301,7 +301,7 @@
let pluralRules = new Intl.PluralRules(); let pluralRules = new Intl.PluralRules();
``` ```
另一种方法是使用开发者提供的Locale和其他相关参数来创建单复数对象。完整的参数列表参见[PluralRulesOptions](../reference/apis/js-apis-intl.md#pluralrulesoptions9)。 另一种方法是使用开发者提供的Locale和其他相关参数来创建单复数对象。完整的参数列表参见[PluralRulesOptions](../reference/apis/js-apis-intl.md#pluralrulesoptions8)。
```js ```js
let pluralRules = new Intl.PluralRules("zh-CN", {localeMatcher: "best fit", type: "cardinal"}); let pluralRules = new Intl.PluralRules("zh-CN", {localeMatcher: "best fit", type: "cardinal"});
...@@ -313,7 +313,7 @@ ...@@ -313,7 +313,7 @@
```js ```js
let pluralRules = new Intl.PluralRules("zh-CN", {localeMatcher: "best fit", type: "cardinal"}); let pluralRules = new Intl.PluralRules("zh-CN", {localeMatcher: "best fit", type: "cardinal"});
let number = 1234.5678 let number = 1234.5678;
let categoryResult = pluralRules.select(number); // categoryResult = "other" let categoryResult = pluralRules.select(number); // categoryResult = "other"
``` ```
...@@ -338,7 +338,7 @@ ...@@ -338,7 +338,7 @@
未正确导入包可能会产生不明确的接口行为。 未正确导入包可能会产生不明确的接口行为。
```js ```js
import Intl from '@ohos.intl' import Intl from '@ohos.intl';
``` ```
2. 实例化相对时间格式化对象。 2. 实例化相对时间格式化对象。
...@@ -349,7 +349,7 @@ ...@@ -349,7 +349,7 @@
let relativeTimeFormat = new Intl.RelativeTimeFormat(); let relativeTimeFormat = new Intl.RelativeTimeFormat();
``` ```
另一种方法是使用开发者提供的Locale和格式化参数来创建相对时间格式化对象。其中,格式化参数是可选的,完整的参数列表参见[ RelativeTimeFormatInputOptions](../reference/apis/js-apis-intl.md#relativetimeformatinputoptions9)。 另一种方法是使用开发者提供的Locale和格式化参数来创建相对时间格式化对象。其中,格式化参数是可选的,完整的参数列表参见[ RelativeTimeFormatInputOptions](../reference/apis/js-apis-intl.md#relativetimeformatinputoptions8)。
```js ```js
let relativeTimeFormat = new Intl.RelativeTimeFormat("zh-CN", {numeric: "always", style: "long"}); let relativeTimeFormat = new Intl.RelativeTimeFormat("zh-CN", {numeric: "always", style: "long"});
...@@ -362,7 +362,7 @@ ...@@ -362,7 +362,7 @@
```js ```js
let relativeTimeFormat = new Intl.RelativeTimeFormat("zh-CN", {numeric: "always", style: "long"}); let relativeTimeFormat = new Intl.RelativeTimeFormat("zh-CN", {numeric: "always", style: "long"});
let number = 2; let number = 2;
let unit = "year" let unit = "year";
let formatResult = relativeTimeFormat.format(number, unit); // 2年后 let formatResult = relativeTimeFormat.format(number, unit); // 2年后
``` ```
...@@ -373,7 +373,7 @@ ...@@ -373,7 +373,7 @@
```js ```js
let relativeTimeFormat = new Intl.RelativeTimeFormat("zh-CN", {numeric: "always", style: "long"}); let relativeTimeFormat = new Intl.RelativeTimeFormat("zh-CN", {numeric: "always", style: "long"});
let number = 2; let number = 2;
let unit = "year" let unit = "year";
let formatPartsResult = relativeTimeFormat.formatToParts(number, unit); // formatPartsResult = [{"type": "integer", "value": "2", "unit": "year"}, {"type":"literal", "value": "年后"}] let formatPartsResult = relativeTimeFormat.formatToParts(number, unit); // formatPartsResult = [{"type": "integer", "value": "2", "unit": "year"}, {"type":"literal", "value": "年后"}]
``` ```
......
...@@ -53,7 +53,7 @@ static getDisplayCountry(country: string, locale: string, sentenceCase?: boolean ...@@ -53,7 +53,7 @@ static getDisplayCountry(country: string, locale: string, sentenceCase?: boolean
try { try {
let displayCountry = I18n.System.getDisplayCountry("zh-CN", "en-GB"); // displayCountry = "China" let displayCountry = I18n.System.getDisplayCountry("zh-CN", "en-GB"); // displayCountry = "China"
} catch(error) { } catch(error) {
console.error(`call System.getDisplayCountry failed, error code: ${error.code}, message: ${error.message}.`) console.error(`call System.getDisplayCountry failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -92,7 +92,7 @@ static getDisplayLanguage(language: string, locale: string, sentenceCase?: boole ...@@ -92,7 +92,7 @@ static getDisplayLanguage(language: string, locale: string, sentenceCase?: boole
try { try {
let displayLanguage = I18n.System.getDisplayLanguage("zh", "en-GB"); // displayLanguage = Chinese let displayLanguage = I18n.System.getDisplayLanguage("zh", "en-GB"); // displayLanguage = Chinese
} catch(error) { } catch(error) {
console.error(`call System.getDisplayLanguage failed, error code: ${error.code}, message: ${error.message}.`) console.error(`call System.getDisplayLanguage failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -123,7 +123,7 @@ static getSystemLanguages(): Array&lt;string&gt; ...@@ -123,7 +123,7 @@ static getSystemLanguages(): Array&lt;string&gt;
try { try {
let systemLanguages = I18n.System.getSystemLanguages(); // [ "en-Latn-US", "zh-Hans" ] let systemLanguages = I18n.System.getSystemLanguages(); // [ "en-Latn-US", "zh-Hans" ]
} catch(error) { } catch(error) {
console.error(`call System.getSystemLanguages failed, error code: ${error.code}, message: ${error.message}.`) console.error(`call System.getSystemLanguages failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -160,7 +160,7 @@ static getSystemCountries(language: string): Array&lt;string&gt; ...@@ -160,7 +160,7 @@ static getSystemCountries(language: string): Array&lt;string&gt;
try { try {
let systemCountries = I18n.System.getSystemCountries('zh'); // systemCountries = [ "ZW", "YT", "YE", ..., "ER", "CN", "DE" ],共计240个国家或地区 let systemCountries = I18n.System.getSystemCountries('zh'); // systemCountries = [ "ZW", "YT", "YE", ..., "ER", "CN", "DE" ],共计240个国家或地区
} catch(error) { } catch(error) {
console.error(`call System.getSystemCountries failed, error code: ${error.code}, message: ${error.message}.`) console.error(`call System.getSystemCountries failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -198,7 +198,7 @@ static isSuggested(language: string, region?: string): boolean ...@@ -198,7 +198,7 @@ static isSuggested(language: string, region?: string): boolean
try { try {
let res = I18n.System.isSuggested('zh', 'CN'); // res = true let res = I18n.System.isSuggested('zh', 'CN'); // res = true
} catch(error) { } catch(error) {
console.error(`call System.isSuggested failed, error code: ${error.code}, message: ${error.message}.`) console.error(`call System.isSuggested failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -229,7 +229,7 @@ static getSystemLanguage(): string ...@@ -229,7 +229,7 @@ static getSystemLanguage(): string
try { try {
let systemLanguage = I18n.System.getSystemLanguage(); // systemLanguage为当前系统语言 let systemLanguage = I18n.System.getSystemLanguage(); // systemLanguage为当前系统语言
} catch(error) { } catch(error) {
console.error(`call System.getSystemLanguage failed, error code: ${error.code}, message: ${error.message}.`) console.error(`call System.getSystemLanguage failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -264,7 +264,7 @@ static setSystemLanguage(language: string): void ...@@ -264,7 +264,7 @@ static setSystemLanguage(language: string): void
try { try {
I18n.System.setSystemLanguage('zh'); // 设置系统当前语言为 "zh" I18n.System.setSystemLanguage('zh'); // 设置系统当前语言为 "zh"
} catch(error) { } catch(error) {
console.error(`call System.setSystemLanguage failed, error code: ${error.code}, message: ${error.message}.`) console.error(`call System.setSystemLanguage failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -295,7 +295,7 @@ static getSystemRegion(): string ...@@ -295,7 +295,7 @@ static getSystemRegion(): string
try { try {
let systemRegion = I18n.System.getSystemRegion(); // 获取系统当前地区设置 let systemRegion = I18n.System.getSystemRegion(); // 获取系统当前地区设置
} catch(error) { } catch(error) {
console.error(`call System.getSystemRegion failed, error code: ${error.code}, message: ${error.message}.`) console.error(`call System.getSystemRegion failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -330,7 +330,7 @@ static setSystemRegion(region: string): void ...@@ -330,7 +330,7 @@ static setSystemRegion(region: string): void
try { try {
I18n.System.setSystemRegion('CN'); // 设置系统当前地区为 "CN" I18n.System.setSystemRegion('CN'); // 设置系统当前地区为 "CN"
} catch(error) { } catch(error) {
console.error(`call System.setSystemRegion failed, error code: ${error.code}, message: ${error.message}.`) console.error(`call System.setSystemRegion failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -361,7 +361,7 @@ static getSystemLocale(): string ...@@ -361,7 +361,7 @@ static getSystemLocale(): string
try { try {
let systemLocale = I18n.System.getSystemLocale(); // 获取系统当前Locale let systemLocale = I18n.System.getSystemLocale(); // 获取系统当前Locale
} catch(error) { } catch(error) {
console.error(`call System.getSystemLocale failed, error code: ${error.code}, message: ${error.message}.`) console.error(`call System.getSystemLocale failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -396,7 +396,7 @@ static setSystemLocale(locale: string): void ...@@ -396,7 +396,7 @@ static setSystemLocale(locale: string): void
try { try {
I18n.System.setSystemLocale('zh-CN'); // 设置系统当前Locale为 "zh-CN" I18n.System.setSystemLocale('zh-CN'); // 设置系统当前Locale为 "zh-CN"
} catch(error) { } catch(error) {
console.error(`call System.setSystemLocale failed, error code: ${error.code}, message: ${error.message}.`) console.error(`call System.setSystemLocale failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -427,7 +427,7 @@ static is24HourClock(): boolean ...@@ -427,7 +427,7 @@ static is24HourClock(): boolean
try { try {
let is24HourClock = I18n.System.is24HourClock(); // 系统24小时开关是否开启 let is24HourClock = I18n.System.is24HourClock(); // 系统24小时开关是否开启
} catch(error) { } catch(error) {
console.error(`call System.is24HourClock failed, error code: ${error.code}, message: ${error.message}.`) console.error(`call System.is24HourClock failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -463,7 +463,7 @@ static set24HourClock(option: boolean): void ...@@ -463,7 +463,7 @@ static set24HourClock(option: boolean): void
try { try {
I18n.System.set24HourClock(true); I18n.System.set24HourClock(true);
} catch(error) { } catch(error) {
console.error(`call System.set24HourClock failed, error code: ${error.code}, message: ${error.message}.`) console.error(`call System.set24HourClock failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -502,7 +502,7 @@ static addPreferredLanguage(language: string, index?: number): void ...@@ -502,7 +502,7 @@ static addPreferredLanguage(language: string, index?: number): void
try { try {
I18n.System.addPreferredLanguage(language, index); // 将zh-CN添加到系统偏好语言列表的第1位 I18n.System.addPreferredLanguage(language, index); // 将zh-CN添加到系统偏好语言列表的第1位
} catch(error) { } catch(error) {
console.error(`call System.addPreferredLanguage failed, error code: ${error.code}, message: ${error.message}.`) console.error(`call System.addPreferredLanguage failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -539,7 +539,7 @@ static removePreferredLanguage(index: number): void ...@@ -539,7 +539,7 @@ static removePreferredLanguage(index: number): void
try { try {
I18n.System.removePreferredLanguage(index); I18n.System.removePreferredLanguage(index);
} catch(error) { } catch(error) {
console.error(`call System.removePreferredLanguage failed, error code: ${error.code}, message: ${error.message}.`) console.error(`call System.removePreferredLanguage failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -570,7 +570,7 @@ static getPreferredLanguageList(): Array&lt;string&gt; ...@@ -570,7 +570,7 @@ static getPreferredLanguageList(): Array&lt;string&gt;
try { try {
let preferredLanguageList = I18n.System.getPreferredLanguageList(); // 获取系统当前偏好语言列表 let preferredLanguageList = I18n.System.getPreferredLanguageList(); // 获取系统当前偏好语言列表
} catch(error) { } catch(error) {
console.error(`call System.getPreferredLanguageList failed, error code: ${error.code}, message: ${error.message}.`) console.error(`call System.getPreferredLanguageList failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -601,7 +601,7 @@ static getFirstPreferredLanguage(): string ...@@ -601,7 +601,7 @@ static getFirstPreferredLanguage(): string
try { try {
let firstPreferredLanguage = I18n.System.getFirstPreferredLanguage(); // 获取系统当前偏好语言列表中的第一个偏好语言 let firstPreferredLanguage = I18n.System.getFirstPreferredLanguage(); // 获取系统当前偏好语言列表中的第一个偏好语言
} catch(error) { } catch(error) {
console.error(`call System.getFirstPreferredLanguage failed, error code: ${error.code}, message: ${error.message}.`) console.error(`call System.getFirstPreferredLanguage failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -632,7 +632,7 @@ static getAppPreferredLanguage(): string ...@@ -632,7 +632,7 @@ static getAppPreferredLanguage(): string
try { try {
let appPreferredLanguage = I18n.System.getAppPreferredLanguage(); // 获取应用偏好语言 let appPreferredLanguage = I18n.System.getAppPreferredLanguage(); // 获取应用偏好语言
} catch(error) { } catch(error) {
console.error(`call System.getAppPreferredLanguage failed, error code: ${error.code}, message: ${error.message}.`) console.error(`call System.getAppPreferredLanguage failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -640,7 +640,7 @@ static getAppPreferredLanguage(): string ...@@ -640,7 +640,7 @@ static getAppPreferredLanguage(): string
static setUsingLocalDigit(flag: boolean): void static setUsingLocalDigit(flag: boolean): void
设置是否打开本地数字开关 设置系统是否使用本地数字
此接口为系统接口。 此接口为系统接口。
...@@ -667,7 +667,7 @@ static setUsingLocalDigit(flag: boolean): void ...@@ -667,7 +667,7 @@ static setUsingLocalDigit(flag: boolean): void
try { try {
I18n.System.setUsingLocalDigit(true); // 打开本地化数字开关 I18n.System.setUsingLocalDigit(true); // 打开本地化数字开关
} catch(error) { } catch(error) {
console.error(`call System.setUsingLocalDigit failed, error code: ${error.code}, message: ${error.message}.`) console.error(`call System.setUsingLocalDigit failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -675,7 +675,7 @@ static setUsingLocalDigit(flag: boolean): void ...@@ -675,7 +675,7 @@ static setUsingLocalDigit(flag: boolean): void
static getUsingLocalDigit(): boolean static getUsingLocalDigit(): boolean
获取系统当前是否打开本地数字开关 判断系统是否使用本地数字
**系统能力**:SystemCapability.Global.I18n **系统能力**:SystemCapability.Global.I18n
...@@ -698,7 +698,7 @@ static getUsingLocalDigit(): boolean ...@@ -698,7 +698,7 @@ static getUsingLocalDigit(): boolean
try { try {
let status = I18n.System.getUsingLocalDigit(); // 判断本地化数字开关是否打开 let status = I18n.System.getUsingLocalDigit(); // 判断本地化数字开关是否打开
} catch(error) { } catch(error) {
console.error(`call System.getUsingLocalDigit failed, error code: ${error.code}, message: ${error.message}.`) console.error(`call System.getUsingLocalDigit failed, error code: ${error.code}, message: ${error.message}.`);
} }
``` ```
...@@ -1025,7 +1025,7 @@ isWeekend(date?: Date): boolean ...@@ -1025,7 +1025,7 @@ isWeekend(date?: Date): boolean
| 参数名 | 类型 | 必填 | 说明 | | 参数名 | 类型 | 必填 | 说明 |
| ---- | ---- | ---- | ---------------------------------------- | | ---- | ---- | ---- | ---------------------------------------- |
| date | Date | 否 | 判断日期在日历中是否是周末。如果date没有给出,判断calendar当前日期是否为周末。 | | date | Date | 否 | 判断日期在日历中是否是周末。如果不传日期参数,则判断当前日期是否为周末。 |
**返回值:** **返回值:**
......
...@@ -48,9 +48,9 @@ constructor() ...@@ -48,9 +48,9 @@ constructor()
**示例:** **示例:**
```js ```js
// 默认构造函数使用系统当前locale创建Locale对象 // 默认构造函数使用系统当前locale创建Locale对象
let locale = new Intl.Locale() let locale = new Intl.Locale();
// 返回系统当前localel // 返回系统当前localel
let localeID = locale.toString() let localeID = locale.toString();
``` ```
...@@ -72,8 +72,8 @@ constructor(locale: string, options?: LocaleOptions) ...@@ -72,8 +72,8 @@ constructor(locale: string, options?: LocaleOptions)
**示例:** **示例:**
```js ```js
// 创建 "zh-CN" Locale对象 // 创建 "zh-CN" Locale对象
let locale = new Intl.Locale("zh-CN") let locale = new Intl.Locale("zh-CN");
let localeID = locale.toString() // localeID = "zh-CN" let localeID = locale.toString(); // localeID = "zh-CN"
``` ```
...@@ -429,7 +429,7 @@ resolvedOptions(): NumberOptions ...@@ -429,7 +429,7 @@ resolvedOptions(): NumberOptions
// 获取NumberFormat对象配置项 // 获取NumberFormat对象配置项
let options = numfmt.resolvedOptions(); let options = numfmt.resolvedOptions();
let style = options.style; // style = decimal let style = options.style; // style = decimal
let notation = options.notation // notation = scientific let notation = options.notation; // notation = scientific
``` ```
...@@ -552,7 +552,7 @@ resolvedOptions(): CollatorOptions ...@@ -552,7 +552,7 @@ resolvedOptions(): CollatorOptions
// 获取Collator对象的配置项 // 获取Collator对象的配置项
let options = collator.resolvedOptions(); let options = collator.resolvedOptions();
let usage = options.usage; // usage = "sort" let usage = options.usage; // usage = "sort"
let ignorePunctuation = options.ignorePunctuation // ignorePunctuation = true let ignorePunctuation = options.ignorePunctuation; // ignorePunctuation = true
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册