From 28a889e608c8d6b99e0d223569475e498c7d9fa0 Mon Sep 17 00:00:00 2001 From: LY Date: Wed, 8 Nov 2023 11:32:55 +0000 Subject: [PATCH 1/3] update zh-cn/application-dev/reference/apis/js-apis-i18n.md. Signed-off-by: LY --- .../reference/apis/js-apis-i18n.md | 976 ++++++++---------- 1 file changed, 443 insertions(+), 533 deletions(-) diff --git a/zh-cn/application-dev/reference/apis/js-apis-i18n.md b/zh-cn/application-dev/reference/apis/js-apis-i18n.md index fcad6c2..d4c2c0e 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-i18n.md +++ b/zh-cn/application-dev/reference/apis/js-apis-i18n.md @@ -11,902 +11,812 @@ > - 在本项目SDK中,国际化数据暂时仅支持简体中文、香港繁体、台湾繁体、美式英语、藏语、维吾尔语6种语言,其他语言支持待后续版本根据需要补充;使用非支持的语言,可能会回溯到英文特性或者返回空值。 + ## 导入模块 ```js -import I18n from '@ohos.i18n'; +import Intl from '@ohos.intl'; ``` +未正确导入包可能产生不明确的接口行为。 +## Locale -## System9+ - -### getDisplayCountry9+ -static getDisplayCountry(country: string, locale: string, sentenceCase?: boolean): string - -获取指定国家的本地化显示文本。 +### 属性 **系统能力**:SystemCapability.Global.I18n -**参数:** +| 名称 | 类型 | 可读 | 可写 | 说明 | +| --------------- | ------- | ---- | ---- | ---------------------------------------- | +| language | string | 是 | 否 | 与区域设置相关的语言,如:zh。 | +| script | string | 是 | 否 | 语言的书写方式,如:Hans。 | +| region | string | 是 | 否 | 与区域设置相关的地区,如:CN。 | +| baseName | string | 是 | 否 | Locale的基本核心信息(由语言脚本与地区组成),如:zh-Hans-CN。 | +| caseFirst | string | 是 | 否 | 区域的整理规则是否考虑大小写,取值包括:"upper", "lower", "false"。 | +| calendar | string | 是 | 否 | 区域的日历信息,取值包括:"buddhist", "chinese", "coptic","dangi", "ethioaa", "ethiopic", "gregory", "hebrew", "indian", "islamic", "islamic-umalqura", "islamic-tbla", "islamic-civil", "islamic-rgsa", "iso8601", "japanese", "persian", "roc", "islamicc"。 | +| collation | string | 是 | 否 | 区域的排序规则,取值包括:"big5han", "compat", "dict", "direct", "ducet", "eor", "gb2312", "phonebk", "phonetic", "pinyin", "reformed", "searchjl", "stroke", "trad", "unihan", "zhuyin"。 | +| hourCycle | string | 是 | 否 | 区域的时制信息,取值包括:"h12", "h23", "h11", "h24"。 | +| numberingSystem | string | 是 | 否 | 区域使用的数字系统,取值包括:"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 | 是 | 否 | 是否对数字字符具有特殊的排序规则处理。默认值:false。 | -| 参数名 | 类型 | 必填 | 说明 | -| ------------ | ------- | ---- | ---------------- | -| country | string | 是 | 指定国家。 | -| locale | string | 是 | 显示指定国家的区域ID。 | -| sentenceCase | boolean | 否 | 本地化显示文本是否要首字母大写。 | -**返回值:** - -| 类型 | 说明 | -| ------ | ------------- | -| string | 指定国家的本地化显示文本。 | +### constructor8+ -**错误码:** +constructor() -以下错误码的详细介绍请参见[ohos.i18n错误码](../errorcodes/errorcode-i18n.md)。 +创建区域对象 -| 错误码ID | 错误信息 | -| ------ | ---------------------- | -| 890001 | param value not valid | +**系统能力**:SystemCapability.Global.I18n **示例:** - ```js - try { - let displayCountry = I18n.System.getDisplayCountry("zh-CN", "en-GB"); // displayCountry = "China" - } catch(error) { - console.error(`call System.getDisplayCountry failed, error code: ${error.code}, message: ${error.message}.`); - } + ```ts + // 默认构造函数使用系统当前locale创建Locale对象 + let locale = new Intl.Locale(); + // 返回系统当前localel + let localeID = locale.toString(); ``` -### getDisplayLanguage9+ -static getDisplayLanguage(language: string, locale: string, sentenceCase?: boolean): string +### constructor + +constructor(locale: string, options?: LocaleOptions) -获取指定语言的本地化显示文本。 +创建区域对象 **系统能力**:SystemCapability.Global.I18n **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| ------------ | ------- | ---- | ---------------- | -| language | string | 是 | 指定语言。 | -| locale | string | 是 | 显示指定语言的区域ID。 | -| sentenceCase | boolean | 否 | 本地化显示文本是否要首字母大写。 | - -**返回值:** - -| 类型 | 说明 | -| ------ | ------------- | -| string | 指定语言的本地化显示文本。 | - -**错误码:** - -以下错误码的详细介绍请参见[ohos.i18n错误码](../errorcodes/errorcode-i18n.md)。 - -| 错误码ID | 错误信息 | -| ------ | ---------------------- | -| 890001 | param value not valid | +| 参数名 | 类型 | 必填 | 说明 | +| -------------------- | -------------------------------- | ---- | ---------------------------- | +| locale | string | 是 | 区域信息的字符串,由语言、脚本、国家或地区组成。 | +| options | [LocaleOptions](#localeoptions6) | 否 | 用于创建区域对象的选项。 | **示例:** - ```js - try { - let displayLanguage = I18n.System.getDisplayLanguage("zh", "en-GB"); // displayLanguage = Chinese - } catch(error) { - console.error(`call System.getDisplayLanguage failed, error code: ${error.code}, message: ${error.message}.`); - } + ```ts + // 创建 "zh-CN" Locale对象 + let locale = new Intl.Locale("zh-CN"); + let localeID = locale.toString(); // localeID = "zh-CN" ``` -### getSystemLanguage9+ - -static getSystemLanguage(): string - -获取系统语言。 - -**系统能力**:SystemCapability.Global.I18n - -**返回值:** -| 类型 | 说明 | -| ------ | ------- | -| string | 系统语言ID。 | +### toString -**错误码:** +toString(): string -以下错误码的详细介绍请参见[ohos.i18n错误码](../errorcodes/errorcode-i18n.md)。 - -| 错误码ID | 错误信息 | -| ------ | ---------------------- | -| 890001 | param value not valid | - -**示例:** - ```js - try { - let systemLanguage = I18n.System.getSystemLanguage(); // systemLanguage为当前系统语言 - } catch(error) { - console.error(`call System.getSystemLanguage failed, error code: ${error.code}, message: ${error.message}.`); - } - ``` - -### getSystemRegion9+ - -static getSystemRegion(): string - -获取系统地区。 +获取区域对象的字符串表示 **系统能力**:SystemCapability.Global.I18n **返回值:** -| 类型 | 说明 | -| ------ | ------- | -| string | 系统地区ID。 | - -**错误码:** - -以下错误码的详细介绍请参见[ohos.i18n错误码](../errorcodes/errorcode-i18n.md)。 - -| 错误码ID | 错误信息 | -| ------ | ---------------------- | -| 890001 | param value not valid | +| 类型 | 说明 | +| ------ | ----------- | +| string | 区域对象的字符串表示。 | **示例:** - ```js - try { - let systemRegion = I18n.System.getSystemRegion(); // 获取系统当前地区设置 - } catch(error) { - console.error(`call System.getSystemRegion failed, error code: ${error.code}, message: ${error.message}.`); - } + ```ts + // 创建 "en-GB" Locale对象 + let locale = new Intl.Locale("en-GB"); + let localeID = locale.toString(); // localeID = "en-GB" ``` -### getSystemLocale9+ -static getSystemLocale(): string +### maximize + +maximize(): Locale -获取系统区域。 +最大化区域信息,若缺少脚本与地区信息,则补齐。 **系统能力**:SystemCapability.Global.I18n **返回值:** -| 类型 | 说明 | -| ------ | ------- | -| string | 系统区域ID。 | - -**错误码:** - -以下错误码的详细介绍请参见[ohos.i18n错误码](../errorcodes/errorcode-i18n.md)。 - -| 错误码ID | 错误信息 | -| ------ | ---------------------- | -| 890001 | param value not valid | +| 类型 | 说明 | +| ----------------- | ---------- | +| [Locale](#locale) | 最大化后的区域对象。 | **示例:** - ```js - try { - let systemLocale = I18n.System.getSystemLocale(); // 获取系统当前Locale - } catch(error) { - console.error(`call System.getSystemLocale failed, error code: ${error.code}, message: ${error.message}.`); - } + ```ts + // 创建 "zh" Locale对象 + let locale = new Intl.Locale("zh"); + // 补齐Locale对象的脚本和地区 + let maximizedLocale = locale.maximize(); + let localeID = maximizedLocale.toString(); // localeID = "zh-Hans-CN" + + // 创建 "en-US" Locale对象 + locale = new Intl.Locale("en-US"); + // 补齐Locale对象的脚本 + maximizedLocale = locale.maximize(); + localeID = maximizedLocale.toString(); // localeID = "en-Latn-US" ``` -### is24HourClock9+ -static is24HourClock(): boolean +### minimize + +minimize(): Locale -判断系统时间是否为24小时制。 +最小化区域信息,若包含脚本与地区信息,则去除。 **系统能力**:SystemCapability.Global.I18n **返回值:** -| 类型 | 说明 | -| ------- | ---------------------------------------- | -| boolean | 返回true,表示系统24小时开关开启;返回false,表示系统24小时开关关闭。 | - -**错误码:** - -以下错误码的详细介绍请参见[ohos.i18n错误码](../errorcodes/errorcode-i18n.md)。 - -| 错误码ID | 错误信息 | -| ------ | ---------------------- | -| 890001 | param value not valid | +| 类型 | 说明 | +| ----------------- | ---------- | +| [Locale](#locale) | 最小化后的区域对象。 | **示例:** - ```js - try { - let is24HourClock = I18n.System.is24HourClock(); // 系统24小时开关是否开启 - } catch(error) { - console.error(`call System.is24HourClock failed, error code: ${error.code}, message: ${error.message}.`); - } + ```ts + // 创建 "zh-Hans-CN" Locale对象 + let locale = new Intl.Locale("zh-Hans-CN"); + // 去除Locale对象的脚本和地区 + let minimizedLocale = locale.minimize(); + let localeID = minimizedLocale.toString(); // localeID = "zh" + + // 创建 "en-US" Locale对象 + locale = new Intl.Locale("en-US"); + // 去除Locale对象的地区 + minimizedLocale = locale.minimize(); + localeID = minimizedLocale.toString(); // localeID = "en" ``` -## I18n.isRTL7+ -isRTL(locale: string): boolean +## LocaleOptions6+ -获取该区域是否为从右至左显示语言。 +表示区域初始化选项。 +从API9开始,LocaleOptions中的属性改为可选。 **系统能力**:SystemCapability.Global.I18n -**参数:** +| 名称 | 类型 | 可读 | 可写 | 说明 | +| --------------- | ------- | ---- | ---- | ---------------------------------------- | +| calendar | string | 是 | 是 | 日历参数,如:"buddhist", "chinese", "coptic", "dangi", "ethioaa", "ethiopic", "gregory", "hebrew", "indian", "islamic", "islamic-umalqura", "islamic-tbla", "islamic-civil", "islamic-rgsa", "iso8601", "japanese", "persian", "roc", "islamicc"。 | +| collation | string | 是 | 是 | 排序参数,取值包括:"big5han", "compat", "dict", "direct", "ducet", "emoji", "eor", "gb2312", "phonebk", "phonetic", "pinyin", "reformed ", "search", "searchjl", "standard", "stroke", "trad", "unihan", "zhuyin"。 | +| hourCycle | string | 是 | 是 | 时制格式,取值包括:"h11", "h12", "h23", "h24"。 | +| numberingSystem | string | 是 | 是 | 数字系统,取值包括:"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 | 是 | 是 | 是否使用12小时制。默认值:false。 | +| caseFirst | string | 是 | 是 | 表示大写、小写的排序顺序,取值范围:"upper", "lower", "false"。 | -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ------ | ---- | ------- | -| locale | string | 是 | 指定区域ID。 | -**返回值:** +## DateTimeFormat -| 类型 | 说明 | -| ------- | ---------------------------------------- | -| boolean | true表示该locale从右至左显示语言;false表示该locale从左至右显示语言。 | -**示例:** - ```js - I18n.isRTL("zh-CN");// 中文不是RTL语言,返回false - I18n.isRTL("ar-EG");// 阿语是RTL语言,返回true - ``` - -## I18n.getCalendar8+ +### constructor8+ -getCalendar(locale: string, type? : string): Calendar +constructor() -获取日历对象。 +创建时间日期格式化对象。 **系统能力**:SystemCapability.Global.I18n -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ------ | ---- | ---------------------------------------- | -| locale | string | 是 | 合法的locale值,例如zh-Hans-CN。 | -| type | string | 否 | 合法的日历类型,目前合法的类型有buddhist, chinese, coptic, ethiopic, hebrew, gregory, indian, islamic_civil, islamic_tbla, islamic_umalqura, japanese, persian。当type没有给出时,采用区域默认的日历类型。 | - -**返回值:** - -| 类型 | 说明 | -| ---------------------- | ----- | -| [Calendar](#calendar8) | 日历对象。 | - **示例:** - ```js - I18n.getCalendar("zh-Hans", "chinese"); // 获取中国农历日历对象 + ```ts + // 使用系统当前locale创建DateTimeFormat对象 + let datefmt= new Intl.DateTimeFormat(); ``` -## Calendar8+ - - -### setTime8+ +### constructor -setTime(date: Date): void +constructor(locale: string | Array<string>, options?: DateTimeOptions) -设置日历对象内部的时间日期。 +创建时间日期格式化对象。 **系统能力**:SystemCapability.Global.I18n **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| ---- | ---- | ---- | ----------------- | -| date | Date | 是 | 将要设置的日历对象的内部时间日期。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------------------- | ------------------------------------ | ---- | ---------------------------- | +| locale | string \| Array<string> | 是 | 包含区域设置信息的字符串,包括语言以及可选的脚本和区域。 | +| options | [DateTimeOptions](#datetimeoptions6) | 否 | 用于创建时间日期格式化的选项。若所有选项均未设置时,year、month、day三个属性的默认值为numeric。 | **示例:** - ```js - let calendar = I18n.getCalendar("en-US", "gregory"); - let date = new Date(2021, 10, 7, 8, 0, 0, 0); - calendar.setTime(date); + ```ts + // 使用 "zh-CN" locale创建DateTimeFormat对象,日期风格为full,时间风格为medium + let datefmt= new Intl.DateTimeFormat("zh-CN", { dateStyle: 'full', timeStyle: 'medium' }); ``` -### setTime8+ - -setTime(time: number): void - -设置日历对象内部的时间日期, time为从1970.1.1 00:00:00 GMT逝去的毫秒数。 - -**系统能力**:SystemCapability.Global.I18n - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ---- | ------ | ---- | ---------------------------------------- | -| time | number | 是 | time为从1970.1.1 00:00:00 GMT逝去的毫秒数。 | - **示例:** - ```js - let calendar = I18n.getCalendar("en-US", "gregory"); - calendar.setTime(10540800000); + ```ts + // 使用 ["ban", "zh"] locale列表创建DateTimeFormat对象,因为ban为非法LocaleID,因此使用zh Locale创建DateTimeFormat对象 + let datefmt= new Intl.DateTimeFormat(["ban", "zh"], { dateStyle: 'full', timeStyle: 'medium' }); ``` -### set8+ +### format -set(year: number, month: number, date:number, hour?: number, minute?: number, second?: number): void +format(date: Date): string -设置日历对象的年、月、日、时、分、秒。 +格式化时间日期字符串。 **系统能力**:SystemCapability.Global.I18n **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ------ | ---- | ------ | -| year | number | 是 | 设置的年。 | -| month | number | 是 | 设置的月。 | -| date | number | 是 | 设置的日。 | -| hour | number | 否 | 设置的小时。 | -| minute | number | 否 | 设置的分钟。 | -| second | number | 否 | 设置的秒。 | +| 参数名 | 类型 | 必填 | 说明 | +| ---- | ---- | ---- | ------- | +| date | Date | 是 | 时间日期对象。 | + +**返回值:** + +| 类型 | 说明 | +| ------ | ------------ | +| string | 格式化后的时间日期字符串 | **示例:** - ```js - let calendar = I18n.getCalendar("zh-Hans"); - calendar.set(2021, 10, 1, 8, 0, 0); // set time to 2021.10.1 08:00:00 + ```ts + let date = new Date(2021, 11, 17, 3, 24, 0); + // 使用 en-GB locale创建DateTimeFormat对象 + let datefmt = new Intl.DateTimeFormat("en-GB"); + let formattedDate = datefmt.format(date); // formattedDate "17/12/2021" + + // 使用 en-GB locale创建DateTimeFormat对象,dateStyle设置为full,timeStyle设置为medium + datefmt = new Intl.DateTimeFormat("en-GB", { dateStyle: 'full', timeStyle: 'medium' }); + formattedDate = datefmt.format(date); // formattedDate "Friday, 17 December 2021 at 03:24:00" ``` -### setTimeZone8+ +### formatRange -setTimeZone(timezone: string): void +formatRange(startDate: Date, endDate: Date): string -设置日历对象的时区。 +格式化时间日期段字符串。 **系统能力**:SystemCapability.Global.I18n **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------ | ---- | ------------------------- | -| timezone | string | 是 | 设置的时区id,如“Asia/Shanghai”。 | - -**示例:** - ```js - let calendar = I18n.getCalendar("zh-Hans"); - calendar.setTimeZone("Asia/Shanghai"); - ``` - - -### getTimeZone8+ - -getTimeZone(): string - -获取日历对象的时区。 - -**系统能力**:SystemCapability.Global.I18n +| 参数名 | 类型 | 必填 | 说明 | +| --------- | ---- | ---- | -------- | +| startDate | Date | 是 | 起始的时间日期。 | +| endDate | Date | 是 | 结束的时间日期。 | **返回值:** -| 类型 | 说明 | -| ------ | ---------- | -| string | 日历对象的时区id。 | +| 类型 | 说明 | +| ------ | -------------- | +| string | 格式化后的时间日期段字符串。 | **示例:** - ```js - let calendar = I18n.getCalendar("zh-Hans"); - calendar.setTimeZone("Asia/Shanghai"); - let timezone = calendar.getTimeZone(); // timezone = "Asia/Shanghai" + ```ts + let startDate = new Date(2021, 11, 17, 3, 24, 0); + let endDate = new Date(2021, 11, 18, 3, 24, 0); + // 使用 en-GB locale创建DateTimeFormat对象 + let datefmt = new Intl.DateTimeFormat("en-GB"); + let formattedDateRange = datefmt.formatRange(startDate, endDate); // formattedDateRange = "17/12/2021-18/12/2021" ``` -### getFirstDayOfWeek8+ +### resolvedOptions -getFirstDayOfWeek(): number +resolvedOptions(): DateTimeOptions -获取日历对象的一周起始日。 +获取DateTimeFormat对象的格式化选项。 **系统能力**:SystemCapability.Global.I18n **返回值:** -| 类型 | 说明 | -| ------ | --------------------- | -| number | 获取一周的起始日,1代表周日,7代表周六。 | +| 类型 | 说明 | +| ------------------------------------ | ----------------------------- | +| [DateTimeOptions](#datetimeoptions6) | DateTimeFormat 对象的格式化选项。 | **示例:** - ```js - let calendar = I18n.getCalendar("en-US", "gregory"); - let firstDayOfWeek = calendar.getFirstDayOfWeek(); // firstDayOfWeek = 1 + ```ts + let datefmt = new Intl.DateTimeFormat("en-GB", { dateStyle: 'full', timeStyle: 'medium' }); + // 返回DateTimeFormat对象的配置项 + let options = datefmt.resolvedOptions(); + let dateStyle = options.dateStyle; // dateStyle = "full" + let timeStyle = options.timeStyle; // timeStyle = "medium" ``` -### setFirstDayOfWeek8+ +## DateTimeOptions6+ -setFirstDayOfWeek(value: number): void - -设置每一周的起始日。 +表示时间日期格式化选项。 +从API9开始,DateTimeOptions中的属性改为可选。 **系统能力**:SystemCapability.Global.I18n -**参数:** +| 名称 | 类型 | 可读 | 可写 | 说明 | +| --------------- | ------- | ---- | ---- | ---------------------------------------- | +| locale | string | 是 | 否 | 区域参数, 如:zh-Hans-CN。 | +| dateStyle | string | 是 | 是 | 日期显示格式,取值包括:"long", "short", "medium", "full"。 | +| timeStyle | string | 是 | 是 | 时间显示格式,取值包括:"long", "short", "medium", "full"。 | +| hourCycle | string | 是 | 是 | 时制格式,取值包括:"h11", "h12", "h23", "h24"。 | +| timeZone | string | 是 | 是 | 使用的时区(合法的IANA时区ID)。 | +| numberingSystem | string | 是 | 是 | 数字系统,取值包括:"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"。 | +| hour12 | boolean | 是 | 是 | 是否使用12小时制。若hour12和hourCycle未设置且系统24小时开关打开时,hour12属性的默认值为false。 | +| weekday | string | 是 | 是 | 工作日的显示格式,取值包括:"long", "short", "narrow"。 | +| era | string | 是 | 是 | 时代的显示格式,取值包括:"long", "short", "narrow"。 | +| year | string | 是 | 是 | 年份的显示格式,取值包括:"numeric", "2-digit"。 | +| month | string | 是 | 是 | 月份的显示格式,取值包括:"numeric", "2-digit", "long", "short", "narrow"。 | +| day | string | 是 | 是 | 日期的显示格式,取值包括:"numeric", "2-digit"。 | +| hour | string | 是 | 是 | 小时的显示格式,取值包括:"numeric", "2-digit"。 | +| minute | string | 是 | 是 | 分钟的显示格式,取值包括:"numeric", "2-digit"。 | +| second | string | 是 | 是 | 秒钟的显示格式,取值包括:"numeric", "2-digit"。 | +| timeZoneName | string | 是 | 是 | 时区名称的本地化表示。 | +| dayPeriod | string | 是 | 是 | 时段的显示格式,取值包括:"long", "short", "narrow"。 | +| localeMatcher | string | 是 | 是 | 要使用的区域匹配算法,取值包括:"lookup", "best fit"。 | +| formatMatcher | string | 是 | 是 | 要使用的格式匹配算法,取值包括:"basic", "best fit"。 | -| 参数名 | 类型 | 必填 | 说明 | -| ----- | ------ | ---- | --------------------- | -| value | number | 是 | 设置一周的起始日,1代表周日,7代表周六。 | -**示例:** - ```js - let calendar = I18n.getCalendar("zh-Hans"); - calendar.setFirstDayOfWeek(3); - let firstDayOfWeek = calendar.getFirstDayOfWeek(); // firstDayOfWeek = 3 - ``` +## NumberFormat -### getMinimalDaysInFirstWeek8+ +### constructor8+ -getMinimalDaysInFirstWeek(): number +constructor() -获取一年中第一周的最小天数。 +创建数字格式化对象。 **系统能力**:SystemCapability.Global.I18n -**返回值:** - -| 类型 | 说明 | -| ------ | ------------ | -| number | 一年中第一周的最小天数。 | - **示例:** - ```js - let calendar = I18n.getCalendar("zh-Hans"); - let minimalDaysInFirstWeek = calendar.getMinimalDaysInFirstWeek(); // minimalDaysInFirstWeek = 1 + ```ts + // 使用系统当前locale创建NumberFormat对象 + let numfmt = new Intl.NumberFormat(); ``` -### setMinimalDaysInFirstWeek8+ +### constructor -setMinimalDaysInFirstWeek(value: number): void +constructor(locale: string | Array<string>, options?: NumberOptions) -设置一年中第一周的最小天数。 +创建数字格式化对象。 **系统能力**:SystemCapability.Global.I18n **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| ----- | ------ | ---- | ------------ | -| value | number | 是 | 一年中第一周的最小天数。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------------------- | -------------------------------- | ---- | ---------------------------- | +| locale | string \| Array<string> | 是 | 包含区域设置信息的字符串,包括语言以及可选的脚本和区域。 | +| options | [NumberOptions](#numberoptions6) | 否 | 用于创建数字格式化的选项。 | **示例:** - ```js - let calendar = I18n.getCalendar("zh-Hans"); - calendar.setMinimalDaysInFirstWeek(3); - let minimalDaysInFirstWeek = calendar.getMinimalDaysInFirstWeek(); // minimalDaysInFirstWeek = 3 + ```ts + // 使用 en-GB locale创建NumberFormat对象,style设置为decimal,notation设置为scientific + let numfmt = new Intl.NumberFormat("en-GB", {style:'decimal', notation:"scientific"}); ``` -### get8+ +### format -get(field: string): number +format(number: number): string; -获取日历对象中与field相关联的值。 +格式化数字字符串。 **系统能力**:SystemCapability.Global.I18n **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| ----- | ------ | ---- | ---------------------------------------- | -| field | string | 是 | 通过field来获取日历对象相应的值。目前支持的field值有 era, year, month, week_of_year, week_of_month, date, day_of_year, day_of_week, day_of_week_in_month, hour, hour_of_day, minute, second, millisecond, zone_offset, dst_offset, year_woy, dow_local, extended_year, julian_day, milliseconds_in_day, is_leap_month。 | +| 参数名 | 类型 | 必填 | 说明 | +| ------ | ------ | ---- | ---- | +| number | number | 是 | 数字对象 | **返回值:** -| 类型 | 说明 | -| ------ | ---------------------------------------- | -| number | 与field相关联的值,如当前Calendar对象的内部日期的年份为1990,get("year")返回1990。 | +| 类型 | 说明 | +| ------ | ---------- | +| string | 格式化后的数字字符串 | + **示例:** - ```js - let calendar = I18n.getCalendar("zh-Hans"); - calendar.set(2021, 10, 1, 8, 0, 0); // set time to 2021.10.1 08:00:00 - let hourOfDay = calendar.get("hour_of_day"); // hourOfDay = 8 + ```ts + // 使用 ["en-GB", "zh"] locale列表创建NumberFormat对象,因为en-GB为合法LocaleID,因此使用en-GB创建NumberFormat对象 + let numfmt = new Intl.NumberFormat(["en-GB", "zh"], {style:'decimal', notation:"scientific"}); + let formattedNumber = numfmt.format(1223); // formattedNumber = 1.223E3 ``` -### isWeekend8+ +### resolvedOptions -isWeekend(date?: Date): boolean +resolvedOptions(): NumberOptions -判断给定的日期是否在日历中是周末。 +获取NumberFormat 对象的格式化选项。 **系统能力**:SystemCapability.Global.I18n -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ---- | ---- | ---- | ---------------------------------------- | -| date | Date | 否 | 判断日期在日历中是否是周末。如果不传日期参数,则判断当前日期是否为周末。 | - **返回值:** -| 类型 | 说明 | -| ------- | ----------------------------------- | -| boolean | 当所判断的日期为周末时,返回 true,否则返回false。 | +| 类型 | 说明 | +| -------------------------------- | --------------------------- | +| [NumberOptions](#numberoptions6) | NumberFormat 对象的格式化选项。 | + **示例:** - ```js - let calendar = I18n.getCalendar("zh-Hans"); - calendar.set(2021, 11, 11, 8, 0, 0); // set time to 2021.11.11 08:00:00 - calendar.isWeekend(); // false - let date = new Date(2011, 11, 6, 9, 0, 0); - calendar.isWeekend(date); // true + ```ts + let numfmt = new Intl.NumberFormat(["en-GB", "zh"], {style:'decimal', notation:"scientific"}); + // 获取NumberFormat对象配置项 + let options = numfmt.resolvedOptions(); + let style = options.style; // style = decimal + let notation = options.notation; // notation = scientific ``` -## I18n.getTimeZone7+ +## NumberOptions6+ -getTimeZone(zoneID?: string): TimeZone - -获取时区ID对应的时区对象。 +表示设备支持的能力。 +从API9开始,NumberOptions中的属性改为可选。 **系统能力**:SystemCapability.Global.I18n -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ------ | ---- | ----- | -| zondID | string | 否 | 时区ID。 | - -**返回值:** - -| 类型 | 说明 | -| -------- | ------------ | -| TimeZone | 时区ID对应的时区对象。 | - -**示例:** - ```js - let timezone = I18n.getTimeZone(); - ``` +| 名称 | 类型 | 可读 | 可写 | 说明 | +| ------------------------ | ------- | ---- | ---- | ---------------------------------------- | +| locale | string | 是 | 否 | 区域参数, 如:"zh-Hans-CN"。locale属性默认值为系统Locale。 | +| currency | string | 是 | 是 | 货币单位, 如:"EUR","CNY","USD"等。 | +| currencySign | string | 是 | 是 | 货币单位的符号显示,取值包括: "standard","accounting"。currencySign属性默认值为standard。 | +| currencyDisplay | string | 是 | 是 | 货币的显示方式,取值包括:"symbol", "narrowSymbol", "code", "name"。currencyDisplay属性默认值为symbol。 | +| unit | string | 是 | 是 | 单位名称,如:"meter","inch",“hectare”等。 | +| unitDisplay | string | 是 | 是 | 单位的显示格式,取值包括:"long", "short", "narrow"。unitDisplay属性默认值为short。 | +| unitUsage8+ | string | 是 | 是 | 单位的使用场景,取值包括:"default", "area-land-agricult", "area-land-commercl", "area-land-residntl", "length-person", "length-person-small", "length-rainfall", "length-road", "length-road-small", "length-snowfall", "length-vehicle", "length-visiblty", "length-visiblty-small", "length-person-informal", "length-person-small-informal", "length-road-informal", "speed-road-travel", "speed-wind", "temperature-person", "temperature-weather", "volume-vehicle-fuel"。unitUsage属性默认值为default。 | +| signDisplay | string | 是 | 是 | 数字符号的显示格式,取值包括:"auto", "never", "always", "expectZero"。signDisplay属性默认值为auto。 | +| compactDisplay | string | 是 | 是 | 紧凑型的显示格式,取值包括:"long", "short"。compactDisplay属性默认值为short。 | +| notation | string | 是 | 是 | 数字的格式化规格,取值包括:"standard", "scientific", "engineering", "compact"。notation属性默认值为standard。 | +| localeMatcher | string | 是 | 是 | 要使用的区域匹配算法,取值包括:"lookup", "best fit"。localeMatcher属性默认值为best fit。 | +| style | string | 是 | 是 | 数字的显示格式,取值包括:"decimal", "currency", "percent", "unit"。style属性默认值为decimal。 | +| numberingSystem | string | 是 | 是 | 数字系统,取值包括:"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属性默认值为locale的默认数字系统。 | +| useGrouping | boolean | 是 | 是 | 是否分组显示。useGrouping属性默认值为auto。 | +| minimumIntegerDigits | number | 是 | 是 | 表示要使用的最小整数位数,取值范围:1~21。minimumIntegerDigits属性默认值为1。 | +| minimumFractionDigits | number | 是 | 是 | 表示要使用的最小分数位数,取值范围:0~20。minimumFractionDigits属性默认值为0。 | +| maximumFractionDigits | number | 是 | 是 | 表示要使用的最大分数位数,取值范围:1~21。maximumFractionDigits属性默认值为3。 | +| minimumSignificantDigits | number | 是 | 是 | 表示要使用的最低有效位数,取值范围:1~21。minimumSignificantDigits属性默认值为1。 | +| maximumSignificantDigits | number | 是 | 是 | 表示要使用的最大有效位数,取值范围:1~21。maximumSignificantDigits属性默认值为21。 | -## TimeZone +## Collator8+ -### getID +### constructor8+ -getID(): string +constructor() -获取时区对象的ID。 +创建排序对象。 **系统能力**:SystemCapability.Global.I18n -**返回值:** - -| 类型 | 说明 | -| ------ | ------------ | -| string | 时区对象对应的时区ID。 | - **示例:** - ```js - let timezone = I18n.getTimeZone(); - let timezoneID = timezone.getID(); // timezoneID = "Asia/Shanghai" + ```ts + // 使用系统locale创建Collator对象 + let collator = new Intl.Collator(); ``` -### getRawOffset +### constructor8+ -getRawOffset(): number +constructor(locale: string | Array<string>, options?: CollatorOptions) -获取时区对象表示的时区与UTC时区的偏差。 +创建排序对象。 **系统能力**:SystemCapability.Global.I18n -**返回值:** +**参数:** -| 类型 | 说明 | -| ------ | ------------------- | -| number | 时区对象表示的时区与UTC时区的偏差。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------------------- | ------------------------------------ | ---- | ---------------------------- | +| locale | string \| Array<string> | 是 | 包含区域设置信息的字符串,包括语言以及可选的脚本和区域。 | +| options | [CollatorOptions](#collatoroptions8) | 否 | 用于创建排序对象的选项。 | **示例:** - ```js - let timezone = I18n.getTimeZone(); - let offset = timezone.getRawOffset(); // offset = 28800000 + ```ts + // 使用 zh-CN locale创建Collator对象,localeMatcher设置为lookup,usage设置为sort + let collator = new Intl.Collator("zh-CN", {localeMatcher: "lookup", usage: "sort"}); ``` -### getOffset +### compare8+ -getOffset(date?: number): number +compare(first: string, second: string): number -获取某一时刻时区对象表示的时区与UTC时区的偏差。 +依据Collator的排序策略对两个字符串进行比较。 **系统能力**:SystemCapability.Global.I18n +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ------ | ------ | ---- | ------------ | +| first | string | 是 | 进行比较第一个字符串。 | +| second | string | 是 | 进行比较的第二个字符串。 | + **返回值:** -| 类型 | 说明 | -| ------ | ----------------------- | -| number | 某一时刻时区对象表示的时区与UTC时区的偏差。 | +| 类型 | 说明 | +| ------ | ---------------------------------------- | +| number | 比较结果。当number为负数,表示first排序在second之前;当number为0,表示first与second排序相同;当number为正数,表示first排序在second之后。 | **示例:** - ```js - let timezone = I18n.getTimeZone(); - let offset = timezone.getOffset(1234567890); // offset = 28800000 + ```ts + // 使用en-GB locale创建Collator对象 + let collator = new Intl.Collator("en-GB"); + // 比较 "first" 和 "second" 的先后顺序 + let compareResult = collator.compare("first", "second"); // compareResult = -1 ``` -### getAvailableIDs9+ +### resolvedOptions8+ -static getAvailableIDs(): Array<string> +resolvedOptions(): CollatorOptions -获取系统支持的时区ID。 +返回Collator对象的属性。 **系统能力**:SystemCapability.Global.I18n **返回值:** -| 类型 | 说明 | -| ------------------- | ----------- | -| Array<string> | 系统支持的时区ID列表 | +| 类型 | 说明 | +| ------------------------------------ | ----------------- | +| [CollatorOptions](#collatoroptions8) | 返回的Collator对象的属性。 | **示例:** ```ts - // ids = ["America/Adak", "America/Anchorage", "America/Bogota", "America/Denver", "America/Los_Angeles", "America/Montevideo", "America/Santiago", "America/Sao_Paulo", "Asia/Ashgabat", "Asia/Hovd", "Asia/Jerusalem", "Asia/Magadan", "Asia/Omsk", "Asia/Shanghai", "Asia/Tokyo", "Asia/Yerevan", "Atlantic/Cape_Verde", "Australia/Lord_Howe", "Europe/Dublin", "Europe/London", "Europe/Moscow", "Pacific/Auckland", "Pacific/Easter", "Pacific/Pago-Pago"], 当前共支持24个时区 - let ids = I18n.TimeZone.getAvailableIDs(); + let collator = new Intl.Collator("zh-Hans", { usage: 'sort', ignorePunctuation: true }); + // 获取Collator对象的配置项 + let options = collator.resolvedOptions(); + let usage = options.usage; // usage = "sort" + let ignorePunctuation = options.ignorePunctuation; // ignorePunctuation = true ``` -## Unicode9+ +## CollatorOptions8+ +表示Collator可设置的属性。 +从API9中,CollatorOptions中的属性改为可选。 -### isDigit9+ +**系统能力**:SystemCapability.Global.I18n -static isDigit(char: string): boolean +| 名称 | 类型 | 可读 | 可写 | 说明 | +| ----------------- | ------- | ---- | ---- | ---------------------------------------- | +| localeMatcher | string | 是 | 是 | locale匹配算法,取值范围:"best fit", "lookup"。localeMatcher属性默认值为best fit。 | +| usage | string | 是 | 是 | 比较的用途,取值范围:"sort", "search"。usage属性默认值为sort。 | +| sensitivity | string | 是 | 是 | 表示字符串中的哪些差异会导致非零结果值,取值范围:"base", "accent", "case", "letiant"。sensitivity属性默认值为variant。 | +| ignorePunctuation | boolean | 是 | 是 | 表示是否忽略标点符号,取值范围:true, false。ignorePunctuation属性默认值为false。 | +| collation | string | 是 | 是 | 排序规则,取值范围:"big5han", "compat", "dict", "direct", "ducet", "eor", "gb2312", "phonebk", "phonetic", "pinyin", "reformed", "searchjl", "stroke", "trad", "unihan", "zhuyin"。collation属性默认值为default。 | +| numeric | boolean | 是 | 是 | 是否使用数字排序,取值范围:true, false。numeric属性默认值为false。 | +| caseFirst | string | 是 | 是 | 表示大写、小写的排序顺序,取值范围:"upper", "lower", "false"。caseFirst属性默认值为false | -判断字符串char是否是数字。 -**系统能力**:SystemCapability.Global.I18n +## PluralRules8+ -**参数:** -| 参数名 | 类型 | 必填 | 说明 | -| ---- | ------ | ---- | ----- | -| char | string | 是 | 输入字符。 | +### constructor8+ -**返回值:** +constructor() + +创建单复数对象来计算数字的单复数类别。 -| 类型 | 说明 | -| ------- | ------------------------------------ | -| boolean | 返回true表示输入的字符是数字,返回false表示输入的字符不是数字。 | +**系统能力**:SystemCapability.Global.I18n **示例:** - ```js - let isdigit = I18n.Unicode.isDigit("1"); // isdigit = true + ```ts + // 使用系统locale创建PluralRules对象 + let pluralRules = new Intl.PluralRules(); ``` -### isSpaceChar9+ +### constructor8+ -static isSpaceChar(char: string): boolean +constructor(locale: string | Array<string>, options?: PluralRulesOptions) -判断字符串char是否是空格符。 +创建单复数对象来计算数字的单复数类别。 **系统能力**:SystemCapability.Global.I18n **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| ---- | ------ | ---- | ----- | -| char | string | 是 | 输入字符。 | - -**返回值:** - -| 类型 | 说明 | -| ------- | -------------------------------------- | -| boolean | 返回true表示输入的字符是空格符,返回false表示输入的字符不是空格符。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------------------- | ---------------------------------------- | ---- | ---------------------------- | +| locale | string \| Array<string> | 是 | 包含区域设置信息的字符串,包括语言以及可选的脚本和区域。 | +| options | [PluralRulesOptions](#pluralrulesoptions8) | 否 | 用于创建单复数对象的选项。 | **示例:** - ```js - let isspacechar = I18n.Unicode.isSpaceChar("a"); // isspacechar = false + ```ts + // 使用 zh-CN locale创建PluralRules对象,localeMatcher设置为lookup,type设置为cardinal + let pluralRules= new Intl.PluralRules("zh-CN", {"localeMatcher": "lookup", "type": "cardinal"}); ``` -### isWhitespace9+ +### select8+ -static isWhitespace(char: string): boolean +select(n: number): string -判断字符串char是否是空白符。 +返回一个字符串表示该数字的单复数类别。 **系统能力**:SystemCapability.Global.I18n **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| ---- | ------ | ---- | ----- | -| char | string | 是 | 输入字符。 | +| 参数名 | 类型 | 必填 | 说明 | +| ---- | ------ | ---- | ------------ | +| n | number | 是 | 待获取单复数类别的数字。 | **返回值:** -| 类型 | 说明 | -| ------- | -------------------------------------- | -| boolean | 返回true表示输入的字符是空白符,返回false表示输入的字符不是空白符。 | +| 类型 | 说明 | +| ------ | ---------------------------------------- | +| string | 单复数类别,取值包括:"zero","one","two", "few", "many", "others"。 | **示例:** - ```js - let iswhitespace = I18n.Unicode.isWhitespace("a"); // iswhitespace = false - ``` + ```ts + // 使用 zh-Hans locale创建PluralRules对象 + let zhPluralRules = new Intl.PluralRules("zh-Hans"); + // 计算 zh-Hans locale中数字1对应的单复数类别 + let plural = zhPluralRules.select(1); // plural = other + // 使用 en-US locale创建PluralRules对象 + let enPluralRules = new Intl.PluralRules("en-US"); + // 计算 en-US locale中数字1对应的单复数类别 + plural = enPluralRules.select(1); // plural = one + ``` -### isRTL9+ -static isRTL(char: string): boolean +## PluralRulesOptions8+ -判断字符串char是否是从右到左语言的字符。 +表示PluralRules对象可设置的属性。 +从API9开始,PluralRulesOptions中的属性改为可选。 **系统能力**:SystemCapability.Global.I18n -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ---- | ------ | ---- | ----- | -| char | string | 是 | 输入字符。 | +| 名称 | 类型 | 可读 | 可写 | 说明 | +| ------------------------ | ------ | ---- | ---- | ---------------------------------------- | +| localeMatcher | string | 是 | 是 | locale匹配算法,取值包括:"best fit", "lookup"。localeMatcher属性默认值为best fit。 | +| type | string | 是 | 是 | 排序的类型,取值包括:"cardinal", "ordinal"。type属性默认值为cardinal。 | +| minimumIntegerDigits | number | 是 | 是 | 表示要使用的最小整数位数,取值范围:1~21。minimumIntegerDigits属性默认值为1。 | +| minimumFractionDigits | number | 是 | 是 | 表示要使用的最小分数位数,取值范围:0~20。minimumFractionDigits属性默认值为0。 | +| maximumFractionDigits | number | 是 | 是 | 表示要使用的最大分数位数,取值范围:1~21。maximumFractionDigits属性默认值为3。 | +| minimumSignificantDigits | number | 是 | 是 | 表示要使用的最低有效位数,取值范围:1~21。minimumSignificantDigits属性默认值为1。 | +| maximumSignificantDigits | number | 是 | 是 | 表示要使用的最大有效位数,取值范围:1~21。maximumSignificantDigits属性默认值为21。 | -**返回值:** - -| 类型 | 说明 | -| ------- | ---------------------------------------- | -| boolean | 返回true表示输入的字符是从右到左语言的字符,返回false表示输入的字符不是从右到左语言的字符。 | -**示例:** - ```js - let isrtl = I18n.Unicode.isRTL("a"); // isrtl = false - ``` +## RelativeTimeFormat8+ -### isIdeograph9+ +### constructor8+ -static isIdeograph(char: string): boolean +constructor() -判断字符串char是否是表意文字。 +创建相对时间格式化对象。 **系统能力**:SystemCapability.Global.I18n -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ---- | ------ | ---- | ----- | -| char | string | 是 | 输入字符。 | - -**返回值:** - -| 类型 | 说明 | -| ------- | ---------------------------------------- | -| boolean | 返回true表示输入的字符是表意文字,返回false表示输入的字符不是表意文字。 | - **示例:** - ```js - let isideograph = I18n.Unicode.isIdeograph("a"); // isideograph = false + ```ts + // 使用系统locale创建RelativeTimeFormat对象 + let relativetimefmt = new Intl.RelativeTimeFormat(); ``` -### isLetter9+ +### constructor8+ -static isLetter(char: string): boolean +constructor(locale: string | Array<string>, options?: RelativeTimeFormatInputOptions) -判断字符串char是否是字母。 +创建相对时间格式化对象。 **系统能力**:SystemCapability.Global.I18n **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| ---- | ------ | ---- | ----- | -| char | string | 是 | 输入字符。 | - -**返回值:** - -| 类型 | 说明 | -| ------- | ------------------------------------ | -| boolean | 返回true表示输入的字符是字母,返回false表示输入的字符不是字母。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------------------- | ---------------------------------------- | ---- | ---------------------------- | +| locale | string \| Array<string> | 是 | 包含区域设置信息的字符串,包括语言以及可选的脚本和区域。 | +| options | [RelativeTimeFormatInputOptions](#relativetimeformatinputoptions8) | 否 | 用于创建相对时间格式化对象的选项。 | **示例:** - ```js - let isletter = I18n.Unicode.isLetter("a"); // isletter = true + ```ts + // 使用 zh-CN locale创建RelativeTimeFormat对象,localeMatcher设置为lookup,numeric设置为always,style设置为long + let relativeTimeFormat = new Intl.RelativeTimeFormat("zh-CN", {"localeMatcher": "lookup", "numeric": "always", "style": "long"}); ``` -### isLowerCase9+ +### format8+ -static isLowerCase(char: string): boolean +format(value: number, unit: string): string -判断字符串char是否是小写字母。 +依据locale和格式化选项,对value和unit进行格式化。 **系统能力**:SystemCapability.Global.I18n **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| ---- | ------ | ---- | ----- | -| char | string | 是 | 输入字符。 | +| 参数名 | 类型 | 必填 | 说明 | +| ----- | ------ | ---- | ---------------------------------------- | +| value | number | 是 | 相对时间格式化的数值。 | +| unit | string | 是 | 相对时间格式化的单位,取值包括:"year", "quarter", "month", "week", "day", "hour", "minute", "second"。 | **返回值:** -| 类型 | 说明 | -| ------- | ---------------------------------------- | -| boolean | 返回true表示输入的字符是小写字母,返回false表示输入的字符不是小写字母。 | +| 类型 | 说明 | +| ------ | ---------- | +| string | 格式化后的相对时间。 | **示例:** - ```js - let islowercase = I18n.Unicode.isLowerCase("a"); // islowercase = true + ```ts + // 使用 zh-CN locale创建RelativeTimeFormat对象 + let relativetimefmt = new Intl.RelativeTimeFormat("zh-CN"); + // 计算 zh-CN locale中数字3,单位quarter的本地化表示 + let formatResult = relativetimefmt.format(3, "quarter"); // formatResult = "3个季度后" ``` -### isUpperCase9+ +### formatToParts8+ -static isUpperCase(char: string): boolean +formatToParts(value: number, unit: string): Array<object> -判断字符串char是否是大写字母。 +返回一个对象数组,表示可用于自定义区域设置格式的相对时间格式。 **系统能力**:SystemCapability.Global.I18n **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| ---- | ------ | ---- | ----- | -| char | string | 是 | 输入字符。 | +| 参数名 | 类型 | 必填 | 说明 | +| ----- | ------ | ---- | ---------------------------------------- | +| value | number | 是 | 相对时间格式化的数值。 | +| unit | string | 是 | 相对时间格式化的单位,取值包括:"year", "quarter", "month", "week", "day", "hour", "minute", "second"。 | **返回值:** -| 类型 | 说明 | -| ------- | ---------------------------------------- | -| boolean | 返回true表示输入的字符是大写字母,返回false表示输入的字符不是大写字母。 | +| 类型 | 说明 | +| ------------------- | --------------------------- | +| Array<object> | 返回可用于自定义区域设置格式的相对时间格式的对象数组。 | **示例:** - ```js - let isuppercase = I18n.Unicode.isUpperCase("a"); // isuppercase = false + ```ts + // 使用 en locale创建RelativeTimeFormat对象,numeric设置为auto + let relativetimefmt = new Intl.RelativeTimeFormat("en", {"numeric": "auto"}); + let parts = relativetimefmt.formatToParts(10, "seconds"); // parts = [ {type: "literal", value: "in"}, {type: "integer", value: 10, unit: "second"}, {type: "literal", value: "seconds"} ] ``` -### getType9+ +### resolvedOptions8+ -static getType(char: string): string +resolvedOptions(): RelativeTimeFormatResolvedOptions -获取输入字符串的一般类别值。 +获取RelativeTimeFormat对象的格式化选项。 **系统能力**:SystemCapability.Global.I18n -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ---- | ------ | ---- | ----- | -| char | string | 是 | 输入字符。 | - **返回值:** -| 类型 | 说明 | -| ------ | ----------- | -| string | 输入字符的一般类别值。 | +| 类型 | 说明 | +| ---------------------------------------- | --------------------------------- | +| [RelativeTimeFormatResolvedOptions](#relativetimeformatresolvedoptions8) | RelativeTimeFormat 对象的格式化选项。 | **示例:** - ```js - let type = I18n.Unicode.getType("a"); // type = "U_LOWERCASE_LETTER" + ```ts + // 使用 en-GB locale创建RelativeTimeFormat对象 + let relativetimefmt= new Intl.RelativeTimeFormat("en-GB", { style: "short" }); + // 获取RelativeTimeFormat对象配置项 + let options = relativetimefmt.resolvedOptions(); + let style = options.style; // style = "short" ``` -## I18NUtil9+ - -### getDateOrder9+ +## RelativeTimeFormatInputOptions8+ -static getDateOrder(locale: string): string - -获取某一区域的日期的年、月、日排列顺序。 +表示RelativeTimeFormat对象可设置的属性。 +从API9开始,RelativeTimeFormatInputOptions中的属性改为可选。 **系统能力**:SystemCapability.Global.I18n +| 名称 | 类型 | 可读 | 可写 | 说明 | +| ------------- | ------ | ---- | ---- | ---------------------------------------- | +| localeMatcher | string | 是 | 是 | locale匹配算法,取值包括:"best fit", "lookup"。localeMatcher属性默认值为best fit。 | +| numeric | string | 是 | 是 | 输出消息的格式,取值包括:"always", "auto"。numeric属性默认值为always。 | +| style | string | 是 | 是 | 国际化消息的长度,取值包括:"long", "short", "narrow"。style属性默认值为long。 | -**参数:** -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ------ | ---- | ------------------------- | -| locale | string | 是 | 格式化时使用的区域参数,如:zh-Hans-CN。 | +## RelativeTimeFormatResolvedOptions8+ -**返回值:** +表示RelativeTimeFormat对象可设置的属性。 -| 类型 | 说明 | -| ------ | ------------------- | -| string | 返回某一区域的日期的年、月、日排列顺序 | +**系统能力**:SystemCapability.Global.I18n -**示例:** - ```js - let order = I18n.I18NUtil.getDateOrder("zh-CN"); // order = "y-L-d" - ``` +| 名称 | 类型 | 可读 | 可写 | 说明 | +| --------------- | ------ | ---- | ---- | ---------------------------------------- | +| locale | string | 是 | 是 | 包含区域设置信息的字符串,包括语言以及可选的脚本和区域。 | +| numeric | string | 是 | 是 | 输出消息的格式,取值包括:"always", "auto"。 | +| style | string | 是 | 是 | 国际化消息的长度,取值包括:"long", "short", "narrow"。 | +| numberingSystem | string | 是 | 是 | 使用的数字系统。 | -- Gitee From 412515cfd414f380b292145d9c106c4262316735 Mon Sep 17 00:00:00 2001 From: LY Date: Wed, 8 Nov 2023 11:38:59 +0000 Subject: [PATCH 2/3] update zh-cn/application-dev/reference/apis/js-apis-i18n.md. Signed-off-by: LY --- .../reference/apis/js-apis-i18n.md | 1047 +++++++++-------- 1 file changed, 583 insertions(+), 464 deletions(-) diff --git a/zh-cn/application-dev/reference/apis/js-apis-i18n.md b/zh-cn/application-dev/reference/apis/js-apis-i18n.md index d4c2c0e..aa5a732 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-i18n.md +++ b/zh-cn/application-dev/reference/apis/js-apis-i18n.md @@ -15,808 +15,927 @@ ## 导入模块 ```js -import Intl from '@ohos.intl'; +import I18n from '@ohos.i18n'; ``` -未正确导入包可能产生不明确的接口行为。 -## Locale +## System9+ -### 属性 +### getDisplayCountry9+ + +static getDisplayCountry(country: string, locale: string, sentenceCase?: boolean): string + +获取指定国家的本地化显示文本。 **系统能力**:SystemCapability.Global.I18n -| 名称 | 类型 | 可读 | 可写 | 说明 | -| --------------- | ------- | ---- | ---- | ---------------------------------------- | -| language | string | 是 | 否 | 与区域设置相关的语言,如:zh。 | -| script | string | 是 | 否 | 语言的书写方式,如:Hans。 | -| region | string | 是 | 否 | 与区域设置相关的地区,如:CN。 | -| baseName | string | 是 | 否 | Locale的基本核心信息(由语言脚本与地区组成),如:zh-Hans-CN。 | -| caseFirst | string | 是 | 否 | 区域的整理规则是否考虑大小写,取值包括:"upper", "lower", "false"。 | -| calendar | string | 是 | 否 | 区域的日历信息,取值包括:"buddhist", "chinese", "coptic","dangi", "ethioaa", "ethiopic", "gregory", "hebrew", "indian", "islamic", "islamic-umalqura", "islamic-tbla", "islamic-civil", "islamic-rgsa", "iso8601", "japanese", "persian", "roc", "islamicc"。 | -| collation | string | 是 | 否 | 区域的排序规则,取值包括:"big5han", "compat", "dict", "direct", "ducet", "eor", "gb2312", "phonebk", "phonetic", "pinyin", "reformed", "searchjl", "stroke", "trad", "unihan", "zhuyin"。 | -| hourCycle | string | 是 | 否 | 区域的时制信息,取值包括:"h12", "h23", "h11", "h24"。 | -| numberingSystem | string | 是 | 否 | 区域使用的数字系统,取值包括:"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 | 是 | 否 | 是否对数字字符具有特殊的排序规则处理。默认值:false。 | +**参数:** +| 参数名 | 类型 | 必填 | 说明 | +| ------------ | ------- | ---- | ---------------- | +| country | string | 是 | 指定国家。 | +| locale | string | 是 | 显示指定国家的区域ID。 | +| sentenceCase | boolean | 否 | 本地化显示文本是否要首字母大写。默认值:true。 | -### constructor8+ +**返回值:** -constructor() +| 类型 | 说明 | +| ------ | ------------- | +| string | 指定国家的本地化显示文本。 | -创建区域对象 +**错误码:** -**系统能力**:SystemCapability.Global.I18n +以下错误码的详细介绍请参见[ohos.i18n错误码](../errorcodes/errorcode-i18n.md)。 -**示例:** +| 错误码ID | 错误信息 | +| ------ | ---------------------- | +| 890001 | param value not valid | + +**示例:** ```ts - // 默认构造函数使用系统当前locale创建Locale对象 - let locale = new Intl.Locale(); - // 返回系统当前localel - let localeID = locale.toString(); + import { BusinessError } from '@ohos.base'; + + try { + let displayCountry: string = I18n.System.getDisplayCountry("zh-CN", "en-GB"); // displayCountry = "China" + } catch (error) { + let err: BusinessError = error as BusinessError; + console.error(`call System.getDisplayCountry failed, error code: ${err.code}, message: ${err.message}.`); + } ``` +### getDisplayLanguage9+ -### constructor - -constructor(locale: string, options?: LocaleOptions) +static getDisplayLanguage(language: string, locale: string, sentenceCase?: boolean): string -创建区域对象 +获取指定语言的本地化显示文本。 **系统能力**:SystemCapability.Global.I18n -**参数:** +**参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------------------- | -------------------------------- | ---- | ---------------------------- | -| locale | string | 是 | 区域信息的字符串,由语言、脚本、国家或地区组成。 | -| options | [LocaleOptions](#localeoptions6) | 否 | 用于创建区域对象的选项。 | +| 参数名 | 类型 | 必填 | 说明 | +| ------------ | ------- | ---- | ---------------- | +| language | string | 是 | 指定语言。 | +| locale | string | 是 | 显示指定语言的区域ID。 | +| sentenceCase | boolean | 否 | 本地化显示文本是否要首字母大写。默认值:true。 | -**示例:** +**返回值:** + +| 类型 | 说明 | +| ------ | ------------- | +| string | 指定语言的本地化显示文本。 | + +**错误码:** + +以下错误码的详细介绍请参见[ohos.i18n错误码](../errorcodes/errorcode-i18n.md)。 + +| 错误码ID | 错误信息 | +| ------ | ---------------------- | +| 890001 | param value not valid | + +**示例:** ```ts - // 创建 "zh-CN" Locale对象 - let locale = new Intl.Locale("zh-CN"); - let localeID = locale.toString(); // localeID = "zh-CN" + import { BusinessError } from '@ohos.base'; + + try { + let displayLanguage: string = I18n.System.getDisplayLanguage("zh", "en-GB"); // displayLanguage = Chinese + } catch(error) { + let err: BusinessError = error as BusinessError; + console.error(`call System.getDisplayLanguage failed, error code: ${err.code}, message: ${err.message}.`); + } ``` +### getSystemLanguage9+ -### toString - -toString(): string +static getSystemLanguage(): string -获取区域对象的字符串表示 +获取系统语言。 **系统能力**:SystemCapability.Global.I18n -**返回值:** +**返回值:** -| 类型 | 说明 | -| ------ | ----------- | -| string | 区域对象的字符串表示。 | +| 类型 | 说明 | +| ------ | ------- | +| string | 系统语言ID。 | -**示例:** +**示例:** ```ts - // 创建 "en-GB" Locale对象 - let locale = new Intl.Locale("en-GB"); - let localeID = locale.toString(); // localeID = "en-GB" + import { BusinessError } from '@ohos.base'; + + try { + let systemLanguage: string = I18n.System.getSystemLanguage(); // systemLanguage为当前系统语言 + } catch(error) { + let err: BusinessError = error as BusinessError; + console.error(`call System.getSystemLanguage failed, error code: ${err.code}, message: ${err.message}.`); + } ``` +### getSystemRegion9+ -### maximize - -maximize(): Locale +static getSystemRegion(): string -最大化区域信息,若缺少脚本与地区信息,则补齐。 +获取系统地区。 **系统能力**:SystemCapability.Global.I18n -**返回值:** +**返回值:** -| 类型 | 说明 | -| ----------------- | ---------- | -| [Locale](#locale) | 最大化后的区域对象。 | +| 类型 | 说明 | +| ------ | ------- | +| string | 系统地区ID。 | -**示例:** +**示例:** ```ts - // 创建 "zh" Locale对象 - let locale = new Intl.Locale("zh"); - // 补齐Locale对象的脚本和地区 - let maximizedLocale = locale.maximize(); - let localeID = maximizedLocale.toString(); // localeID = "zh-Hans-CN" - - // 创建 "en-US" Locale对象 - locale = new Intl.Locale("en-US"); - // 补齐Locale对象的脚本 - maximizedLocale = locale.maximize(); - localeID = maximizedLocale.toString(); // localeID = "en-Latn-US" + import { BusinessError } from '@ohos.base'; + + try { + let systemRegion: string = I18n.System.getSystemRegion(); // 获取系统当前地区设置 + } catch(error) { + let err: BusinessError = error as BusinessError; + console.error(`call System.getSystemRegion failed, error code: ${err.code}, message: ${err.message}.`); + } ``` +### getSystemLocale9+ -### minimize +static getSystemLocale(): string -minimize(): Locale - -最小化区域信息,若包含脚本与地区信息,则去除。 +获取系统区域。 **系统能力**:SystemCapability.Global.I18n -**返回值:** +**返回值:** -| 类型 | 说明 | -| ----------------- | ---------- | -| [Locale](#locale) | 最小化后的区域对象。 | +| 类型 | 说明 | +| ------ | ------- | +| string | 系统区域ID。 | -**示例:** +**示例:** ```ts - // 创建 "zh-Hans-CN" Locale对象 - let locale = new Intl.Locale("zh-Hans-CN"); - // 去除Locale对象的脚本和地区 - let minimizedLocale = locale.minimize(); - let localeID = minimizedLocale.toString(); // localeID = "zh" - - // 创建 "en-US" Locale对象 - locale = new Intl.Locale("en-US"); - // 去除Locale对象的地区 - minimizedLocale = locale.minimize(); - localeID = minimizedLocale.toString(); // localeID = "en" + import { BusinessError } from '@ohos.base'; + + try { + let systemLocale: string = I18n.System.getSystemLocale(); // 获取系统当前Locale + } catch(error) { + let err: BusinessError = error as BusinessError; + console.error(`call System.getSystemLocale failed, error code: ${err.code}, message: ${err.message}.`); + } ``` +### is24HourClock9+ -## LocaleOptions6+ +static is24HourClock(): boolean -表示区域初始化选项。 -从API9开始,LocaleOptions中的属性改为可选。 +判断系统时间是否为24小时制。 **系统能力**:SystemCapability.Global.I18n -| 名称 | 类型 | 可读 | 可写 | 说明 | -| --------------- | ------- | ---- | ---- | ---------------------------------------- | -| calendar | string | 是 | 是 | 日历参数,如:"buddhist", "chinese", "coptic", "dangi", "ethioaa", "ethiopic", "gregory", "hebrew", "indian", "islamic", "islamic-umalqura", "islamic-tbla", "islamic-civil", "islamic-rgsa", "iso8601", "japanese", "persian", "roc", "islamicc"。 | -| collation | string | 是 | 是 | 排序参数,取值包括:"big5han", "compat", "dict", "direct", "ducet", "emoji", "eor", "gb2312", "phonebk", "phonetic", "pinyin", "reformed ", "search", "searchjl", "standard", "stroke", "trad", "unihan", "zhuyin"。 | -| hourCycle | string | 是 | 是 | 时制格式,取值包括:"h11", "h12", "h23", "h24"。 | -| numberingSystem | string | 是 | 是 | 数字系统,取值包括:"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 | 是 | 是 | 是否使用12小时制。默认值:false。 | -| caseFirst | string | 是 | 是 | 表示大写、小写的排序顺序,取值范围:"upper", "lower", "false"。 | - +**返回值:** -## DateTimeFormat +| 类型 | 说明 | +| ------- | ---------------------------------------- | +| boolean | 返回true,表示系统24小时开关开启;返回false,表示系统24小时开关关闭。 | +**示例:** + ```ts + import { BusinessError } from '@ohos.base'; + + try { + let is24HourClock: boolean = I18n.System.is24HourClock(); // 系统24小时开关是否开启 + } catch(error) { + let err: BusinessError = error as BusinessError; + console.error(`call System.is24HourClock failed, error code: ${err.code}, message: ${err.message}.`); + } + ``` -### constructor8+ +## I18n.isRTL7+ -constructor() +isRTL(locale: string): boolean -创建时间日期格式化对象。 +获取该区域是否为从右至左显示语言。 **系统能力**:SystemCapability.Global.I18n -**示例:** +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ------ | ------ | ---- | ------- | +| locale | string | 是 | 指定区域ID。 | + +**返回值:** + +| 类型 | 说明 | +| ------- | ---------------------------------------- | +| boolean | true表示该locale从右至左显示语言;false表示该locale从左至右显示语言。 | + +**示例:** ```ts - // 使用系统当前locale创建DateTimeFormat对象 - let datefmt= new Intl.DateTimeFormat(); + I18n.isRTL("zh-CN");// 中文不是RTL语言,返回false + I18n.isRTL("ar-EG");// 阿语是RTL语言,返回true ``` +## I18n.getCalendar8+ -### constructor - -constructor(locale: string | Array<string>, options?: DateTimeOptions) +getCalendar(locale: string, type? : string): Calendar -创建时间日期格式化对象。 +获取日历对象。 **系统能力**:SystemCapability.Global.I18n **参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------------------- | ------------------------------------ | ---- | ---------------------------- | -| locale | string \| Array<string> | 是 | 包含区域设置信息的字符串,包括语言以及可选的脚本和区域。 | -| options | [DateTimeOptions](#datetimeoptions6) | 否 | 用于创建时间日期格式化的选项。若所有选项均未设置时,year、month、day三个属性的默认值为numeric。 | +| 参数名 | 类型 | 必填 | 说明 | +| ------ | ------ | ---- | ---------------------------------------- | +| locale | string | 是 | 合法的locale值,例如zh-Hans-CN。 | +| type | string | 否 | 合法的日历类型,目前合法的类型有buddhist, chinese, coptic, ethiopic, hebrew, gregory, indian, islamic_civil, islamic_tbla, islamic_umalqura, japanese, persian。当type没有给出时,采用区域默认的日历类型。 | + +**返回值:** + +| 类型 | 说明 | +| ---------------------- | ----- | +| [Calendar](#calendar8) | 日历对象。 | **示例:** - ```ts - // 使用 "zh-CN" locale创建DateTimeFormat对象,日期风格为full,时间风格为medium - let datefmt= new Intl.DateTimeFormat("zh-CN", { dateStyle: 'full', timeStyle: 'medium' }); + ```js + I18n.getCalendar("zh-Hans", "chinese"); // 获取中国农历日历对象 ``` -**示例:** +## Calendar8+ + + +### setTime8+ + +setTime(date: Date): void + +设置日历对象内部的时间日期。 + +**系统能力**:SystemCapability.Global.I18n + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ---- | ---- | ---- | ----------------- | +| date | Date | 是 | 将要设置的日历对象的内部时间日期。 | + +**示例:** ```ts - // 使用 ["ban", "zh"] locale列表创建DateTimeFormat对象,因为ban为非法LocaleID,因此使用zh Locale创建DateTimeFormat对象 - let datefmt= new Intl.DateTimeFormat(["ban", "zh"], { dateStyle: 'full', timeStyle: 'medium' }); + let calendar: I18n.Calendar = I18n.getCalendar("en-US", "gregory"); + let date: Date = new Date(2021, 10, 7, 8, 0, 0, 0); + calendar.setTime(date); ``` -### format +### setTime8+ -format(date: Date): string +setTime(time: number): void -格式化时间日期字符串。 +设置日历对象内部的时间日期, time为从1970.1.1 00:00:00 GMT逝去的毫秒数。 **系统能力**:SystemCapability.Global.I18n -**参数:** +**参数:** -| 参数名 | 类型 | 必填 | 说明 | -| ---- | ---- | ---- | ------- | -| date | Date | 是 | 时间日期对象。 | +| 参数名 | 类型 | 必填 | 说明 | +| ---- | ------ | ---- | ---------------------------------------- | +| time | number | 是 | time为从1970.1.1 00:00:00 GMT逝去的毫秒数。 | -**返回值:** +**示例:** + ```ts + let calendar: I18n.Calendar = I18n.getCalendar("en-US", "gregory"); + calendar.setTime(10540800000); + ``` -| 类型 | 说明 | -| ------ | ------------ | -| string | 格式化后的时间日期字符串 | -**示例:** - ```ts - let date = new Date(2021, 11, 17, 3, 24, 0); - // 使用 en-GB locale创建DateTimeFormat对象 - let datefmt = new Intl.DateTimeFormat("en-GB"); - let formattedDate = datefmt.format(date); // formattedDate "17/12/2021" +### set8+ + +set(year: number, month: number, date:number, hour?: number, minute?: number, second?: number): void + +设置日历对象的年、月、日、时、分、秒。 + +**系统能力**:SystemCapability.Global.I18n - // 使用 en-GB locale创建DateTimeFormat对象,dateStyle设置为full,timeStyle设置为medium - datefmt = new Intl.DateTimeFormat("en-GB", { dateStyle: 'full', timeStyle: 'medium' }); - formattedDate = datefmt.format(date); // formattedDate "Friday, 17 December 2021 at 03:24:00" +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ------ | ------ | ---- | ------ | +| year | number | 是 | 设置的年。 | +| month | number | 是 | 设置的月。 | +| date | number | 是 | 设置的日。 | +| hour | number | 否 | 设置的小时。默认值:系统小时。 | +| minute | number | 否 | 设置的分钟。默认值:系统分钟。 | +| second | number | 否 | 设置的秒。默认值:系统秒。 | + +**示例:** + ```ts + let calendar: I18n.Calendar = I18n.getCalendar("zh-Hans"); + calendar.set(2021, 10, 1, 8, 0, 0); // set time to 2021.10.1 08:00:00 ``` -### formatRange +### setTimeZone8+ -formatRange(startDate: Date, endDate: Date): string +setTimeZone(timezone: string): void -格式化时间日期段字符串。 +设置日历对象的时区。 **系统能力**:SystemCapability.Global.I18n -**参数:** +**参数:** -| 参数名 | 类型 | 必填 | 说明 | -| --------- | ---- | ---- | -------- | -| startDate | Date | 是 | 起始的时间日期。 | -| endDate | Date | 是 | 结束的时间日期。 | +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------ | ---- | ------------------------- | +| timezone | string | 是 | 设置的时区id,如“Asia/Shanghai”。 | -**返回值:** +**示例:** + ```ts + let calendar: I18n.Calendar = I18n.getCalendar("zh-Hans"); + calendar.setTimeZone("Asia/Shanghai"); + ``` -| 类型 | 说明 | -| ------ | -------------- | -| string | 格式化后的时间日期段字符串。 | -**示例:** +### getTimeZone8+ + +getTimeZone(): string + +获取日历对象的时区。 + +**系统能力**:SystemCapability.Global.I18n + +**返回值:** + +| 类型 | 说明 | +| ------ | ---------- | +| string | 日历对象的时区id。 | + +**示例:** ```ts - let startDate = new Date(2021, 11, 17, 3, 24, 0); - let endDate = new Date(2021, 11, 18, 3, 24, 0); - // 使用 en-GB locale创建DateTimeFormat对象 - let datefmt = new Intl.DateTimeFormat("en-GB"); - let formattedDateRange = datefmt.formatRange(startDate, endDate); // formattedDateRange = "17/12/2021-18/12/2021" + let calendar: I18n.Calendar = I18n.getCalendar("zh-Hans"); + calendar.setTimeZone("Asia/Shanghai"); + let timezone: string = calendar.getTimeZone(); // timezone = "Asia/Shanghai" ``` -### resolvedOptions +### getFirstDayOfWeek8+ -resolvedOptions(): DateTimeOptions +getFirstDayOfWeek(): number -获取DateTimeFormat对象的格式化选项。 +获取日历对象的一周起始日。 **系统能力**:SystemCapability.Global.I18n -**返回值:** +**返回值:** -| 类型 | 说明 | -| ------------------------------------ | ----------------------------- | -| [DateTimeOptions](#datetimeoptions6) | DateTimeFormat 对象的格式化选项。 | +| 类型 | 说明 | +| ------ | --------------------- | +| number | 获取一周的起始日,1代表周日,7代表周六。 | -**示例:** +**示例:** ```ts - let datefmt = new Intl.DateTimeFormat("en-GB", { dateStyle: 'full', timeStyle: 'medium' }); - // 返回DateTimeFormat对象的配置项 - let options = datefmt.resolvedOptions(); - let dateStyle = options.dateStyle; // dateStyle = "full" - let timeStyle = options.timeStyle; // timeStyle = "medium" + let calendar: I18n.Calendar = I18n.getCalendar("en-US", "gregory"); + let firstDayOfWeek: number = calendar.getFirstDayOfWeek(); // firstDayOfWeek = 1 ``` -## DateTimeOptions6+ +### setFirstDayOfWeek8+ -表示时间日期格式化选项。 -从API9开始,DateTimeOptions中的属性改为可选。 +setFirstDayOfWeek(value: number): void + +设置每一周的起始日。 **系统能力**:SystemCapability.Global.I18n -| 名称 | 类型 | 可读 | 可写 | 说明 | -| --------------- | ------- | ---- | ---- | ---------------------------------------- | -| locale | string | 是 | 否 | 区域参数, 如:zh-Hans-CN。 | -| dateStyle | string | 是 | 是 | 日期显示格式,取值包括:"long", "short", "medium", "full"。 | -| timeStyle | string | 是 | 是 | 时间显示格式,取值包括:"long", "short", "medium", "full"。 | -| hourCycle | string | 是 | 是 | 时制格式,取值包括:"h11", "h12", "h23", "h24"。 | -| timeZone | string | 是 | 是 | 使用的时区(合法的IANA时区ID)。 | -| numberingSystem | string | 是 | 是 | 数字系统,取值包括:"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"。 | -| hour12 | boolean | 是 | 是 | 是否使用12小时制。若hour12和hourCycle未设置且系统24小时开关打开时,hour12属性的默认值为false。 | -| weekday | string | 是 | 是 | 工作日的显示格式,取值包括:"long", "short", "narrow"。 | -| era | string | 是 | 是 | 时代的显示格式,取值包括:"long", "short", "narrow"。 | -| year | string | 是 | 是 | 年份的显示格式,取值包括:"numeric", "2-digit"。 | -| month | string | 是 | 是 | 月份的显示格式,取值包括:"numeric", "2-digit", "long", "short", "narrow"。 | -| day | string | 是 | 是 | 日期的显示格式,取值包括:"numeric", "2-digit"。 | -| hour | string | 是 | 是 | 小时的显示格式,取值包括:"numeric", "2-digit"。 | -| minute | string | 是 | 是 | 分钟的显示格式,取值包括:"numeric", "2-digit"。 | -| second | string | 是 | 是 | 秒钟的显示格式,取值包括:"numeric", "2-digit"。 | -| timeZoneName | string | 是 | 是 | 时区名称的本地化表示。 | -| dayPeriod | string | 是 | 是 | 时段的显示格式,取值包括:"long", "short", "narrow"。 | -| localeMatcher | string | 是 | 是 | 要使用的区域匹配算法,取值包括:"lookup", "best fit"。 | -| formatMatcher | string | 是 | 是 | 要使用的格式匹配算法,取值包括:"basic", "best fit"。 | +**参数:** +| 参数名 | 类型 | 必填 | 说明 | +| ----- | ------ | ---- | --------------------- | +| value | number | 是 | 设置一周的起始日,1代表周日,7代表周六。 | -## NumberFormat +**示例:** + ```ts + let calendar: I18n.Calendar = I18n.getCalendar("zh-Hans"); + calendar.setFirstDayOfWeek(3); + let firstDayOfWeek: number = calendar.getFirstDayOfWeek(); // firstDayOfWeek = 3 + ``` -### constructor8+ +### getMinimalDaysInFirstWeek8+ -constructor() +getMinimalDaysInFirstWeek(): number -创建数字格式化对象。 +获取一年中第一周的最小天数。 **系统能力**:SystemCapability.Global.I18n -**示例:** +**返回值:** + +| 类型 | 说明 | +| ------ | ------------ | +| number | 一年中第一周的最小天数。 | + +**示例:** ```ts - // 使用系统当前locale创建NumberFormat对象 - let numfmt = new Intl.NumberFormat(); + let calendar: I18n.Calendar = I18n.getCalendar("zh-Hans"); + let minimalDaysInFirstWeek: number = calendar.getMinimalDaysInFirstWeek(); // minimalDaysInFirstWeek = 1 ``` -### constructor +### setMinimalDaysInFirstWeek8+ -constructor(locale: string | Array<string>, options?: NumberOptions) +setMinimalDaysInFirstWeek(value: number): void -创建数字格式化对象。 +设置一年中第一周的最小天数。 **系统能力**:SystemCapability.Global.I18n -**参数:** +**参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------------------- | -------------------------------- | ---- | ---------------------------- | -| locale | string \| Array<string> | 是 | 包含区域设置信息的字符串,包括语言以及可选的脚本和区域。 | -| options | [NumberOptions](#numberoptions6) | 否 | 用于创建数字格式化的选项。 | +| 参数名 | 类型 | 必填 | 说明 | +| ----- | ------ | ---- | ------------ | +| value | number | 是 | 一年中第一周的最小天数。 | -**示例:** +**示例:** ```ts - // 使用 en-GB locale创建NumberFormat对象,style设置为decimal,notation设置为scientific - let numfmt = new Intl.NumberFormat("en-GB", {style:'decimal', notation:"scientific"}); + let calendar: I18n.Calendar = I18n.getCalendar("zh-Hans"); + calendar.setMinimalDaysInFirstWeek(3); + let minimalDaysInFirstWeek: number = calendar.getMinimalDaysInFirstWeek(); // minimalDaysInFirstWeek = 3 ``` -### format +### get8+ -format(number: number): string; +get(field: string): number -格式化数字字符串。 +获取日历对象中与field相关联的值。 **系统能力**:SystemCapability.Global.I18n -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ------ | ---- | ---- | -| number | number | 是 | 数字对象 | +**参数:** -**返回值:** +| 参数名 | 类型 | 必填 | 说明 | +| ----- | ------ | ---- | ---------------------------------------- | +| field | string | 是 | 通过field来获取日历对象相应的值。目前支持的field值有 era, year, month, week_of_year, week_of_month, date, day_of_year, day_of_week, day_of_week_in_month, hour, hour_of_day, minute, second, millisecond, zone_offset, dst_offset, year_woy, dow_local, extended_year, julian_day, milliseconds_in_day, is_leap_month。 | -| 类型 | 说明 | -| ------ | ---------- | -| string | 格式化后的数字字符串 | +**返回值:** +| 类型 | 说明 | +| ------ | ---------------------------------------- | +| number | 与field相关联的值,如当前Calendar对象的内部日期的年份为1990,get("year")返回1990。 | -**示例:** +**示例:** ```ts - // 使用 ["en-GB", "zh"] locale列表创建NumberFormat对象,因为en-GB为合法LocaleID,因此使用en-GB创建NumberFormat对象 - let numfmt = new Intl.NumberFormat(["en-GB", "zh"], {style:'decimal', notation:"scientific"}); - let formattedNumber = numfmt.format(1223); // formattedNumber = 1.223E3 + let calendar: I18n.Calendar = I18n.getCalendar("zh-Hans"); + calendar.set(2021, 10, 1, 8, 0, 0); // set time to 2021.10.1 08:00:00 + let hourOfDay: number = calendar.get("hour_of_day"); // hourOfDay = 8 ``` -### resolvedOptions +### isWeekend8+ -resolvedOptions(): NumberOptions +isWeekend(date?: Date): boolean -获取NumberFormat 对象的格式化选项。 +判断指定的日期在日历中是否为周末。 **系统能力**:SystemCapability.Global.I18n -**返回值:** +**参数:** -| 类型 | 说明 | -| -------------------------------- | --------------------------- | -| [NumberOptions](#numberoptions6) | NumberFormat 对象的格式化选项。 | +| 参数名 | 类型 | 必填 | 说明 | +| ---- | ---- | ---- | ---------------------------------------- | +| date | Date | 否 | 指定的日期。若不填,则判断当前日期是否为周末。默认值:系统日期。 | +**返回值:** -**示例:** +| 类型 | 说明 | +| ------- | ----------------------------------- | +| boolean | 若判断指定日期为周末时,返回true,否则返回false。 | + +**示例:** ```ts - let numfmt = new Intl.NumberFormat(["en-GB", "zh"], {style:'decimal', notation:"scientific"}); - // 获取NumberFormat对象配置项 - let options = numfmt.resolvedOptions(); - let style = options.style; // style = decimal - let notation = options.notation; // notation = scientific + let calendar: I18n.Calendar = I18n.getCalendar("zh-Hans"); + calendar.set(2021, 11, 11, 8, 0, 0); // set time to 2021.11.11 08:00:00 + calendar.isWeekend(); // false + let date: Date = new Date(2011, 11, 6, 9, 0, 0); + calendar.isWeekend(date); // true ``` -## NumberOptions6+ +## I18n.getTimeZone7+ + +getTimeZone(zoneID?: string): TimeZone -表示设备支持的能力。 -从API9开始,NumberOptions中的属性改为可选。 +获取时区ID对应的时区对象。 **系统能力**:SystemCapability.Global.I18n -| 名称 | 类型 | 可读 | 可写 | 说明 | -| ------------------------ | ------- | ---- | ---- | ---------------------------------------- | -| locale | string | 是 | 否 | 区域参数, 如:"zh-Hans-CN"。locale属性默认值为系统Locale。 | -| currency | string | 是 | 是 | 货币单位, 如:"EUR","CNY","USD"等。 | -| currencySign | string | 是 | 是 | 货币单位的符号显示,取值包括: "standard","accounting"。currencySign属性默认值为standard。 | -| currencyDisplay | string | 是 | 是 | 货币的显示方式,取值包括:"symbol", "narrowSymbol", "code", "name"。currencyDisplay属性默认值为symbol。 | -| unit | string | 是 | 是 | 单位名称,如:"meter","inch",“hectare”等。 | -| unitDisplay | string | 是 | 是 | 单位的显示格式,取值包括:"long", "short", "narrow"。unitDisplay属性默认值为short。 | -| unitUsage8+ | string | 是 | 是 | 单位的使用场景,取值包括:"default", "area-land-agricult", "area-land-commercl", "area-land-residntl", "length-person", "length-person-small", "length-rainfall", "length-road", "length-road-small", "length-snowfall", "length-vehicle", "length-visiblty", "length-visiblty-small", "length-person-informal", "length-person-small-informal", "length-road-informal", "speed-road-travel", "speed-wind", "temperature-person", "temperature-weather", "volume-vehicle-fuel"。unitUsage属性默认值为default。 | -| signDisplay | string | 是 | 是 | 数字符号的显示格式,取值包括:"auto", "never", "always", "expectZero"。signDisplay属性默认值为auto。 | -| compactDisplay | string | 是 | 是 | 紧凑型的显示格式,取值包括:"long", "short"。compactDisplay属性默认值为short。 | -| notation | string | 是 | 是 | 数字的格式化规格,取值包括:"standard", "scientific", "engineering", "compact"。notation属性默认值为standard。 | -| localeMatcher | string | 是 | 是 | 要使用的区域匹配算法,取值包括:"lookup", "best fit"。localeMatcher属性默认值为best fit。 | -| style | string | 是 | 是 | 数字的显示格式,取值包括:"decimal", "currency", "percent", "unit"。style属性默认值为decimal。 | -| numberingSystem | string | 是 | 是 | 数字系统,取值包括:"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属性默认值为locale的默认数字系统。 | -| useGrouping | boolean | 是 | 是 | 是否分组显示。useGrouping属性默认值为auto。 | -| minimumIntegerDigits | number | 是 | 是 | 表示要使用的最小整数位数,取值范围:1~21。minimumIntegerDigits属性默认值为1。 | -| minimumFractionDigits | number | 是 | 是 | 表示要使用的最小分数位数,取值范围:0~20。minimumFractionDigits属性默认值为0。 | -| maximumFractionDigits | number | 是 | 是 | 表示要使用的最大分数位数,取值范围:1~21。maximumFractionDigits属性默认值为3。 | -| minimumSignificantDigits | number | 是 | 是 | 表示要使用的最低有效位数,取值范围:1~21。minimumSignificantDigits属性默认值为1。 | -| maximumSignificantDigits | number | 是 | 是 | 表示要使用的最大有效位数,取值范围:1~21。maximumSignificantDigits属性默认值为21。 | +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ------ | ------ | ---- | ----- | +| zondID | string | 否 | 时区ID。默认值:系统时区。 | + +**返回值:** + +| 类型 | 说明 | +| -------- | ------------ | +| [TimeZone](#timezone) | 时区ID对应的时区对象。 | + +**示例:** + ```ts + let timezone: I18n.TimeZone = I18n.getTimeZone(); + ``` -## Collator8+ +## TimeZone -### constructor8+ +### getID -constructor() +getID(): string -创建排序对象。 +获取时区对象的ID。 **系统能力**:SystemCapability.Global.I18n -**示例:** +**返回值:** + +| 类型 | 说明 | +| ------ | ------------ | +| string | 时区对象对应的时区ID。 | + +**示例:** ```ts - // 使用系统locale创建Collator对象 - let collator = new Intl.Collator(); + let timezone: I18n.TimeZone = I18n.getTimeZone(); + let timezoneID: string = timezone.getID(); // timezoneID = "Asia/Shanghai" ``` -### constructor8+ +### getRawOffset -constructor(locale: string | Array<string>, options?: CollatorOptions) +getRawOffset(): number -创建排序对象。 +获取时区对象表示的时区与UTC时区的偏差。 **系统能力**:SystemCapability.Global.I18n -**参数:** +**返回值:** -| 参数名 | 类型 | 必填 | 说明 | -| -------------------- | ------------------------------------ | ---- | ---------------------------- | -| locale | string \| Array<string> | 是 | 包含区域设置信息的字符串,包括语言以及可选的脚本和区域。 | -| options | [CollatorOptions](#collatoroptions8) | 否 | 用于创建排序对象的选项。 | +| 类型 | 说明 | +| ------ | ------------------- | +| number | 时区对象表示的时区与UTC时区的偏差。 | -**示例:** +**示例:** ```ts - // 使用 zh-CN locale创建Collator对象,localeMatcher设置为lookup,usage设置为sort - let collator = new Intl.Collator("zh-CN", {localeMatcher: "lookup", usage: "sort"}); + let timezone: I18n.TimeZone = I18n.getTimeZone(); + let offset: number = timezone.getRawOffset(); // offset = 28800000 ``` -### compare8+ +### getOffset -compare(first: string, second: string): number +getOffset(date?: number): number -依据Collator的排序策略对两个字符串进行比较。 +获取某一时刻时区对象表示的时区与UTC时区的偏差。 **系统能力**:SystemCapability.Global.I18n -**参数:** +**参数:** -| 参数名 | 类型 | 必填 | 说明 | -| ------ | ------ | ---- | ------------ | -| first | string | 是 | 进行比较第一个字符串。 | -| second | string | 是 | 进行比较的第二个字符串。 | +| 参数名 | 类型 | 必填 | 说明 | +| ------ | ------ | ---- | ------ | +| date | number | 否 | 待计算偏差的时刻 | -**返回值:** +**返回值:** -| 类型 | 说明 | -| ------ | ---------------------------------------- | -| number | 比较结果。当number为负数,表示first排序在second之前;当number为0,表示first与second排序相同;当number为正数,表示first排序在second之后。 | +| 类型 | 说明 | +| ------ | ----------------------- | +| number | 某一时刻时区对象表示的时区与UTC时区的偏差。默认值:系统时间。 | -**示例:** +**示例:** ```ts - // 使用en-GB locale创建Collator对象 - let collator = new Intl.Collator("en-GB"); - // 比较 "first" 和 "second" 的先后顺序 - let compareResult = collator.compare("first", "second"); // compareResult = -1 + let timezone: I18n.TimeZone = I18n.getTimeZone(); + let offset: number = timezone.getOffset(1234567890); // offset = 28800000 ``` -### resolvedOptions8+ +### getAvailableIDs9+ -resolvedOptions(): CollatorOptions +static getAvailableIDs(): Array<string> -返回Collator对象的属性。 +获取系统支持的时区ID。 **系统能力**:SystemCapability.Global.I18n -**返回值:** +**返回值:** -| 类型 | 说明 | -| ------------------------------------ | ----------------- | -| [CollatorOptions](#collatoroptions8) | 返回的Collator对象的属性。 | +| 类型 | 说明 | +| ------------------- | ----------- | +| Array<string> | 系统支持的时区ID列表 | -**示例:** +**示例:** ```ts - let collator = new Intl.Collator("zh-Hans", { usage: 'sort', ignorePunctuation: true }); - // 获取Collator对象的配置项 - let options = collator.resolvedOptions(); - let usage = options.usage; // usage = "sort" - let ignorePunctuation = options.ignorePunctuation; // ignorePunctuation = true + // ids = ["America/Adak", "America/Anchorage", "America/Bogota", "America/Denver", "America/Los_Angeles", "America/Montevideo", "America/Santiago", "America/Sao_Paulo", "Asia/Ashgabat", "Asia/Hovd", "Asia/Jerusalem", "Asia/Magadan", "Asia/Omsk", "Asia/Shanghai", "Asia/Tokyo", "Asia/Yerevan", "Atlantic/Cape_Verde", "Australia/Lord_Howe", "Europe/Dublin", "Europe/London", "Europe/Moscow", "Pacific/Auckland", "Pacific/Easter", "Pacific/Pago-Pago"], 当前共支持24个时区 + let ids: Array = I18n.TimeZone.getAvailableIDs(); ``` -## CollatorOptions8+ +## Unicode9+ -表示Collator可设置的属性。 -从API9中,CollatorOptions中的属性改为可选。 -**系统能力**:SystemCapability.Global.I18n +### isDigit9+ -| 名称 | 类型 | 可读 | 可写 | 说明 | -| ----------------- | ------- | ---- | ---- | ---------------------------------------- | -| localeMatcher | string | 是 | 是 | locale匹配算法,取值范围:"best fit", "lookup"。localeMatcher属性默认值为best fit。 | -| usage | string | 是 | 是 | 比较的用途,取值范围:"sort", "search"。usage属性默认值为sort。 | -| sensitivity | string | 是 | 是 | 表示字符串中的哪些差异会导致非零结果值,取值范围:"base", "accent", "case", "letiant"。sensitivity属性默认值为variant。 | -| ignorePunctuation | boolean | 是 | 是 | 表示是否忽略标点符号,取值范围:true, false。ignorePunctuation属性默认值为false。 | -| collation | string | 是 | 是 | 排序规则,取值范围:"big5han", "compat", "dict", "direct", "ducet", "eor", "gb2312", "phonebk", "phonetic", "pinyin", "reformed", "searchjl", "stroke", "trad", "unihan", "zhuyin"。collation属性默认值为default。 | -| numeric | boolean | 是 | 是 | 是否使用数字排序,取值范围:true, false。numeric属性默认值为false。 | -| caseFirst | string | 是 | 是 | 表示大写、小写的排序顺序,取值范围:"upper", "lower", "false"。caseFirst属性默认值为false | +static isDigit(char: string): boolean +判断字符串char是否是数字。 -## PluralRules8+ +**系统能力**:SystemCapability.Global.I18n +**参数:** -### constructor8+ +| 参数名 | 类型 | 必填 | 说明 | +| ---- | ------ | ---- | ----- | +| char | string | 是 | 输入字符。 | -constructor() +**返回值:** -创建单复数对象来计算数字的单复数类别。 +| 类型 | 说明 | +| ------- | ------------------------------------ | +| boolean | 返回true表示输入的字符是数字,返回false表示输入的字符不是数字。 | -**系统能力**:SystemCapability.Global.I18n - -**示例:** +**示例:** ```ts - // 使用系统locale创建PluralRules对象 - let pluralRules = new Intl.PluralRules(); + let isdigit: boolean = I18n.Unicode.isDigit("1"); // isdigit = true ``` -### constructor8+ +### isSpaceChar9+ -constructor(locale: string | Array<string>, options?: PluralRulesOptions) +static isSpaceChar(char: string): boolean -创建单复数对象来计算数字的单复数类别。 +判断字符串char是否是空格符。 **系统能力**:SystemCapability.Global.I18n -**参数:** +**参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------------------- | ---------------------------------------- | ---- | ---------------------------- | -| locale | string \| Array<string> | 是 | 包含区域设置信息的字符串,包括语言以及可选的脚本和区域。 | -| options | [PluralRulesOptions](#pluralrulesoptions8) | 否 | 用于创建单复数对象的选项。 | +| 参数名 | 类型 | 必填 | 说明 | +| ---- | ------ | ---- | ----- | +| char | string | 是 | 输入字符。 | -**示例:** +**返回值:** + +| 类型 | 说明 | +| ------- | -------------------------------------- | +| boolean | 返回true表示输入的字符是空格符,返回false表示输入的字符不是空格符。 | + +**示例:** ```ts - // 使用 zh-CN locale创建PluralRules对象,localeMatcher设置为lookup,type设置为cardinal - let pluralRules= new Intl.PluralRules("zh-CN", {"localeMatcher": "lookup", "type": "cardinal"}); + let isspacechar: boolean = I18n.Unicode.isSpaceChar("a"); // isspacechar = false ``` -### select8+ +### isWhitespace9+ -select(n: number): string +static isWhitespace(char: string): boolean -返回一个字符串表示该数字的单复数类别。 +判断字符串char是否是空白符。 **系统能力**:SystemCapability.Global.I18n -**参数:** +**参数:** -| 参数名 | 类型 | 必填 | 说明 | -| ---- | ------ | ---- | ------------ | -| n | number | 是 | 待获取单复数类别的数字。 | +| 参数名 | 类型 | 必填 | 说明 | +| ---- | ------ | ---- | ----- | +| char | string | 是 | 输入字符。 | -**返回值:** +**返回值:** -| 类型 | 说明 | -| ------ | ---------------------------------------- | -| string | 单复数类别,取值包括:"zero","one","two", "few", "many", "others"。 | +| 类型 | 说明 | +| ------- | -------------------------------------- | +| boolean | 返回true表示输入的字符是空白符,返回false表示输入的字符不是空白符。 | -**示例:** +**示例:** ```ts - // 使用 zh-Hans locale创建PluralRules对象 - let zhPluralRules = new Intl.PluralRules("zh-Hans"); - // 计算 zh-Hans locale中数字1对应的单复数类别 - let plural = zhPluralRules.select(1); // plural = other - - // 使用 en-US locale创建PluralRules对象 - let enPluralRules = new Intl.PluralRules("en-US"); - // 计算 en-US locale中数字1对应的单复数类别 - plural = enPluralRules.select(1); // plural = one + let iswhitespace: boolean = I18n.Unicode.isWhitespace("a"); // iswhitespace = false ``` -## PluralRulesOptions8+ +### isRTL9+ + +static isRTL(char: string): boolean -表示PluralRules对象可设置的属性。 -从API9开始,PluralRulesOptions中的属性改为可选。 +判断字符串char是否是从右到左语言的字符。 **系统能力**:SystemCapability.Global.I18n -| 名称 | 类型 | 可读 | 可写 | 说明 | -| ------------------------ | ------ | ---- | ---- | ---------------------------------------- | -| localeMatcher | string | 是 | 是 | locale匹配算法,取值包括:"best fit", "lookup"。localeMatcher属性默认值为best fit。 | -| type | string | 是 | 是 | 排序的类型,取值包括:"cardinal", "ordinal"。type属性默认值为cardinal。 | -| minimumIntegerDigits | number | 是 | 是 | 表示要使用的最小整数位数,取值范围:1~21。minimumIntegerDigits属性默认值为1。 | -| minimumFractionDigits | number | 是 | 是 | 表示要使用的最小分数位数,取值范围:0~20。minimumFractionDigits属性默认值为0。 | -| maximumFractionDigits | number | 是 | 是 | 表示要使用的最大分数位数,取值范围:1~21。maximumFractionDigits属性默认值为3。 | -| minimumSignificantDigits | number | 是 | 是 | 表示要使用的最低有效位数,取值范围:1~21。minimumSignificantDigits属性默认值为1。 | -| maximumSignificantDigits | number | 是 | 是 | 表示要使用的最大有效位数,取值范围:1~21。maximumSignificantDigits属性默认值为21。 | +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ---- | ------ | ---- | ----- | +| char | string | 是 | 输入字符。 | +**返回值:** -## RelativeTimeFormat8+ +| 类型 | 说明 | +| ------- | ---------------------------------------- | +| boolean | 返回true表示输入的字符是从右到左语言的字符,返回false表示输入的字符不是从右到左语言的字符。 | + +**示例:** + ```ts + let isrtl: boolean = I18n.Unicode.isRTL("a"); // isrtl = false + ``` -### constructor8+ +### isIdeograph9+ -constructor() +static isIdeograph(char: string): boolean -创建相对时间格式化对象。 +判断字符串char是否是表意文字。 **系统能力**:SystemCapability.Global.I18n -**示例:** +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ---- | ------ | ---- | ----- | +| char | string | 是 | 输入字符。 | + +**返回值:** + +| 类型 | 说明 | +| ------- | ---------------------------------------- | +| boolean | 返回true表示输入的字符是表意文字,返回false表示输入的字符不是表意文字。 | + +**示例:** ```ts - // 使用系统locale创建RelativeTimeFormat对象 - let relativetimefmt = new Intl.RelativeTimeFormat(); + let isideograph: boolean = I18n.Unicode.isIdeograph("a"); // isideograph = false ``` -### constructor8+ +### isLetter9+ -constructor(locale: string | Array<string>, options?: RelativeTimeFormatInputOptions) +static isLetter(char: string): boolean -创建相对时间格式化对象。 +判断字符串char是否是字母。 **系统能力**:SystemCapability.Global.I18n -**参数:** +**参数:** -| 参数名 | 类型 | 必填 | 说明 | -| -------------------- | ---------------------------------------- | ---- | ---------------------------- | -| locale | string \| Array<string> | 是 | 包含区域设置信息的字符串,包括语言以及可选的脚本和区域。 | -| options | [RelativeTimeFormatInputOptions](#relativetimeformatinputoptions8) | 否 | 用于创建相对时间格式化对象的选项。 | +| 参数名 | 类型 | 必填 | 说明 | +| ---- | ------ | ---- | ----- | +| char | string | 是 | 输入字符。 | -**示例:** +**返回值:** + +| 类型 | 说明 | +| ------- | ------------------------------------ | +| boolean | 返回true表示输入的字符是字母,返回false表示输入的字符不是字母。 | + +**示例:** ```ts - // 使用 zh-CN locale创建RelativeTimeFormat对象,localeMatcher设置为lookup,numeric设置为always,style设置为long - let relativeTimeFormat = new Intl.RelativeTimeFormat("zh-CN", {"localeMatcher": "lookup", "numeric": "always", "style": "long"}); + let isletter: boolean = I18n.Unicode.isLetter("a"); // isletter = true ``` -### format8+ +### isLowerCase9+ -format(value: number, unit: string): string +static isLowerCase(char: string): boolean -依据locale和格式化选项,对value和unit进行格式化。 +判断字符串char是否是小写字母。 **系统能力**:SystemCapability.Global.I18n -**参数:** +**参数:** -| 参数名 | 类型 | 必填 | 说明 | -| ----- | ------ | ---- | ---------------------------------------- | -| value | number | 是 | 相对时间格式化的数值。 | -| unit | string | 是 | 相对时间格式化的单位,取值包括:"year", "quarter", "month", "week", "day", "hour", "minute", "second"。 | +| 参数名 | 类型 | 必填 | 说明 | +| ---- | ------ | ---- | ----- | +| char | string | 是 | 输入字符。 | -**返回值:** +**返回值:** -| 类型 | 说明 | -| ------ | ---------- | -| string | 格式化后的相对时间。 | +| 类型 | 说明 | +| ------- | ---------------------------------------- | +| boolean | 返回true表示输入的字符是小写字母,返回false表示输入的字符不是小写字母。 | -**示例:** +**示例:** ```ts - // 使用 zh-CN locale创建RelativeTimeFormat对象 - let relativetimefmt = new Intl.RelativeTimeFormat("zh-CN"); - // 计算 zh-CN locale中数字3,单位quarter的本地化表示 - let formatResult = relativetimefmt.format(3, "quarter"); // formatResult = "3个季度后" + let islowercase: boolean = I18n.Unicode.isLowerCase("a"); // islowercase = true ``` -### formatToParts8+ +### isUpperCase9+ -formatToParts(value: number, unit: string): Array<object> +static isUpperCase(char: string): boolean -返回一个对象数组,表示可用于自定义区域设置格式的相对时间格式。 +判断字符串char是否是大写字母。 **系统能力**:SystemCapability.Global.I18n -**参数:** +**参数:** -| 参数名 | 类型 | 必填 | 说明 | -| ----- | ------ | ---- | ---------------------------------------- | -| value | number | 是 | 相对时间格式化的数值。 | -| unit | string | 是 | 相对时间格式化的单位,取值包括:"year", "quarter", "month", "week", "day", "hour", "minute", "second"。 | +| 参数名 | 类型 | 必填 | 说明 | +| ---- | ------ | ---- | ----- | +| char | string | 是 | 输入字符。 | -**返回值:** +**返回值:** -| 类型 | 说明 | -| ------------------- | --------------------------- | -| Array<object> | 返回可用于自定义区域设置格式的相对时间格式的对象数组。 | +| 类型 | 说明 | +| ------- | ---------------------------------------- | +| boolean | 返回true表示输入的字符是大写字母,返回false表示输入的字符不是大写字母。 | -**示例:** +**示例:** ```ts - // 使用 en locale创建RelativeTimeFormat对象,numeric设置为auto - let relativetimefmt = new Intl.RelativeTimeFormat("en", {"numeric": "auto"}); - let parts = relativetimefmt.formatToParts(10, "seconds"); // parts = [ {type: "literal", value: "in"}, {type: "integer", value: 10, unit: "second"}, {type: "literal", value: "seconds"} ] + let isuppercase: boolean = I18n.Unicode.isUpperCase("a"); // isuppercase = false ``` -### resolvedOptions8+ +### getType9+ -resolvedOptions(): RelativeTimeFormatResolvedOptions +static getType(char: string): string -获取RelativeTimeFormat对象的格式化选项。 +获取输入字符串的一般类别值。 **系统能力**:SystemCapability.Global.I18n -**返回值:** +**参数:** -| 类型 | 说明 | -| ---------------------------------------- | --------------------------------- | -| [RelativeTimeFormatResolvedOptions](#relativetimeformatresolvedoptions8) | RelativeTimeFormat 对象的格式化选项。 | +| 参数名 | 类型 | 必填 | 说明 | +| ---- | ------ | ---- | ----- | +| char | string | 是 | 输入字符。 | -**示例:** +**返回值:** + +| 类型 | 说明 | +| ------ | ----------- | +| string | 输入字符的一般类别值。| + +一般类别值如下,更详细的介绍可以参考Unicode标准。 + +| 名称 | 值 | 说明 | +| ---- | -------- | ---------- | +| U_UNASSIGNED | U_UNASSIGNED | 表示未分配和非字符代码点对应类别。 | +| U_GENERAL_OTHER_TYPES | U_GENERAL_OTHER_TYPES | 与 U_UNASSIGNED 相同。 | +| U_UPPERCASE_LETTER | U_UPPERCASE_LETTER | 表示大写字母。 | +| U_LOWERCASE_LETTER | U_LOWERCASE_LETTER | 表示小写字母。 | +| U_TITLECASE_LETTER | U_TITLECASE_LETTER | 表示首字母大写。 | +| U_MODIFIER_LETTER | U_MODIFIER_LETTER | 表示字母修饰符。 | +| U_OTHER_LETTER | U_OTHER_LETTER | 表示其它字母,不属于大写字母、小写字母、首字母大写或修饰符字母的字母。 | +| U_NON_SPACING_MARK | U_NON_SPACING_MARK | 表示非间距标记,如重音符号',变音符号#。 | +| U_ENCLOSING_MARK | U_ENCLOSING_MARK | 表示封闭标记和能围住其它字符的标记,如圆圈、方框等。 | +| U_COMBINING_SPACING_MARK | U_COMBINING_SPACING_MARK | 表示间距标记,如元音符号[ ]。 | +| U_DECIMAL_DIGIT_NUMBER | U_DECIMAL_DIGIT_NUMBER | 表示十进制数字。 | +| U_LETTER_NUMBER | U_LETTER_NUMBER | 表示字母数字,罗马数字。 | +| U_OTHER_NUMBER | U_OTHER_NUMBER | 表示其它作为加密符号和记号的数字,非阿拉伯数字的数字表示符,如@、#、(1)、①等。 | +| U_SPACE_SEPARATOR | U_SPACE_SEPARATOR | 表示空白分隔符,如空格符、不间断空格、固定宽度的空白符。 | +| U_LINE_SEPARATOR | U_LINE_SEPARATOR | 表示行分隔符。| +| U_PARAGRAPH_SEPARATOR | U_PARAGRAPH_SEPARATOR | 表示段落分割符。 | +| U_CONTROL_CHAR | U_CONTROL_CHAR | 表示控制字符。 | +| U_FORMAT_CHAR | U_FORMAT_CHAR | 表示格式字符。 | +| U_PRIVATE_USE_CHAR | U_PRIVATE_USE_CHAR | 表示私人使用区代码点类别,例如公司 logo。 | +| U_SURROGATE | U_SURROGATE | 表示代理项,在UTF-16中用来表示补充字符的方法。 | +| U_DASH_PUNCTUATION | U_DASH_PUNCTUATION | 表示短划线标点。 | +| U_START_PUNCTUATION | U_START_PUNCTUATION | 表示开始标点,如左括号。 | +| U_END_PUNCTUATION | U_END_PUNCTUATION | 表示结束标点,如右括号。 | +| U_INITIAL_PUNCTUATION | U_INITIAL_PUNCTUATION | 表示前引号,如左双引号、左单引号。 | +| U_FINAL_PUNCTUATION | U_FINAL_PUNCTUATION | 表示后引号,如右双引号、右单引号。 | +| U_CONNECTOR_PUNCTUATION | U_CONNECTOR_PUNCTUATION | 表示连接符标点。 | +| U_OTHER_PUNCTUATION | U_OTHER_PUNCTUATION | 表示其他标点。 | +| U_MATH_SYMBOL | U_MATH_SYMBOL | 表示数学符号。 | +| U_CURRENCY_SYMBOL | U_CURRENCY_SYMBOL | 表示货币符号。 | +| U_MODIFIER_SYMBOL | U_MODIFIER_SYMBOL | 表示修饰符号。 | +| U_OTHER_SYMBOL | U_OTHER_SYMBOL | 表示其它符号。 | + +**示例:** ```ts - // 使用 en-GB locale创建RelativeTimeFormat对象 - let relativetimefmt= new Intl.RelativeTimeFormat("en-GB", { style: "short" }); - // 获取RelativeTimeFormat对象配置项 - let options = relativetimefmt.resolvedOptions(); - let style = options.style; // style = "short" + let type: string = I18n.Unicode.getType("a"); // type = "U_LOWERCASE_LETTER" ``` -## RelativeTimeFormatInputOptions8+ +## I18NUtil9+ -表示RelativeTimeFormat对象可设置的属性。 -从API9开始,RelativeTimeFormatInputOptions中的属性改为可选。 +### getDateOrder9+ + +static getDateOrder(locale: string): string + +获取该区域日期中年、月、日的排列顺序。 **系统能力**:SystemCapability.Global.I18n -| 名称 | 类型 | 可读 | 可写 | 说明 | -| ------------- | ------ | ---- | ---- | ---------------------------------------- | -| localeMatcher | string | 是 | 是 | locale匹配算法,取值包括:"best fit", "lookup"。localeMatcher属性默认值为best fit。 | -| numeric | string | 是 | 是 | 输出消息的格式,取值包括:"always", "auto"。numeric属性默认值为always。 | -| style | string | 是 | 是 | 国际化消息的长度,取值包括:"long", "short", "narrow"。style属性默认值为long。 | +**参数:** -## RelativeTimeFormatResolvedOptions8+ +| 参数名 | 类型 | 必填 | 说明 | +| ------ | ------ | ---- | ------------------------- | +| locale | string | 是 | 格式化时使用的区域参数,如:zh-Hans-CN。 | -表示RelativeTimeFormat对象可设置的属性。 +**返回值:** -**系统能力**:SystemCapability.Global.I18n +| 类型 | 说明 | +| ------ | ------------------- | +| string | 返回该区域年、月、日的排列顺序。 | -| 名称 | 类型 | 可读 | 可写 | 说明 | -| --------------- | ------ | ---- | ---- | ---------------------------------------- | -| locale | string | 是 | 是 | 包含区域设置信息的字符串,包括语言以及可选的脚本和区域。 | -| numeric | string | 是 | 是 | 输出消息的格式,取值包括:"always", "auto"。 | -| style | string | 是 | 是 | 国际化消息的长度,取值包括:"long", "short", "narrow"。 | -| numberingSystem | string | 是 | 是 | 使用的数字系统。 | +**示例:** + ```ts + let order: string = I18n.I18NUtil.getDateOrder("zh-CN"); // order = "y-L-d" + ``` -- Gitee From 56cfdadba92c8485bb5174f0e6c6d4e5c1fccb81 Mon Sep 17 00:00:00 2001 From: LY Date: Wed, 8 Nov 2023 11:42:07 +0000 Subject: [PATCH 3/3] update zh-cn/application-dev/reference/apis/js-apis-intl.md. Signed-off-by: LY --- .../reference/apis/js-apis-intl.md | 155 +++++++++--------- 1 file changed, 77 insertions(+), 78 deletions(-) diff --git a/zh-cn/application-dev/reference/apis/js-apis-intl.md b/zh-cn/application-dev/reference/apis/js-apis-intl.md index be0b571..1025892 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-intl.md +++ b/zh-cn/application-dev/reference/apis/js-apis-intl.md @@ -27,7 +27,7 @@ import Intl from '@ohos.intl'; | 名称 | 类型 | 可读 | 可写 | 说明 | | --------------- | ------- | ---- | ---- | ---------------------------------------- | -| language | string | 是 | 否 | 与区域设置关联的语, 如:zh。 | +| language | string | 是 | 否 | 与区域设置相关的语言,如:zh。 | | script | string | 是 | 否 | 语言的书写方式,如:Hans。 | | region | string | 是 | 否 | 与区域设置相关的地区,如:CN。 | | baseName | string | 是 | 否 | Locale的基本核心信息(由语言脚本与地区组成),如:zh-Hans-CN。 | @@ -36,7 +36,7 @@ import Intl from '@ohos.intl'; | collation | string | 是 | 否 | 区域的排序规则,取值包括:"big5han", "compat", "dict", "direct", "ducet", "eor", "gb2312", "phonebk", "phonetic", "pinyin", "reformed", "searchjl", "stroke", "trad", "unihan", "zhuyin"。 | | hourCycle | string | 是 | 否 | 区域的时制信息,取值包括:"h12", "h23", "h11", "h24"。 | | numberingSystem | string | 是 | 否 | 区域使用的数字系统,取值包括:"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 | 是 | 否 | 是否对数字字符具有特殊的排序规则处理。 | +| numeric | boolean | 是 | 否 | 是否对数字字符具有特殊的排序规则处理。默认值:false。 | ### constructor8+ @@ -48,7 +48,7 @@ constructor() **系统能力**:SystemCapability.Global.I18n **示例:** - ```js + ```ts // 默认构造函数使用系统当前locale创建Locale对象 let locale = new Intl.Locale(); // 返回系统当前localel @@ -68,11 +68,11 @@ constructor(locale: string, options?: LocaleOptions) | 参数名 | 类型 | 必填 | 说明 | | -------------------- | -------------------------------- | ---- | ---------------------------- | -| locale | string | 是 | 包含区域信息的字符串,包括语言以、脚本、国家或地区。 | -| options | [LocaleOptions](#localeoptions6) | 否 | 用于创建区域对象的选项。 | +| locale | string | 是 | 区域信息的字符串,由语言、脚本、国家或地区组成。 | +| options | [LocaleOptions](#localeoptions6) | 否 | 用于创建区域对象的选项。 | **示例:** - ```js + ```ts // 创建 "zh-CN" Locale对象 let locale = new Intl.Locale("zh-CN"); let localeID = locale.toString(); // localeID = "zh-CN" @@ -94,7 +94,7 @@ toString(): string | string | 区域对象的字符串表示。 | **示例:** - ```js + ```ts // 创建 "en-GB" Locale对象 let locale = new Intl.Locale("en-GB"); let localeID = locale.toString(); // localeID = "en-GB" @@ -116,7 +116,7 @@ maximize(): Locale | [Locale](#locale) | 最大化后的区域对象。 | **示例:** - ```js + ```ts // 创建 "zh" Locale对象 let locale = new Intl.Locale("zh"); // 补齐Locale对象的脚本和地区 @@ -146,7 +146,7 @@ minimize(): Locale | [Locale](#locale) | 最小化后的区域对象。 | **示例:** - ```js + ```ts // 创建 "zh-Hans-CN" Locale对象 let locale = new Intl.Locale("zh-Hans-CN"); // 去除Locale对象的脚本和地区 @@ -164,7 +164,7 @@ minimize(): Locale ## LocaleOptions6+ 表示区域初始化选项。 -在API9中,LocaleOptions中的属性修改为可选属性。 +从API9开始,LocaleOptions中的属性改为可选。 **系统能力**:SystemCapability.Global.I18n @@ -174,7 +174,7 @@ minimize(): Locale | collation | string | 是 | 是 | 排序参数,取值包括:"big5han", "compat", "dict", "direct", "ducet", "emoji", "eor", "gb2312", "phonebk", "phonetic", "pinyin", "reformed ", "search", "searchjl", "standard", "stroke", "trad", "unihan", "zhuyin"。 | | hourCycle | string | 是 | 是 | 时制格式,取值包括:"h11", "h12", "h23", "h24"。 | | numberingSystem | string | 是 | 是 | 数字系统,取值包括:"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 | 是 | 是 | 是否使用12小时制。 | +| numeric | boolean | 是 | 是 | 是否使用12小时制。默认值:false。 | | caseFirst | string | 是 | 是 | 表示大写、小写的排序顺序,取值范围:"upper", "lower", "false"。 | @@ -190,7 +190,7 @@ constructor() **系统能力**:SystemCapability.Global.I18n **示例:** - ```js + ```ts // 使用系统当前locale创建DateTimeFormat对象 let datefmt= new Intl.DateTimeFormat(); ``` @@ -209,17 +209,17 @@ constructor(locale: string | Array<string>, options?: DateTimeOptions) | 参数名 | 类型 | 必填 | 说明 | | -------------------- | ------------------------------------ | ---- | ---------------------------- | | locale | string \| Array<string> | 是 | 包含区域设置信息的字符串,包括语言以及可选的脚本和区域。 | -| options | [DateTimeOptions](#datetimeoptions6) | 否 | 用于创建时间日期格式化的选项。 | +| options | [DateTimeOptions](#datetimeoptions6) | 否 | 用于创建时间日期格式化的选项。若所有选项均未设置时,year、month、day三个属性的默认值为numeric。 | **示例:** - ```js + ```ts // 使用 "zh-CN" locale创建DateTimeFormat对象,日期风格为full,时间风格为medium let datefmt= new Intl.DateTimeFormat("zh-CN", { dateStyle: 'full', timeStyle: 'medium' }); ``` **示例:** - ```js + ```ts // 使用 ["ban", "zh"] locale列表创建DateTimeFormat对象,因为ban为非法LocaleID,因此使用zh Locale创建DateTimeFormat对象 let datefmt= new Intl.DateTimeFormat(["ban", "zh"], { dateStyle: 'full', timeStyle: 'medium' }); ``` @@ -246,7 +246,7 @@ format(date: Date): string | string | 格式化后的时间日期字符串 | **示例:** - ```js + ```ts let date = new Date(2021, 11, 17, 3, 24, 0); // 使用 en-GB locale创建DateTimeFormat对象 let datefmt = new Intl.DateTimeFormat("en-GB"); @@ -280,7 +280,7 @@ formatRange(startDate: Date, endDate: Date): string | string | 格式化后的时间日期段字符串。 | **示例:** - ```js + ```ts let startDate = new Date(2021, 11, 17, 3, 24, 0); let endDate = new Date(2021, 11, 18, 3, 24, 0); // 使用 en-GB locale创建DateTimeFormat对象 @@ -304,7 +304,7 @@ resolvedOptions(): DateTimeOptions | [DateTimeOptions](#datetimeoptions6) | DateTimeFormat 对象的格式化选项。 | **示例:** - ```js + ```ts let datefmt = new Intl.DateTimeFormat("en-GB", { dateStyle: 'full', timeStyle: 'medium' }); // 返回DateTimeFormat对象的配置项 let options = datefmt.resolvedOptions(); @@ -316,7 +316,7 @@ resolvedOptions(): DateTimeOptions ## DateTimeOptions6+ 表示时间日期格式化选项。 -在API9中,DateTimeOptions中的属性修改为可选属性。 +从API9开始,DateTimeOptions中的属性改为可选。 **系统能力**:SystemCapability.Global.I18n @@ -328,7 +328,7 @@ resolvedOptions(): DateTimeOptions | hourCycle | string | 是 | 是 | 时制格式,取值包括:"h11", "h12", "h23", "h24"。 | | timeZone | string | 是 | 是 | 使用的时区(合法的IANA时区ID)。 | | numberingSystem | string | 是 | 是 | 数字系统,取值包括:"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"。 | -| hour12 | boolean | 是 | 是 | 是否使用12小时制。 | +| hour12 | boolean | 是 | 是 | 是否使用12小时制。若hour12和hourCycle未设置且系统24小时开关打开时,hour12属性的默认值为false。 | | weekday | string | 是 | 是 | 工作日的显示格式,取值包括:"long", "short", "narrow"。 | | era | string | 是 | 是 | 时代的显示格式,取值包括:"long", "short", "narrow"。 | | year | string | 是 | 是 | 年份的显示格式,取值包括:"numeric", "2-digit"。 | @@ -355,7 +355,7 @@ constructor() **系统能力**:SystemCapability.Global.I18n **示例:** - ```js + ```ts // 使用系统当前locale创建NumberFormat对象 let numfmt = new Intl.NumberFormat(); ``` @@ -377,7 +377,7 @@ constructor(locale: string | Array<string>, options?: NumberOptions) | options | [NumberOptions](#numberoptions6) | 否 | 用于创建数字格式化的选项。 | **示例:** - ```js + ```ts // 使用 en-GB locale创建NumberFormat对象,style设置为decimal,notation设置为scientific let numfmt = new Intl.NumberFormat("en-GB", {style:'decimal', notation:"scientific"}); ``` @@ -405,7 +405,7 @@ format(number: number): string; **示例:** - ```js + ```ts // 使用 ["en-GB", "zh"] locale列表创建NumberFormat对象,因为en-GB为合法LocaleID,因此使用en-GB创建NumberFormat对象 let numfmt = new Intl.NumberFormat(["en-GB", "zh"], {style:'decimal', notation:"scientific"}); let formattedNumber = numfmt.format(1223); // formattedNumber = 1.223E3 @@ -428,7 +428,7 @@ resolvedOptions(): NumberOptions **示例:** - ```js + ```ts let numfmt = new Intl.NumberFormat(["en-GB", "zh"], {style:'decimal', notation:"scientific"}); // 获取NumberFormat对象配置项 let options = numfmt.resolvedOptions(); @@ -440,31 +440,31 @@ resolvedOptions(): NumberOptions ## NumberOptions6+ 表示设备支持的能力。 -在API9中,NumberOptions中的属性修改为可选属性。 +从API9开始,NumberOptions中的属性改为可选。 **系统能力**:SystemCapability.Global.I18n | 名称 | 类型 | 可读 | 可写 | 说明 | | ------------------------ | ------- | ---- | ---- | ---------------------------------------- | -| locale | string | 是 | 否 | 区域参数, 如:"zh-Hans-CN"。 | +| locale | string | 是 | 否 | 区域参数, 如:"zh-Hans-CN"。locale属性默认值为系统Locale。 | | currency | string | 是 | 是 | 货币单位, 如:"EUR","CNY","USD"等。 | -| currencySign | string | 是 | 是 | 货币单位的符号显示,取值包括: "symbol","narrowSymbol","code","name" 。 | -| currencyDisplay | string | 是 | 是 | 货币的显示方式,取值包括:"symbol", "narrowSymbol", "code", "name"。 | +| currencySign | string | 是 | 是 | 货币单位的符号显示,取值包括: "standard","accounting"。currencySign属性默认值为standard。 | +| currencyDisplay | string | 是 | 是 | 货币的显示方式,取值包括:"symbol", "narrowSymbol", "code", "name"。currencyDisplay属性默认值为symbol。 | | unit | string | 是 | 是 | 单位名称,如:"meter","inch",“hectare”等。 | -| unitDisplay | string | 是 | 是 | 单位的显示格式,取值包括:"long", "short", "narrow"。 | -| unitUsage8+ | string | 是 | 是 | 单位的使用场景,取值包括:"default", "area-land-agricult", "area-land-commercl", "area-land-residntl", "length-person", "length-person-small", "length-rainfall", "length-road", "length-road-small", "length-snowfall", "length-vehicle", "length-visiblty", "length-visiblty-small", "length-person-informal", "length-person-small-informal", "length-road-informal", "speed-road-travel", "speed-wind", "temperature-person", "temperature-weather", "volume-vehicle-fuel"。 | -| signDisplay | string | 是 | 是 | 数字符号的显示格式,取值包括:"auto", "never", "always", "expectZero"。 | -| compactDisplay | string | 是 | 是 | 紧凑型的显示格式,取值包括:"long", "short"。 | -| notation | string | 是 | 是 | 数字的格式化规格,取值包括:"standard", "scientific", "engineering", "compact"。 | -| localeMatcher | string | 是 | 是 | 要使用的区域匹配算法,取值包括:"lookup", "best fit"。 | -| style | string | 是 | 是 | 数字的显示格式,取值包括:"decimal", "currency", "percent", "unit"。 | -| numberingSystem | string | 是 | 是 | 数字系统,取值包括:"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"。 | -| useGrouping | boolean | 是 | 是 | 是否分组显示。 | -| minimumIntegerDigits | number | 是 | 是 | 表示要使用的最小整数位数,取值范围:1~21。 | -| minimumFractionDigits | number | 是 | 是 | 表示要使用的最小分数位数,取值范围:0~20。 | -| maximumFractionDigits | number | 是 | 是 | 表示要使用的最大分数位数,取值范围:1~21。 | -| minimumSignificantDigits | number | 是 | 是 | 表示要使用的最低有效位数,取值范围:1~21。 | -| maximumSignificantDigits | number | 是 | 是 | 表示要使用的最大有效位数,取值范围:1~21。 | +| unitDisplay | string | 是 | 是 | 单位的显示格式,取值包括:"long", "short", "narrow"。unitDisplay属性默认值为short。 | +| unitUsage8+ | string | 是 | 是 | 单位的使用场景,取值包括:"default", "area-land-agricult", "area-land-commercl", "area-land-residntl", "length-person", "length-person-small", "length-rainfall", "length-road", "length-road-small", "length-snowfall", "length-vehicle", "length-visiblty", "length-visiblty-small", "length-person-informal", "length-person-small-informal", "length-road-informal", "speed-road-travel", "speed-wind", "temperature-person", "temperature-weather", "volume-vehicle-fuel"。unitUsage属性默认值为default。 | +| signDisplay | string | 是 | 是 | 数字符号的显示格式,取值包括:"auto", "never", "always", "expectZero"。signDisplay属性默认值为auto。 | +| compactDisplay | string | 是 | 是 | 紧凑型的显示格式,取值包括:"long", "short"。compactDisplay属性默认值为short。 | +| notation | string | 是 | 是 | 数字的格式化规格,取值包括:"standard", "scientific", "engineering", "compact"。notation属性默认值为standard。 | +| localeMatcher | string | 是 | 是 | 要使用的区域匹配算法,取值包括:"lookup", "best fit"。localeMatcher属性默认值为best fit。 | +| style | string | 是 | 是 | 数字的显示格式,取值包括:"decimal", "currency", "percent", "unit"。style属性默认值为decimal。 | +| numberingSystem | string | 是 | 是 | 数字系统,取值包括:"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属性默认值为locale的默认数字系统。 | +| useGrouping | boolean | 是 | 是 | 是否分组显示。useGrouping属性默认值为auto。 | +| minimumIntegerDigits | number | 是 | 是 | 表示要使用的最小整数位数,取值范围:1~21。minimumIntegerDigits属性默认值为1。 | +| minimumFractionDigits | number | 是 | 是 | 表示要使用的最小分数位数,取值范围:0~20。minimumFractionDigits属性默认值为0。 | +| maximumFractionDigits | number | 是 | 是 | 表示要使用的最大分数位数,取值范围:1~21。maximumFractionDigits属性默认值为3。 | +| minimumSignificantDigits | number | 是 | 是 | 表示要使用的最低有效位数,取值范围:1~21。minimumSignificantDigits属性默认值为1。 | +| maximumSignificantDigits | number | 是 | 是 | 表示要使用的最大有效位数,取值范围:1~21。maximumSignificantDigits属性默认值为21。 | ## Collator8+ @@ -479,7 +479,7 @@ constructor() **系统能力**:SystemCapability.Global.I18n **示例:** - ```js + ```ts // 使用系统locale创建Collator对象 let collator = new Intl.Collator(); ``` @@ -498,10 +498,10 @@ constructor(locale: string | Array<string>, options?: CollatorOptions) | 参数名 | 类型 | 必填 | 说明 | | -------------------- | ------------------------------------ | ---- | ---------------------------- | | locale | string \| Array<string> | 是 | 包含区域设置信息的字符串,包括语言以及可选的脚本和区域。 | -| options | [CollatorOptions](#collatoroptions8) | 否 | 用于创建排序对象的选项。 | +| options | [CollatorOptions](#collatoroptions8) | 否 | 用于创建排序对象的选项。 | **示例:** - ```js + ```ts // 使用 zh-CN locale创建Collator对象,localeMatcher设置为lookup,usage设置为sort let collator = new Intl.Collator("zh-CN", {localeMatcher: "lookup", usage: "sort"}); ``` @@ -529,7 +529,7 @@ compare(first: string, second: string): number | number | 比较结果。当number为负数,表示first排序在second之前;当number为0,表示first与second排序相同;当number为正数,表示first排序在second之后。 | **示例:** - ```js + ```ts // 使用en-GB locale创建Collator对象 let collator = new Intl.Collator("en-GB"); // 比较 "first" 和 "second" 的先后顺序 @@ -552,7 +552,7 @@ resolvedOptions(): CollatorOptions | [CollatorOptions](#collatoroptions8) | 返回的Collator对象的属性。 | **示例:** - ```js + ```ts let collator = new Intl.Collator("zh-Hans", { usage: 'sort', ignorePunctuation: true }); // 获取Collator对象的配置项 let options = collator.resolvedOptions(); @@ -564,19 +564,19 @@ resolvedOptions(): CollatorOptions ## CollatorOptions8+ 表示Collator可设置的属性。 -在API9中,CollatorOptions中的属性修改为可选属性。 +从API9中,CollatorOptions中的属性改为可选。 **系统能力**:SystemCapability.Global.I18n | 名称 | 类型 | 可读 | 可写 | 说明 | | ----------------- | ------- | ---- | ---- | ---------------------------------------- | -| localeMatcher | string | 是 | 是 | locale匹配算法,取值范围:"best fit", "lookup"。 | -| usage | string | 是 | 是 | 比较的用途,取值范围:"sort", "search"。 | -| sensitivity | string | 是 | 是 | 表示字符串中的哪些差异会导致非零结果值,取值范围:"base", "accent", "case", "letiant"。 | -| ignorePunctuation | boolean | 是 | 是 | 表示是否忽略标点符号,取值范围:true, false。 | -| collation | string | 是 | 是 | 排序规则,取值范围:"big5han", "compat", "dict", "direct", "ducet", "eor", "gb2312", "phonebk", "phonetic", "pinyin", "reformed", "searchjl", "stroke", "trad", "unihan", "zhuyin"。 | -| numeric | boolean | 是 | 是 | 是否使用数字排序,取值范围:true, false。 | -| caseFirst | string | 是 | 是 | 表示大写、小写的排序顺序,取值范围:"upper", "lower", "false"。 | +| localeMatcher | string | 是 | 是 | locale匹配算法,取值范围:"best fit", "lookup"。localeMatcher属性默认值为best fit。 | +| usage | string | 是 | 是 | 比较的用途,取值范围:"sort", "search"。usage属性默认值为sort。 | +| sensitivity | string | 是 | 是 | 表示字符串中的哪些差异会导致非零结果值,取值范围:"base", "accent", "case", "letiant"。sensitivity属性默认值为variant。 | +| ignorePunctuation | boolean | 是 | 是 | 表示是否忽略标点符号,取值范围:true, false。ignorePunctuation属性默认值为false。 | +| collation | string | 是 | 是 | 排序规则,取值范围:"big5han", "compat", "dict", "direct", "ducet", "eor", "gb2312", "phonebk", "phonetic", "pinyin", "reformed", "searchjl", "stroke", "trad", "unihan", "zhuyin"。collation属性默认值为default。 | +| numeric | boolean | 是 | 是 | 是否使用数字排序,取值范围:true, false。numeric属性默认值为false。 | +| caseFirst | string | 是 | 是 | 表示大写、小写的排序顺序,取值范围:"upper", "lower", "false"。caseFirst属性默认值为false | ## PluralRules8+ @@ -591,7 +591,7 @@ constructor() **系统能力**:SystemCapability.Global.I18n **示例:** - ```js + ```ts // 使用系统locale创建PluralRules对象 let pluralRules = new Intl.PluralRules(); ``` @@ -610,10 +610,10 @@ constructor(locale: string | Array<string>, options?: PluralRulesOptions) | 参数名 | 类型 | 必填 | 说明 | | -------------------- | ---------------------------------------- | ---- | ---------------------------- | | locale | string \| Array<string> | 是 | 包含区域设置信息的字符串,包括语言以及可选的脚本和区域。 | -| options | [PluralRulesOptions](#pluralrulesoptions8) | 否 | 用于创建单复数对象的选项。 | +| options | [PluralRulesOptions](#pluralrulesoptions8) | 否 | 用于创建单复数对象的选项。 | **示例:** - ```js + ```ts // 使用 zh-CN locale创建PluralRules对象,localeMatcher设置为lookup,type设置为cardinal let pluralRules= new Intl.PluralRules("zh-CN", {"localeMatcher": "lookup", "type": "cardinal"}); ``` @@ -640,7 +640,7 @@ select(n: number): string | string | 单复数类别,取值包括:"zero","one","two", "few", "many", "others"。 | **示例:** - ```js + ```ts // 使用 zh-Hans locale创建PluralRules对象 let zhPluralRules = new Intl.PluralRules("zh-Hans"); // 计算 zh-Hans locale中数字1对应的单复数类别 @@ -656,19 +656,19 @@ select(n: number): string ## PluralRulesOptions8+ 表示PluralRules对象可设置的属性。 -在API9中,PluralRulesOptions中的属性修改为可选属性。 +从API9开始,PluralRulesOptions中的属性改为可选。 **系统能力**:SystemCapability.Global.I18n | 名称 | 类型 | 可读 | 可写 | 说明 | | ------------------------ | ------ | ---- | ---- | ---------------------------------------- | -| localeMatcher | string | 是 | 是 | locale匹配算法,取值包括:"best fit", "lookup"。 | -| type | string | 是 | 是 | 排序的类型,取值包括:"cardinal", "ordinal"。 | -| minimumIntegerDigits | number | 是 | 是 | 表示要使用的最小整数位数,取值范围:1~21。 | -| minimumFractionDigits | number | 是 | 是 | 表示要使用的最小分数位数,取值范围:0~20。 | -| maximumFractionDigits | number | 是 | 是 | 表示要使用的最大分数位数,取值范围:1~21。 | -| minimumSignificantDigits | number | 是 | 是 | 表示要使用的最低有效位数,取值范围:1~21。 | -| maximumSignificantDigits | number | 是 | 是 | 表示要使用的最大有效位数,取值范围:1~21。 | +| localeMatcher | string | 是 | 是 | locale匹配算法,取值包括:"best fit", "lookup"。localeMatcher属性默认值为best fit。 | +| type | string | 是 | 是 | 排序的类型,取值包括:"cardinal", "ordinal"。type属性默认值为cardinal。 | +| minimumIntegerDigits | number | 是 | 是 | 表示要使用的最小整数位数,取值范围:1~21。minimumIntegerDigits属性默认值为1。 | +| minimumFractionDigits | number | 是 | 是 | 表示要使用的最小分数位数,取值范围:0~20。minimumFractionDigits属性默认值为0。 | +| maximumFractionDigits | number | 是 | 是 | 表示要使用的最大分数位数,取值范围:1~21。maximumFractionDigits属性默认值为3。 | +| minimumSignificantDigits | number | 是 | 是 | 表示要使用的最低有效位数,取值范围:1~21。minimumSignificantDigits属性默认值为1。 | +| maximumSignificantDigits | number | 是 | 是 | 表示要使用的最大有效位数,取值范围:1~21。maximumSignificantDigits属性默认值为21。 | ## RelativeTimeFormat8+ @@ -683,7 +683,7 @@ constructor() **系统能力**:SystemCapability.Global.I18n **示例:** - ```js + ```ts // 使用系统locale创建RelativeTimeFormat对象 let relativetimefmt = new Intl.RelativeTimeFormat(); ``` @@ -705,7 +705,7 @@ constructor(locale: string | Array<string>, options?: RelativeTimeFormatIn | options | [RelativeTimeFormatInputOptions](#relativetimeformatinputoptions8) | 否 | 用于创建相对时间格式化对象的选项。 | **示例:** - ```js + ```ts // 使用 zh-CN locale创建RelativeTimeFormat对象,localeMatcher设置为lookup,numeric设置为always,style设置为long let relativeTimeFormat = new Intl.RelativeTimeFormat("zh-CN", {"localeMatcher": "lookup", "numeric": "always", "style": "long"}); ``` @@ -733,7 +733,7 @@ format(value: number, unit: string): string | string | 格式化后的相对时间。 | **示例:** - ```js + ```ts // 使用 zh-CN locale创建RelativeTimeFormat对象 let relativetimefmt = new Intl.RelativeTimeFormat("zh-CN"); // 计算 zh-CN locale中数字3,单位quarter的本地化表示 @@ -763,7 +763,7 @@ formatToParts(value: number, unit: string): Array<object> | Array<object> | 返回可用于自定义区域设置格式的相对时间格式的对象数组。 | **示例:** - ```js + ```ts // 使用 en locale创建RelativeTimeFormat对象,numeric设置为auto let relativetimefmt = new Intl.RelativeTimeFormat("en", {"numeric": "auto"}); let parts = relativetimefmt.formatToParts(10, "seconds"); // parts = [ {type: "literal", value: "in"}, {type: "integer", value: 10, unit: "second"}, {type: "literal", value: "seconds"} ] @@ -785,7 +785,7 @@ resolvedOptions(): RelativeTimeFormatResolvedOptions | [RelativeTimeFormatResolvedOptions](#relativetimeformatresolvedoptions8) | RelativeTimeFormat 对象的格式化选项。 | **示例:** - ```js + ```ts // 使用 en-GB locale创建RelativeTimeFormat对象 let relativetimefmt= new Intl.RelativeTimeFormat("en-GB", { style: "short" }); // 获取RelativeTimeFormat对象配置项 @@ -797,15 +797,14 @@ resolvedOptions(): RelativeTimeFormatResolvedOptions ## RelativeTimeFormatInputOptions8+ 表示RelativeTimeFormat对象可设置的属性。 -在API9中,RelativeTimeFormatInputOptions中的属性修改为可选属性。 +从API9开始,RelativeTimeFormatInputOptions中的属性改为可选。 **系统能力**:SystemCapability.Global.I18n - | 名称 | 类型 | 可读 | 可写 | 说明 | | ------------- | ------ | ---- | ---- | ---------------------------------------- | -| localeMatcher | string | 是 | 是 | locale匹配算法,取值包括:"best fit", "lookup"。 | -| numeric | string | 是 | 是 | 输出消息的格式,取值包括:"always", "auto"。 | -| style | string | 是 | 是 | 国际化消息的长度,取值包括:"long", "short", "narrow"。 | +| localeMatcher | string | 是 | 是 | locale匹配算法,取值包括:"best fit", "lookup"。localeMatcher属性默认值为best fit。 | +| numeric | string | 是 | 是 | 输出消息的格式,取值包括:"always", "auto"。numeric属性默认值为always。 | +| style | string | 是 | 是 | 国际化消息的长度,取值包括:"long", "short", "narrow"。style属性默认值为long。 | ## RelativeTimeFormatResolvedOptions8+ @@ -819,4 +818,4 @@ resolvedOptions(): RelativeTimeFormatResolvedOptions | locale | string | 是 | 是 | 包含区域设置信息的字符串,包括语言以及可选的脚本和区域。 | | numeric | string | 是 | 是 | 输出消息的格式,取值包括:"always", "auto"。 | | style | string | 是 | 是 | 国际化消息的长度,取值包括:"long", "short", "narrow"。 | -| numberingSystem | string | 是 | 是 | 使用的数字系统。 | +| numberingSystem | string | 是 | 是 | 使用的数字系统。 | \ No newline at end of file -- Gitee