diff --git a/en/application-dev/reference/apis/js-apis-i18n.md b/en/application-dev/reference/apis/js-apis-i18n.md index 27dc8eb464f9615f0b61462a5f7f81d71195d1f1..7a604fdd852e43c09c418312c6797ea96e7fc6e0 100644 --- a/en/application-dev/reference/apis/js-apis-i18n.md +++ b/en/application-dev/reference/apis/js-apis-i18n.md @@ -1,2665 +1,1252 @@ -# Internationalization \(i18n\) +# Internationalization – i18n ->![](public_sys-resources/icon-note.gif) **NOTE:** ->- The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. ->- This module contains enhanced i18n APIs, which are not defined in ECMA 402. +> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** +> - The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. +> +> - This module contains enhanced i18n APIs, which are not defined in ECMA 402. -## Modules to Import + +## Modules to Import ``` import i18n from '@ohos.i18n'; ``` -## Required Permissions - -None -## i18n.getDisplayLanguage +## i18n.getDisplayLanguage -getDisplayLanguage\(language: string, locale: string, sentenceCase?: boolean\): string +getDisplayLanguage(language: string, locale: string, sentenceCase?: boolean): string Obtains the localized script for the specified language. -- Parameters - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

language

-

string

-

Yes

-

Specified language.

-

locale

-

string

-

Yes

-

Locale ID.

-

sentenceCase

-

boolean

-

No

-

Whether to use sentence case for the localized script.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

string

-

Localized script for the specified language.

-
- -- Example - - ``` - I18n.getDisplayLanguage("zh", "en-GB", true); - I18n.getDisplayLanguage("zh", "en-GB"); - ``` - - -## i18n.getDisplayCountry - -getDisplayCountry\(country: string, locale: string, sentenceCase?: boolean\): string +**System capability**: SystemCapability.Global.I18n + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | language | string | Yes| Specified language.| + | locale | string | Yes| Locale ID.| + | sentenceCase | boolean | No| Whether to use sentence case for the localized script.| + +- Return value + | Type| Description| + | -------- | -------- | + | string | Localized script for the specified language.| + +- Example + ``` + i18n.getDisplayLanguage("zh", "en-GB", true); + i18n.getDisplayLanguage("zh", "en-GB"); + ``` + + +## i18n.getDisplayCountry + +getDisplayCountry(country: string, locale: string, sentenceCase?: boolean): string Obtains the localized script for the specified country. -- Parameters - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

country

-

string

-

Yes

-

Specified country.

-

locale

-

string

-

Yes

-

Locale ID.

-

sentenceCase

-

boolean

-

No

-

Whether to use sentence case for the localized script.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

string

-

Localized script for the specified country.

-
- -- Example - - ``` - I18n.getDisplayCountry("zh-CN", "en-GB", true); - I18n.getDisplayCountry("zh-CN", "en-GB"); - ``` - - -## i18n.isRTL8+ - -isRTL\(locale: string\): boolean +**System capability**: SystemCapability.Global.I18n + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | country | string | Yes| Specified country.| + | locale | string | Yes| Locale ID.| + | sentenceCase | boolean | No| Whether to use sentence case for the localized script.| + +- Return value + | Type| Description| + | -------- | -------- | + | string | Localized script for the specified country.| + +- Example + ``` + i18n.getDisplayCountry("zh-CN", "en-GB", true); + i18n.getDisplayCountry("zh-CN", "en-GB"); + ``` + + +## i18n.isRTL8+ + +isRTL(locale: string): boolean Checks whether the localized script for the specified language is displayed from right to left. -- Parameters - - - - - - - - - - - - -

Name

-

Type

-

Description

-

locale

-

string

-

Locale ID.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

The value true indicates that the localized script is displayed from right to left, and value false indicates the opposite.

-
- -- Example - - ``` - i18n.isRTL("zh-CN");// Since Chinese is not written from right to left, false is returned. - i18n.isRTL("ar-EG");// Since Arabic is written from right to left, true is returned. - ``` - - -## i18n.getSystemLanguage - -getSystemLanguage\(\): string +**System capability**: SystemCapability.Global.I18n -Obtains the system language. +- Parameters + | Name| Type| Description| + | -------- | -------- | -------- | + | locale | string | Locale ID.| -- Return values +- Return value + | Type| Description| + | -------- | -------- | + | boolean | The value **true** indicates that the localized script is displayed from right to left, and value **false** indicates the opposite.| - - - - - - - - - -

Type

-

Description

-

string

-

System language ID.

-
+- Example + ``` + i18n.isRTL("zh-CN");// Since Chinese is not written from right to left, false is returned. + i18n.isRTL("ar-EG");// Since Arabic is written from right to left, true is returned. + ``` -- Example - ``` - I18n.getSystemLanguage(); - ``` +## i18n.getSystemLanguage +getSystemLanguage(): string -## i18n.getSystemRegion +Obtains the system language. -getSystemRegion\(\): string +**System capability**: SystemCapability.Global.I18n + +- Return value + | Type| Description| + | -------- | -------- | + | string | System language ID.| + +- Example + ``` + i18n.getSystemLanguage(); + ``` -Obtains the system region. -- Return values +## i18n.getSystemRegion - - - - - - - - - -

Type

-

Description

-

string

-

System region ID.

-
+getSystemRegion(): string -- Example +Obtains the system region. + +**System capability**: SystemCapability.Global.I18n + +- Return value + | Type| Description| + | -------- | -------- | + | string | System region ID.| - ``` - I18n.getSystemRegion(); - ``` +- Example + ``` + i18n.getSystemRegion(); + ``` -## i18n.getSystemLocale +## i18n.getSystemLocale -getSystemLocale\(\): string +getSystemLocale(): string Obtains the system locale. -- Return values - - - - - - - - - - -

Type

-

Description

-

string

-

System locale ID.

-
- -- Example - - ``` - I18n.getSystemLocale(); - ``` - - -## i18n.getCalendar8+ - -getCalendar\(locale: string, type? : string\): Calendar - -Obtains a **Calendar** object. - -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

locale

-

string

-

Yes

-

Valid locale value, for example, zh-Hans-CN.

-

type

-

string

-

No

-

Valid calendar type. Currently, the valid types are as follows: buddhist, chinese, coptic, ethiopic, hebrew, gregory, indian, islamic_civil, islamic_tbla, islamic_umalqura, japanese, and persian. If this parameter is left unspecified, the default calendar type of the specified locale is used.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

Calendar

-

Calendar object.

-
- -- Example - - ``` - I18n.getCalendar("zh-Hans", "gregory"); - ``` - - -## Calendar8+ - -### setTime8+ - -setTime\(date: Date\): void - -Sets the date for this **Calendar** object. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

date

-

Date

-

Yes

-

Date to be set for the Calendar object.

-
- - -- Example - - ``` - var calendar = I18n.getCalendar("en-US", "gregory"); - var date = new Date(2021, 10, 7, 8, 0, 0, 0); - calendar.setTime(date); - ``` - - -### setTime8+ - -setTime\(time: number\): void - -Sets the date and time for this **Calendar** object. The value is represented by the number of milliseconds that have elapsed since the Unix epoch \(00:00:00 UTC on January 1, 1970\). - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

time

-

number

-

Yes

-

Number of milliseconds that have elapsed since the Unix epoch.

-
- - -- Example - - ``` - var calendar = I18n.getCalendar("en-US", "gregory"); - calendar.setTime(10540800000); - ``` - - -### set8+ - -set\(year: number, month: number, date:number, hour?: number, minute?: number, second?: number\): void - -Sets the year, month, day, hour, minute, and second for this **Calendar** object. - -- Parameters - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

year

-

number

-

Yes

-

Year to set.

-

month

-

number

-

Yes

-

Month to set.

-

date

-

number

-

Yes

-

Day to set.

-

hour

-

number

-

No

-

Hour to set.

-

minute

-

number

-

No

-

Minute to set.

-

second

-

number

-

No

-

Second to set.

-
- -- Example - - ``` - var calendar = I18n.getCalendar("zh-Hans"); - calendar.setTime(2021, 10, 1, 8, 0, 0); // set time to 2021.10.1 08:00:00 - ``` - - -### setTimeZone8+ - -setTimeZone\(timezone: string\): void - -Sets the time zone of this **Calendar** object. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

timezone

-

string

-

Yes

-

Time zone, for example, Asia/Shanghai.

-
- -- Example - - ``` - var calendar = I18n.getCalendar("zh-Hans"); - calendar.setTimeZone("Asia/Shanghai"); - ``` - - -### getTimeZone8+ - -getTimeZone\(\): string - -Obtains the time zone of this **Calendar** object. - -- Return values - - - - - - - - - - -

Type

-

Description

-

string

-

Time zone of the Calendar object.

-
- -- Example - - ``` - var calendar = I18n.getCalendar("zh-Hans"); - calendar.setTimeZone("Asia/Shanghai"); - calendar.getTimeZone(); // Asia/Shanghai" - ``` - - -### getFirstDayOfWeek8+ - -getFirstDayOfWeek\(\): number - -Obtains the start day of a week for this **Calendar** object. - -- Return values - - - - - - - - - - -

Type

-

Description

-

number

-

Start day of a week. The value 1 indicates Sunday, and value 7 indicates Saturday.

-
+**System capability**: SystemCapability.Global.I18n +- Return value + | Type| Description| + | -------- | -------- | + | string | System locale ID.| -- Example - - ``` - var calendar = I18n.getCalendar("en-US", "gregory"); - calendar.getFirstDayOfWeek(); - ``` - - -### setFirstDayOfWeek8+ - -setFirstDayOfWeek\(value: number\): void - -Sets the start day of a week for this **Calendar** object. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

value

-

number

-

No

-

Start day of a week. The value 1 indicates Sunday, and value 7 indicates Saturday.

-
+- Example + ``` + i18n.getSystemLocale(); + ``` -- Example - ``` - var calendar = I18n.getCalendar("zh-Hans"); - calendar.setFirstDayOfWeek(0); - ``` +## i18n.getCalendar8+ +getCalendar(locale: string, type? : string): Calendar -### getMinimalDaysInFirstWeek8+ +Obtains a **Calendar** object. -getMinimalDaysInFirstWeek\(\): number +**System capability**: SystemCapability.Global.I18n -Obtains the minimum number of days in the first week of a year. +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | locale | string | Yes| Valid locale value, for example, **zh-Hans-CN**.| + | type | string | No| Valid calendar type. Currently, the valid types are as follows: buddhist, chinese, coptic, ethiopic, hebrew, gregory, indian, islamic\_civil, islamic\_tbla, islamic\_umalqura, japanese, and persian. If this parameter is left unspecified, the default calendar type of the specified locale is used.| + +- Return value + | Type| Description| + | -------- | -------- | + | [Calendar](#calendar8) | **Calendar** object.| + +- Example + ``` + i18n.getCalendar("zh-Hans", "gregory"); + ``` + + +## Calendar8+ + + +### setTime8+ + +setTime(date: Date): void + +Sets the date for this **Calendar** object. + +**System capability**: SystemCapability.Global.I18n + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | date | Date | Yes| Date to be set for the **Calendar** object.| + +- Example + ``` + var calendar = I18n.getCalendar("en-US", "gregory"); + var date = new Date(2021, 10, 7, 8, 0, 0, 0); + calendar.setTime(date); + ``` + + +### setTime8+ + +setTime(time: number): void + +Sets the date and time for this **Calendar** object. The value is represented by the number of milliseconds that have elapsed since the Unix epoch (00:00:00 UTC on January 1, 1970). + +**System capability**: SystemCapability.Global.I18n + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | time | number | Yes| Number of milliseconds that have elapsed since the Unix epoch.| + +- Example + ``` + var calendar = I18n.getCalendar("en-US", "gregory"); + calendar.setTime(10540800000); + ``` + + +### set8+ + +set(year: number, month: number, date:number, hour?: number, minute?: number, second?: number): void + +Sets the year, month, day, hour, minute, and second for this **Calendar** object. + +**System capability**: SystemCapability.Global.I18n + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | year | number | Yes| Year to set.| + | month | number | Yes| Month to set.| + | date | number | Yes| Day to set.| + | hour | number | No| Hour to set.| + | minute | number | No| Minute to set.| + | second | number | No| Second to set.| + +- Example + ``` + var calendar = i18n.getCalendar("zh-Hans"); + calendar.setTime(2021, 10, 1, 8, 0, 0); // set time to 2021.10.1 08:00:00 + ``` + + +### setTimeZone8+ + +setTimeZone(timezone: string): void + +Sets the time zone of this **Calendar** object. + +**System capability**: SystemCapability.Global.I18n + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | timezone | string | Yes| Time zone, for example, **Asia/Shanghai**.| + +- Example + ``` + var calendar = i18n.getCalendar("zh-Hans"); + calendar.setTimeZone("Asia/Shanghai"); + ``` + + +### getTimeZone8+ + +getTimeZone(): string + +Obtains the time zone of this **Calendar** object. + +**System capability**: SystemCapability.Global.I18n + +- Return value + | Type| Description| + | -------- | -------- | + | string | Time zone of the **Calendar** object.| + +- Example + ``` + var calendar = i18n.getCalendar("zh-Hans"); + calendar.setTimeZone("Asia/Shanghai"); + calendar.getTimeZone(); // Asia/Shanghai" + ``` + + +### getFirstDayOfWeek8+ + +getFirstDayOfWeek(): number + +Obtains the start day of a week for this **Calendar** object. + +**System capability**: SystemCapability.Global.I18n + +- Return value + | Type| Description| + | -------- | -------- | + | number | Start day of a week. The value **1** indicates Sunday, and value **7** indicates Saturday.| + +- Example + ``` + var calendar = I18n.getCalendar("en-US", "gregory"); + calendar.getFirstDayOfWeek(); + ``` + + +### setFirstDayOfWeek8+ + +setFirstDayOfWeek(value: number): void + +Sets the start day of a week for this **Calendar** object. + +**System capability**: SystemCapability.Global.I18n + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | value | number | No| Start day of a week. The value **1** indicates Sunday, and value **7** indicates Saturday.| -- Return values +- Example + ``` + var calendar = i18n.getCalendar("zh-Hans"); + calendar.setFirstDayOfWeek(0); + ``` - - - - - - - - - -

Type

-

Description

-

number

-

Minimum number of days in the first week of a year.

-
-- Example +### getMinimalDaysInFirstWeek8+ - ``` - var calendar = I18n.getCalendar("zh-Hans"); - calendar.getMinimalDaysInFirstWeek(); - ``` +getMinimalDaysInFirstWeek(): number + +Obtains the minimum number of days in the first week of a year. + +**System capability**: SystemCapability.Global.I18n + +- Return value + | Type| Description| + | -------- | -------- | + | number | Minimum number of days in the first week of a year.| + +- Example + ``` + var calendar = i18n.getCalendar("zh-Hans"); + calendar.getMinimalDaysInFirstWeek(); + ``` -### setMinimalDaysInFirstWeek8+ +### setMinimalDaysInFirstWeek8+ -setMinimalDaysInFirstWeek\(value: number\): void +setMinimalDaysInFirstWeek(value: number): void Sets the minimum number of days in the first week of a year. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

value

-

number

-

No

-

Minimum number of days in the first week of a year.

-
- -- Example - - ``` - var calendar = i18n.getCalendar("zh-Hans"); - calendar.setMinimalDaysInFirstWeek(3); - ``` - - -### get8+ - -get\(field: string\): number - -Obtains the value of the specified field in the **Calendar** object. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

field

-

string

-

Yes

-

Value of the specified field in the Calendar object. Currently, the valid fields are as follows: 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, and is_leap_month.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

number

-

Value of the specified field. For example, if the year in the internal date of this Calendar object is 1990, the get("year") function will return 1990.

-
- -- Example - - ``` - var calendar = I18n.getCalendar("zh-Hans"); - calendar.setTime(2021, 10, 1, 8, 0, 0); // set time to 2021.10.1 08:00:00 - calendar.get("hour_of_day"); // 8 - ``` - - -### getDisplayName8+ - -getDisplayName\(locale: string\): string - -Obtains the name of the **Calendar** object displayed for the specified locale. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

locale

-

string

-

Yes

-

Locale for which the name of the Calendar object is displayed. For example, if locale is en-US, the name of the Buddhist calendar will be Buddhist Calendar.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

string

-

Name of the Calendar object displayed for the specified locale.

-
- -- Example - - ``` - var calendar = I18n.getCalendar("en-US", "buddhist"); - calendar.getDisplayName("zh"); // Obtain the name of the Buddhist calendar in zh. - ``` - - -### isWeekend8+ - -isWeekend\(date?: Date\): boolean - -Checks whether the specified date in this **Calendar** object is a weekend. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

date

-

Date

-

No

-

Specified date in this Calendar object. If this parameter is left unspecified, the system checks whether the current date in the Calendar object is a weekend.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

The value true indicates that the date is a weekend, and value false indicates a weekday.

-
- -- Example - - ``` - var calendar = I18n.getCalendar("zh-Hans"); - calendar.setTime(2021, 11, 11, 8, 0, 0); // Set the time to 2021.11.11 08:00:00. - calendar.isWeekend(); // false - var date = new Date(2011, 11, 6, 9, 0, 0); - calendar.isWeekend(date); // true - ``` - - -## PhoneNumberFormat8+ - -### constructor8+ - -constructor\(country: string, options?: PhoneNumberFormatOptions\) - -Creates a **PhoneNumberFormat** object. +**System capability**: SystemCapability.Global.I18n + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | value | number | No| Minimum number of days in the first week of a year.| + +- Example + ``` + var calendar = i18n.getCalendar("zh-Hans"); + calendar.setMinimalDaysInFirstWeek(3); + ``` + + +### get8+ + +get(field: string): number + +Obtains the value of the specified field in the **Calendar** object. + +**System capability**: SystemCapability.Global.I18n + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | field | string | Yes| Value of the specified field in the **Calendar** object. Currently, a valid field can be any of the following: era, year, month, week\_of\_year, week\_of\_month, date, day\_of\_year, day\_of\_week, day\_of\_week\_in\_month, hour, hour\_of\_day, minute, second, millisecond, zone\_offset, dst\_offset, year\_woy, dow\_local, extended\_year, julian\_day, milliseconds\_in\_day, is\_leap\_month.| + +- Return value + | Type| Description| + | -------- | -------- | + | number | Value of the specified field. For example, if the year in the internal date of this **Calendar** object is **1990**, the **get("year")** function will return **1990**.| + +- Example + ``` + var calendar = i18n.getCalendar("zh-Hans"); + calendar.setTime(2021, 10, 1, 8, 0, 0); // set time to 2021.10.1 08:00:00 + calendar.get("hour_of_day"); // 8 + ``` + + +### getDisplayName8+ + +getDisplayName(locale: string): string + +Obtains the name of the **Calendar** object displayed for the specified locale. + +**System capability**: SystemCapability.Global.I18n + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | locale | string | Yes| Locale for which the name of the **Calendar** object is displayed. For example, if **locale** is **en-US**, the name of the Buddhist calendar will be **Buddhist Calendar**.| + +- Return value + | Type| Description| + | -------- | -------- | + | string | Name of the **Calendar** object displayed for the specified locale.| + +- Example + ``` + var calendar = i18n.getCalendar("en-US", "buddhist"); + calendar.getDisplayName("zh"); // Obtain the name of the Buddhist calendar in zh. + ``` + + +### isWeekend8+ + +isWeekend(date?: Date): boolean + +Checks whether the specified date in this **Calendar** object is a weekend. + +**System capability**: SystemCapability.Global.I18n + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | date | Date | No| Specified date in this **Calendar** object. If this parameter is left unspecified, the system checks whether the current date in the **Calendar** object is a weekend.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | The value **true** indicates that the date is a weekend, and value **false** indicates a weekday.| + +- Example + ``` + var calendar = i18n.getCalendar("zh-Hans"); + calendar.setTime(2021, 11, 11, 8, 0, 0); // set time to 2021.11.11 08:00:00 + calendar.isWeekend(); // false + var date = new Date(2011, 11, 6, 9, 0, 0); + calendar.isWeekend(date); // true + ``` + + +## PhoneNumberFormat8+ + + +### constructor8+ + +constructor(country: string, options?: PhoneNumberFormatOptions) + +Creates a **PhoneNumberFormat** object. + +**System capability**: SystemCapability.Global.I18n Parameters +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| country | string | Yes| Country or region to which the phone number to be formatted belongs.| +| options | [PhoneNumberFormatOptions](#phonenumberformatoptions8) | No| Options of the **PhoneNumberFormat** object.| - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

country

-

string

-

Yes

-

Country or region to which the phone number to be formatted belongs.

-

options

-

PhoneNumberFormatOptions

-

No

-

Options of the PhoneNumberFormat object.

-
- -- Example - - ``` - var phoneNumberFormat= new I18n.PhoneNumberFormat("CN", {"type": "E164"}); - ``` - - -### isValidNumber8+ - -isValidNumber\(number: string\): boolean +- Example + ``` + var phoneNumberFormat= new i18n.PhoneNumberFormat("CN", {"type": "E164"}); + ``` + + +### isValidNumber8+ + +isValidNumber(number: string): boolean Checks whether the format of the specified phone number is valid. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

number

-

string

-

Yes

-

Phone number to be checked.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

The value true indicates the phone number format is valid, and value false indicates the opposite.

-
- - -- Example - - ``` - var phonenumberfmt = new I18n.PhoneNumberFormat("CN"); - phonenumberfmt.isValidNumber("15812312312"); - ``` - - -### format8+ - -format\(number: string\): string +**System capability**: SystemCapability.Global.I18n + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | number | string | Yes| Phone number to be checked.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | The value **true** indicates the phone number format is valid, and value **false** indicates the opposite.| + +- Example + ``` + var phonenumberfmt = new i18n.PhoneNumberFormat("CN"); + phonenumberfmt.isValidNumber("15812312312"); + ``` + + +### format8+ + +format(number: string): string Formats a phone number. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

number

-

string

-

Yes

-

Phone number to be formatted.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

string

-

Formatted phone number.

-
- - -- Example - - ``` - var phonenumberfmt = new I18n.PhoneNumberFormat("CN"); - phonenumberfmt.format("15812312312"); - ``` - - -## PhoneNumberFormatOptions8+ - -Defines the options for this **PhoneNumberFormat** object. - - - - - - - - - - - - - - - - -

Name

-

Type

-

Readable

-

Writable

-

Description

-

type

-

string

-

Yes

-

Yes

-

Format type of a phone number. The available options are as follows: E164, INTERNATIONAL, NATIONAL, and RFC3966.

-
- -## UnitInfo8+ +**System capability**: SystemCapability.Global.I18n + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | number | string | Yes| Phone number to be formatted.| + +- Return value + | Type| Description| + | -------- | -------- | + | string | Formatted phone number.| + +- Example + ``` + var phonenumberfmt = new i18n.PhoneNumberFormat("CN"); + phonenumberfmt.format("15812312312"); + ``` + + +## PhoneNumberFormatOptions8+ + +Defines the options for this PhoneNumberFormat object. + + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| type | string | Yes| Yes| Format type of a phone number. The value can be **E164**, **INTERNATIONAL**, **NATIONAL**, or **RFC3966**.
**System capability**: SystemCapability.Global.I18n| + + +## UnitInfo8+ Defines the measurement unit information. - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Readable

-

Writable

-

Description

-

unit

-

string

-

Yes

-

Yes

-

Name of the measurement unit, for example, meter, inch, or cup.

-

measureSystem

-

string

-

Yes

-

Yes

-

Measurement system. The value can be SI, US, or UK.

-
- -## Util8+ - -### unitConvert8+ - -unitConvert\(fromUnit: UnitInfo, toUnit: UnitInfo, value: number, locale: string, style?: string\): string + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| unit | string | Yes| Yes| Name of the measurement unit, for example, **meter**, **inch**, or **cup**.| +| measureSystem | string | Yes| Yes| Measurement system. The value can be **SI**, **US**, or **UK**.
**System capability**: SystemCapability.Global.I18n| + + +## Util8+ + + +### unitConvert8+ + +unitConvert(fromUnit: UnitInfo, toUnit: UnitInfo, value: number, locale: string, style?: string): string Converts one measurement unit into another and formats the unit based on the specified locale and style. -- Parameters - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

fromUnit

-

UnitInfo

-

Yes

-

Measurement unit to be converted.

-

toUnit

-

UnitInfo

-

Yes

-

Measurement unit to be converted to.

-

value

-

number

-

Yes

-

Value of the measurement unit to be converted.

-

locale

-

string

-

Yes

-

Locale used for formatting, for example, zh-Hans-CN.

-

style

-

string

-

No

-

Style used for formatting. The value can be long, short, or medium.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

string

-

Character string obtained after formatting based on the measurement unit specified by toUnit.

-
- - -- Example - - ``` - I18n.Util.unitConvert({unit: "cup", measureSystem: "US"}, {unit: "liter", measureSystem: "SI"}, 1000, "en-US", "long"); - ``` - - -## i18n.getInstance8+ - -getInstance\(locale?: string\): IndexUtil - -Creates an **IndexUtil** object. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

locale

-

string

-

No

-

A string containing locale information, including the language, optional script, and region.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

IndexUtil

-

IndexUtil object mapping to the specified locale.

-
- - -- Example - - ``` - var indexUtil= I18n.getInstance("zh-CN"); - ``` - - -## IndexUtil8+ - -### getIndexList8+ - -getIndexList\(\): Array - -Obtains the index list for this **locale** object. - -- Return values - - - - - - - - - - -

Type

-

Description

-

Array<string>

-

Index list for this locale.

-
- - -- Example - - ``` - var indexUtil = i18n.getInstance("zh-CN"); - var indexList = indexUtil.getIndexList(); - ``` - - -### addLocale8+ - -addLocale\(locale: string\) - -Adds the index of the new **locale** object to the index list. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

locale

-

string

-

Yes

-

A string containing locale information, including the language, optional script, and region.

-
- - -- Example - - ``` - var indexUtil = i18n.getInstance("zh-CN"); - indexUtil.addLocale("en-US"); - ``` - - -### getIndex8+ - -getIndex\(text: string\): string - -Obtains the index of a **text** object. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

text

-

string

-

Yes

-

text object whose index is to be obtained.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

string

-

Index of the text object.

-
- - -- Example - - ``` - var indexUtil= i18n.getInstance("zh-CN"); - indexUtil.getIndex("hi"); // Return h. - ``` - - -## Character8+ - -### isDigit8+ - -isDigit\(char: string\): boolean - -Checks whether the input character is a digit. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

char

-

string

-

Yes

-

Input character.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

The value true indicates that the input character is a digit, and value false indicates the opposite.

-
- - -- Example - - ``` - var isdigit = Character.isDigit("1"); // Return true. - ``` - - -### isSpaceChar8+ - -isSpaceChar\(char: string\): boolean +**System capability**: SystemCapability.Global.I18n + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | fromUnit | [UnitInfo](#unitinfo8) | Yes| Measurement unit to be converted.| + | toUnit | [UnitInfo](#unitinfo8) | Yes| Measurement unit to be converted to.| + | value | number | Yes| Value of the measurement unit to be converted.| + | locale | string | Yes| Locale used for formatting, for example, **zh-Hans-CN**.| + | style | string | No| Style used for formatting. The value can be **long**, **short**, or **medium**.| + +- Return value + | Type| Description| + | -------- | -------- | + | string | Character string obtained after formatting based on the measurement unit specified by **toUnit**.| + +- Example + ``` + I18n.Util.unitConvert({unit: "cup", measureSystem: "US"}, {unit: "liter", measureSystem: "SI"}, 1000, "en-US", "long"); + ``` + + +## IndexUtil8+ + + +### getInstance8+ + +getInstance(): IndexUtil + +Creates an **IndexUtil** object. + +**System capability**: SystemCapability.Global.I18n + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | locale | string | No| A string containing locale information, including the language, optional script, and region.| + +- Return value + | Type| Description| + | -------- | -------- | + | [IndexUtil](#indexutil8) | **IndexUtil** object mapping to the specified locale.| + +- Example + ``` + var indexUtil= i18n.IndexUtil.getInstance("zh-CN"); + ``` + + +### getIndexList8+ + +getIndexList(): Array<string> + +Obtains the index list for this **locale** object. + +**System capability**: SystemCapability.Global.I18n + +- Return value + | Type| Description| + | -------- | -------- | + | Array<string> | Index list for this **locale** object.| + +- Example + ``` + var indexUtil = i18n.getInstance("zh-CN"); + var indexList = indexUtil.getIndexList(); + ``` + + +### addLocale8+ + +addLocale(locale: string) + +Adds the index of the new **locale** object to the index list. + +**System capability**: SystemCapability.Global.I18n + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | locale | string | Yes| A string containing locale information, including the language, optional script, and region.| + +- Example + ``` + var indexUtil = i18n.getInstance("zh-CN"); + indexUtil.addLocale("en-US"); + ``` + + +### getIndex8+ + +getIndex(text: string): string + +Obtains the index of a text object. + +**System capability**: SystemCapability.Global.I18n + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | text | string | Yes| **text** object whose index is to be obtained.| + +- Return value + | Type| Description| + | -------- | -------- | + | string | Index of the **text** object.| + +- Example + ``` + var indexUtil= i18n.getInstance("zh-CN"); + indexUtil.getIndex("hi"); // Return h. + ``` + + +## Character8+ + + +### isDigit8+ + +isDigit(char: string): boolean + +Checks whether the input character string is composed of digits. + +**System capability**: SystemCapability.Global.I18n + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | char | string | Yes| Input character.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | The value **true** indicates that the input character is a digit, and value **false** indicates the opposite.| + +- Example + ``` + var isdigit = Character.isDigit("1"); // Return true. + ``` + + +### isSpaceChar8+ + +isSpaceChar(char: string): boolean Checks whether the input character is a space. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

char

-

string

-

Yes

-

Input character.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

The value true indicates that the input character is a space, and value false indicates the opposite.

-
- - -- Example - - ``` - var isspacechar = Character.isSpaceChar("a"); // Return false. - ``` - - -### isWhitespace8+ - -isWhitespace\(char: string\): boolean +**System capability**: SystemCapability.Global.I18n + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | char | string | Yes| Input character.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | The value **true** indicates that the input character is a space, and value **false** indicates the opposite.| + +- Example + ``` + var isspacechar = Character.isSpaceChar("a"); // Return false. + ``` + + +### isWhitespace8+ + +isWhitespace(char: string): boolean Checks whether the input character is a white space. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

char

-

string

-

Yes

-

Input character.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

The value true indicates that the input character is a white space, and value false indicates the opposite.

-
- - -- Example - - ``` - var iswhitespace = Character.isWhitespace("a"); // Return false. - ``` - - -### isRTL8+ - -isRTL\(char: string\): boolean - -Checks whether the input character is of the right to left \(RTL\) language. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

char

-

string

-

Yes

-

Input character.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

The value true indicates that the input character is of the RTL language, and value false indicates the opposite.

-
- - -- Example - - ``` - var isrtl = Character.isRTL("a"); // Return false. - ``` - - -### isIdeograph8+ - -isIdeograph\(char: string\): boolean +**System capability**: SystemCapability.Global.I18n + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | char | string | Yes| Input character.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | The value **true** indicates that the input character is a white space, and value **false** indicates the opposite.| + +- Example + ``` + var iswhitespace = Character.isWhitespace("a"); // Return false. + ``` + + +### isRTL8+ + +isRTL(char: string): boolean + +Checks whether the input character is of the right to left (RTL) language. + +**System capability**: SystemCapability.Global.I18n + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | char | string | Yes| Input character.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | The value **true** indicates that the input character is of the RTL language, and value **false** indicates the opposite.| + +- Example + ``` + var isrtl = Character.isRTL("a"); // Return false. + ``` + + +### isIdeograph8+ + +isIdeograph(char: string): boolean Checks whether the input character is an ideographic character. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

char

-

string

-

Yes

-

Input character.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

The value true indicates that the input character is an ideographic character, and value false indicates the opposite.

-
- - -- Example - - ``` - var isideograph = Character.isIdeograph("a"); // Return false. - ``` - - -### isLetter8+ - -isLetter\(char: string\): boolean +**System capability**: SystemCapability.Global.I18n + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | char | string | Yes| Input character.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | The value **true** indicates that the input character is an ideographic character, and value **false** indicates the opposite.| + +- Example + ``` + var isideograph = Character.isIdeograph("a"); // Return false. + ``` + + +### isLetter8+ + +isLetter(char: string): boolean Checks whether the input character is a letter. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

char

-

string

-

Yes

-

Input character.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

The value true indicates that the input character is a letter, and value false indicates the opposite.

-
- - -- Example - - ``` - var isletter = Character.isLetter("a"); // Return true. - ``` - - -### isLowerCase8+ - -isLowerCase\(char: string\): boolean +**System capability**: SystemCapability.Global.I18n + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | char | string | Yes| Input character.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | The value **true** indicates that the input character is a letter, and value **false** indicates the opposite.| + +- Example + ``` + var isletter = Character.isLetter("a"); // Return true. + ``` + + +### isLowerCase8+ + +isLowerCase(char: string): boolean Checks whether the input character is a lowercase letter. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

char

-

string

-

Yes

-

Input character.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

The value true indicates that the input character is a lowercase letter, and value false indicates the opposite.

-
- - -- Example - - ``` - var islowercase = Character.isLowerCase("a"); // Return true. - ``` - - -### isUpperCase8+ - -isUpperCase\(char: string\): boolean +**System capability**: SystemCapability.Global.I18n + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | char | string | Yes| Input character.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | The value **true** indicates that the input character is a lowercase letter, and value **false** indicates the opposite.| + +- Example + ``` + var islowercase = Character.isLowerCase("a"); // Return true. + ``` + + +### isUpperCase8+ + +isUpperCase(char: string): boolean Checks whether the input character is an uppercase letter. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

char

-

string

-

Yes

-

Input character.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

The value true indicates that the input character is an uppercase letter, and value false indicates the opposite.

-
- - -- Example - - ``` - var isuppercase = Character.isUpperCase("a"); // Return false. - ``` - - -### getType8+ - -getType\(char: string\): string +**System capability**: SystemCapability.Global.I18n + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | char | string | Yes| Input character.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | The value true indicates that the input character is an uppercase letter, and value false indicates the opposite.| + +- Example + ``` + var isuppercase = Character.isUpperCase("a"); // Return false. + ``` + + +### getType8+ + +getType(char: string): string Obtains the type of the input character string. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

char

-

string

-

Yes

-

Input character.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

string

-

Type of the input character.

-
- - -- Example - - ``` - var type = Character.getType("a"); - ``` - - -## i18n.getLineInstance8+ - -getLineInstance\(locale: string\): BreakIterator - -Obtains a [BreakIterator](#section1312302611613) object for text segmentation. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

locale

-

string

-

Yes

-

Valid locale value, for example, zh-Hans-CN. The BreakIterator object segments text according to the rules of the specified locale.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

BreakIterator

-

Break iterator used for text segmentation.

-
- -- Example - - ``` - I18n.getLineInstance("en"); - ``` - - -## BreakIterator8+ - -### setLineBreakText8+ - -setLineBreakText\(text: string\): void - -Sets the text to be processed by the [BreakIterator](#section1312302611613) object. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

text

-

string

-

Yes

-

Text to be processed by the BreakIterator object.

-
- +**System capability**: SystemCapability.Global.I18n -- Example +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | char | string | Yes| Input character.| - ``` - var iterator = I18n.getLineInstance("en"); - var iterator.setLineBreakText("Apple is my favorite fruit."); - ``` - - -### getLineBreakText8+ +- Return value + | Type| Description| + | -------- | -------- | + | string | Type of the input character.| -getLineBreakText\(\): string - -Obtains the text being processed by the [BreakIterator](#section1312302611613) object. - -- Return values - - - - - - - - - - -

Type

-

Description

-

string

-

Text being processed by the BreakIterator object.

-
- - -- Example +- Example + ``` + var type = Character.getType("a"); + ``` - ``` - var iterator = I18n.getLineInstance("en"); - iterator.setLineBreakText("Apple is my favorite fruit."); - iterator.getLineBreakText(); // Apple is my favorite fruit. - ``` +## i18n.getLineInstance8+ -### current8+ +getLineInstance(locale: string): BreakIterator -current\(\): number +Obtains a [BreakIterator](#breakiterator8) object for text segmentation. -Obtains the position of the [BreakIterator](#section1312302611613) object in the text being processed. +**System capability**: SystemCapability.Global.I18n -- Return values +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | locale | string | Yes| Valid locale value, for example, **zh-Hans-CN**. The [BreakIterator](#breakiterator8) object segments text according to the rules of the specified locale.| - - - - - - - - - -

Type

-

Description

-

number

-

Position of the BreakIterator object in the text being processed.

-
+- Return value + | Type| Description| + | -------- | -------- | + | [BreakIterator](#breakiterator8) | [BreakIterator](#breakiterator8) object used for text segmentation.| +- Example + ``` + i18n.getLineInstance("en"); + ``` -- Example - - ``` - var iterator = I18n.getLineInstance("en"); - iterator.setLineBreakText("Apple is my favorite fruit."); - breakIter.current(); // 0 - ``` +## BreakIterator8+ -### first8+ - -first\(\): number - -Puts the [BreakIterator](#section1312302611613) object to the first text boundary, which is always at the beginning of the processed text. - -- Return values - - - - - - - - - - -

Type

-

Description

-

number

-

Offset to the first text boundary of the processed text.

-
+### setLineBreakText8+ -- Example +setLineBreakText(text: string): void - ``` - iterator = I18n.getLineInstance("en"); - iterator.setLineBreakText("Apple is my favorite fruit."); - breakIter.first(); // 0 - ``` +Sets the text to be processed by the [BreakIterator](#breakiterator8) object. +**System capability**: SystemCapability.Global.I18n -### last8+ +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | text | string | Yes| Text to be processed by the **BreakIterator** object.| -last\(\): number +- Example + ``` + iterator = I18n.getLineInstance("en"); + iterator.setLineBreakText("Apple is my favorite fruit."); + ``` -Puts the [BreakIterator](#section1312302611613) object to the last text boundary, which is always the next position after the end of the processed text. -- Return values - - - - - - - - - - -

Type

-

Description

-

number

-

Offset of the last text boundary of the processed text.

-
+### getLineBreakText8+ +getLineBreakText(): string -- Example - - ``` - var iterator = I18n.getLineInstance("en"); - iterator.setLineBreakText("Apple is my favorite fruit."); - iterator.last(); // 27 - ``` +Obtains the text being processed by the [BreakIterator](#breakiterator8) object. +**System capability**: SystemCapability.Global.I18n -### next8+ +- Return value + | Type| Description| + | -------- | -------- | + | string | Text being processed by the **BreakIterator** object.| -next\(index?: number\): number +- Example + ``` + iterator = I18n.getLineInstance("en"); + iterator.setLineBreakText("Apple is my favorite fruit."); + iterator.getLineBreakText(); // Apple is my favorite fruit. + ``` -Moves the [BreakIterator](#section1312302611613) object backward by the specified number of text boundaries if the specified index is a positive number. If the index is a negative number, the [BreakIterator](#section1312302611613) object will be moved forward by the corresponding number of text boundaries. If no index is specified, the index will be treated as **1**. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

index

-

number

-

No

-

Number of text boundaries by which the BreakIterator object is moved. A positive value indicates that the text boundary is moved backward, and a negative value indicates the opposite. If no index is specified, the index will be treated as 1.

-
- - -- Return values - - - - - - - - - - -

Type

-

Description

-

number

-

Position of the BreakIterator object in the text after it is moved by the specified number of text boundaries. The value -1 is returned if the position of the BreakIterator object is outside of the processed text after it is moved by the specified number of text boundaries.

-
- - -- Example - - ``` - var iterator = I18n.getLineInstance("en"); - iterator.setLineBreakText("Apple is my favorite fruit."); - iterator.first(); // 0 - iterator.next(); // 6 - iterator.next(10); // -1 - ``` - - -### previous8+ - -previous\(\): number - -Moves the [BreakIterator](#section1312302611613) object to the previous text boundary. - -- Return values - - - - - - - - - - -

Type

-

Description

-

number

-

Position of the BreakIterator object in the text after it is moved to the previous text boundary. The value -1 is returned if the position of the BreakIterator object is outside of the processed text after it is moved by the specified number of text boundaries.

-
- - -- Example - - ``` - var iterator = I18n.getLineInstance("en"); - iterator.setLineBreakText("Apple is my favorite fruit."); - iterator.first(); // 0 - iterator.next(3); // 12 - iterator.previous(); // 9 - ``` - - -### following8+ - -following\(offset: number\): number - -Moves the [BreakIterator](#section1312302611613) object to the text boundary after the position specified by the offset. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

offset

-

number

-

Yes

-

Offset to the position before the text boundary to which the BreakIterator object is moved.

-
- - -- Return values - - - - - - - - - - -

Type

-

Description

-

number

-

The value -1 is returned if the text boundary to which the BreakIterator object is moved is outside of the processed text.

-
- - -- Example - - ``` - var iterator = I18n.getLineInstance("en"); - iterator.setLineBreakText("Apple is my favorite fruit."); - iterator.following(0); // 6 - iterator.following(100); // -1 - iterator.current(); // 27 - ``` - - -### isBoundary8+ - -isBoundary\(offset: number\): boolean - -Checks whether the position specified by the offset is a text boundary. If **true** is returned, the [BreakIterator](#section1312302611613) object is moved to the position specified by the offset. If **false** is returned, the [BreakIterator](#section1312302611613) object is moved to the text boundary after the position specified by the offset, which is equivalent to calling [following\(offset\)](#section1743155314301). - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

offset

-

number

-

Yes

-

Position to check.

-
- - -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

The value true indicates that the position specified by the offset is a text boundary, and value false indicates the opposite.

-
- - -- Example - - ``` - var iterator = I18n.getLineInstance("en"); - iterator.setLineBreakText("Apple is my favorite fruit."); - iterator.isBoundary(0); // true; - iterator.isBoundary(5); // false; - ``` - - -## i18n.is24HourClock8+ - -is24HourClock\(\): boolean +### current8+ -Checks whether the 24-hour clock is used. +current(): number + +Obtains the position of the [BreakIterator](#breakiterator8) object in the text being processed. + +**System capability**: SystemCapability.Global.I18n + +- Return value + | Type| Description| + | -------- | -------- | + | number | Position of the **BreakIterator** object in the text being processed.| + +- Example + ``` + iterator = I18n.getLineInstance("en"); + iterator.setLineBreakText("Apple is my favorite fruit."); + breakIter.current(); // 0 + ``` + + +### first8+ + +first(): number + +Puts the [BreakIterator](#breakiterator8) object to the first text boundary, which is always at the beginning of the processed text. + +**System capability**: SystemCapability.Global.I18n + +- Return value + | Type| Description| + | -------- | -------- | + | number | Offset to the first text boundary of the processed text.| + +- Example + ``` + iterator = I18n.getLineInstance("en"); + iterator.setLineBreakText("Apple is my favorite fruit."); + breakIter.first(); // 0 + ``` + + +### last8+ + +last(): number + +Puts the [BreakIterator](#breakiterator8) object to the last text boundary, which is always the next position after the end of the processed text. + +**System capability**: SystemCapability.Global.I18n + +- Return value + | Type| Description| + | -------- | -------- | + | number | Offset of the last text boundary of the processed text.| + +- Example + ``` + iterator = I18n.getLineInstance("en"); + iterator.setLineBreakText("Apple is my favorite fruit."); + iterator.last(); // 27 + ``` + + +### next8+ + +next(index?: number): number + +Moves the [BreakIterator](#breakiterator8) object backward by the specified number of text boundaries if the specified index is a positive number. If the index is a negative number, the [BreakIterator](#breakiterator8) object will be moved forward by the corresponding number of text boundaries. If no index is specified, the index will be treated as **1**. + +**System capability**: SystemCapability.Global.I18n + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | index | number | No| Number of text boundaries by which the [BreakIterator](#breakiterator8) object is moved. A positive value indicates that the text boundary is moved backward, and a negative value indicates the opposite. If no index is specified, the index will be treated as **1**.| + +- Return value + | Type| Description| + | -------- | -------- | + | number | Position of the [BreakIterator](#breakiterator8) object in the text after it is moved by the specified number of text boundaries. The value **-1** is returned if the position of the [BreakIterator](#breakiterator8) object is outside of the processed text after it is moved by the specified number of text boundaries.| + +- Example + ``` + iterator = I18n.getLineInstance("en"); + iterator.setLineBreakText("Apple is my favorite fruit."); + iterator.first(); // 0 + iterator.next(); // 6 + iterator.next(10); // -1 + ``` + + +### previous8+ + +previous(): number + +Moves the [BreakIterator](#breakiterator8) object to the previous text boundary. + +**System capability**: SystemCapability.Global.I18n + +- Return value + | Type| Description| + | -------- | -------- | + | number | Position of the [BreakIterator](#breakiterator8) object in the text after it is moved to the previous text boundary. The value **-1** is returned if the position of the [BreakIterator](#breakiterator8) object is outside of the processed text after it is moved by the specified number of text boundaries.| -- Return values +- Example + ``` + iterator = I18n.getLineInstance("en"); + iterator.setLineBreakText("Apple is my favorite fruit."); + iterator.first(); // 0 + iterator.next(3); // 12 + iterator.previous(); // 9 + ``` - - - - - - - - - -

Type

-

Description

-

boolean

-

The value true indicates that the 24-hour clock is used, and value false indicates the opposite.

-
+### following8+ -- Example +following(offset: number): number - ``` - var is24HourClock = i18n.is24HourClock(); - ``` +Moves the [BreakIterator](#breakiterator8) object to the text boundary after the position specified by the offset. Position of the [BreakIterator](#breakiterator8) object after it is moved to the text boundary after the position specified by the offset. +**System capability**: SystemCapability.Global.I18n -## i18n.set24HourClock8+ +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | offset | number | Yes| Offset to the position before the text boundary to which the [BreakIterator](#breakiterator8) object is moved.| -set24HourClock\(option: boolean\): boolean +- Return value + | Type| Description| + | -------- | -------- | + | number | The value **-1** is returned if the text boundary to which the [BreakIterator](#breakiterator8) object is moved is outside of the processed text.| + +- Example + ``` + iterator = I18n.getLineInstance("en"); + iterator.setLineBreakText("Apple is my favorite fruit."); + iterator.following(0); // 6 + iterator.following(100); // -1 + iterator.current(); // 27 + ``` + + +### isBoundary8+ + +isBoundary(offset: number): boolean + +Checks whether the position specified by the offset is a text boundary. If **true** is returned, the [BreakIterator](#breakiterator8) object is moved to the position specified by the offset. If **false** is returned, the [BreakIterator](#breakiterator8) object is moved to the text boundary after the position specified by the offset, which is equivalent to calling [following](#following8)(offset). + +**System capability**: SystemCapability.Global.I18n + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | offset | number | Yes| Position to check.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | The value **true** indicates that the position specified by the offset is a text boundary, and value **false** indicates the opposite.| + +- Example + ``` + iterator = I18n.getLineInstance("en"); + iterator.setLineBreakText("Apple is my favorite fruit."); + iterator.isBoundary(0); // true; + iterator.isBoundary(5); // false; + ``` + + +## i18n.is24HourClock8+ + +is24HourClock(): boolean + +Checks whether the 24-hour clock is used. + +**System capability**: SystemCapability.Global.I18n + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | The value **true** indicates that the 24-hour clock is used, and value **false** indicates the opposite.| + +- Example + ``` + var is24HourClock = i18n.is24HourClock(); + ``` + + +## i18n.set24HourClock8+ + +set24HourClock(option: boolean): boolean Sets the 24-hour clock. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

option

-

boolean

-

Yes

-

Whether to enable the 24-hour clock. The value true means to enable the 24-hour clock, and value false means the opposite.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

The value true indicates that the 24-hour clock is enabled, and value false indicates the opposite.

-
- - -- Example - - ``` - // Set the system time to the 24-hour format. - var success = I18n.set24HourClock(true); - ``` - - -## i18n.addPreferredLanguage8+ - -addPreferredLanguage\(language: string, index?: number\): boolean +**System capability**: SystemCapability.Global.I18n + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | option | boolean | Yes| Whether to enable the 24-hour clock. The value **true** means to enable the 24-hour clock, and value **false** means the opposite.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | The value **true** indicates that the 24-hour clock is enabled, and value **false** indicates the opposite.| + +- Example + ``` + // Set the system time to the 24-hour clock. + var success = I18n.set24HourClock(true); + ``` + + +## i18n.addPreferredLanguage8+ + +addPreferredLanguage(language: string, index?: number): boolean Adds a preferred language to the specified position on the preferred language list. -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

language

-

string

-

Yes

-

Preferred language to add.

-

index

-

number

-

No

-

Position to which the preferred language is added.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

The value true indicates that the preferred language is added, and value false indicates the opposite.

-
- - -- Example - - ``` - // Add zh-CN to the preferred language list. - var language = 'zh-CN'; - var index = 0; - var success = i18n.addPreferredLanguage(langauge, index); - ``` - - -## i18n.removePreferredLanguage8+ - -removePreferredLanguage\(index: number\): boolean +**System capability**: SystemCapability.Global.I18n + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | language | string | Yes| Preferred language to add.| + | index | number | No| Position to which the preferred language is added.| + +- Return value + | Type| Description| + | -------- | -------- | + | boolean | The value **true** indicates that the preferred language is successfully added, and value **false** indicates the opposite.| + +- Example + ``` + // Add zh-CN to the preferred language list. + var language = 'zh-CN'; + var index = 0; + var success = i18n.addPreferredLanguage(language, index); + ``` + + +## i18n.removeDisplayLanguage8+ + +removeDisplayLanguage(index: number): boolean Deletes a preferred language from the specified position on the preferred language list. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

index

-

number

-

Yes

-

Position of the preferred language to delete.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

boolean

-

The value true indicates that the preferred language is deleted, and value false indicates the opposite.

-
- - -- Example - - ``` - // Delete the first preferred language from the preferred language list. - var index = 0; - var success = i18n.removePreferredLanguage(index); - ``` - - -## i18n.getPreferredLanguageList8+ - -getPreferredLanguageList\(\): Array +**System capability**: SystemCapability.Global.I18n -Obtains the preferred language list. +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | index | number | Yes| Position of the preferred language to delete.| -- Return values +- Return value + | Type| Description| + | -------- | -------- | + | boolean | The value **true** indicates that the preferred language is deleted, and value **false** indicates the opposite.| - - - - - - - - - -

Type

-

Description

-

Array<string>

-

Preferred language list.

-
+- Example + ``` + // Delete the first preferred language from the preferred language list. + var index = 0; + var success = i18n.removePreferredLanguage(index); + ``` -- Example +## i18n.getPreferredLanguageList8+ - ``` - var preferredLanguageList = i18n.getPreferredLanguageList(); - ``` +getPreferredLanguageList(): Array +Obtains the preferred language list. -## i18n.getFirstPreferredLanguage8+ +**System capability**: SystemCapability.Global.I18n -getFirstPreferredLanguage\(\): string +- Return value + | Type| Description| + | -------- | -------- | + | Array | Preferred language list.| -Obtains the preferred language that best matches the HAP resource. +- Example + ``` + var preferredLanguageList = i18n.getPreferredLanguageList(); + ``` -- Return values - - - - - - - - - -

Type

-

Description

-

string

-

Preferred language that best matches the HAP resource.

-
+## i18n.getFirstPreferredLanguage8+ +getFirstPreferredLanguage(): string + +Obtains the preferred language that best matches the HAP resource. -- Example +**System capability**: SystemCapability.Global.I18n - ``` - var firstPreferredLangauge = i18n.getFirstPreferredLangauge(); - ``` +- Return value + | Type| Description| + | -------- | -------- | + | string | Preferred language that best matches the HAP resource.| +- Example + ``` + var firstPreferredLanguage = i18n.getFirstPreferredLanguage(); + ``` diff --git a/en/application-dev/reference/apis/js-apis-intl.md b/en/application-dev/reference/apis/js-apis-intl.md index f18b8b8bf316bb4b680d03cef06dbcd19e14bbfe..719154b9fcaf6c484cdf5b7c195be310d1c96c0e 100644 --- a/en/application-dev/reference/apis/js-apis-intl.md +++ b/en/application-dev/reference/apis/js-apis-intl.md @@ -1,1996 +1,681 @@ -# Internationalization (intl) +# Internationalization – intl ->![](../../public_sys-resources/icon-note.gif) **NOTE:** ->- The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. ->- This module contains standard i18n APIs, which are defined in ECMA 402. +> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE** +> - The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. +> +> - This module contains standard i18n APIs, which are defined in ECMA 402. -## Modules to Import + +## Modules to Import ``` import Intl from '@ohos.intl'; ``` -## Required Permissions - -None - -## Locale - -### Attributes - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Parameter Type

-

Readable

-

Writable

-

Description

-

language

-

string

-

Yes

-

No

-

Language associated with the locale, for example, zh.

-

script

-

string

-

Yes

-

No

-

Script type of the language, for example, Hans.

-

region

-

string

-

Yes

-

No

-

Region associated with the locale, for example, CN.

-

baseName

-

string

-

Yes

-

No

-

Basic key information about the locale, which consists of the language, script, and region, for example, zh-Hans-CN.

-

caseFirst

-

string

-

Yes

-

No

-

Whether case is taken into account for the locale's collation rules. The value can be upper, lower, or false.

-

calendar

-

string

-

Yes

-

No

-

Calendar for the locale. The value can be buddhist, chinese, coptic, dangi, ethioaa, ethiopic, gregory, hebrew, indian, islamic, islamic-umalqura, islamic-tbla, islamic-civil, islamic-rgsa, iso8601, japanese, persian, roc, or islamicc.

-

collation

-

string

-

Yes

-

No

-

Collation rules for the locale. The value can be any of the following: big5han, compat, dict, direct, ducet, eor, gb2312, phonebk, phonetic, pinyin, reformed, searchjl, stroke, trad, unihan, and zhuyin.

-

hourCycle

-

string

-

Yes

-

No

-

Time system for the locale. The value can be h11, h12, h23, or h24.

-

numberingSystem

-

string

-

Yes

-

No

-

Numbering system for the locale. The value can be any of the following: adlm, ahom, arab, arabext, bali, beng, bhks, brah, cakm, cham, deva, diak, fullwide, gong, gonm, gujr, guru, hanidec, hmng, hmnp, java, kali, khmr, knda, lana, lanatham, laoo, latn, lepc, limb, mathbold, mathdbl, mathmono, mathsanb, mathsans, mlym, modi, mong, mroo, mtei, mymr, mymrshan, mymrtlng, newa, nkoo, olck, orya, osma, rohg, saur, segment, shrd, sind, sinh, sora, sund, takr, talu, tamldec, telu, thai, tibt, tirh, vaii, wara, and wcho.

-

numeric

-

boolean

-

Yes

-

No

-

Whether to apply special collation rules for numeric characters.

-
- -### constructor - -constructor\(locale: string, options?: options\) - -Creates a **Locale** object. - -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

locale

-

string

-

Yes

-

A string containing locale information, including the language, optional script, and locale.

-
- - -- Example - - ``` - var locale = new Intl.Locale("zh-CN"); - ``` - - -### toString - -toString\(\): string + +## Locale + + +### Attributes + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| language | string | Yes| No| Language associated with the locale, for example, **zh**.
**System capability**: SystemCapability.Global.I18n| +| script | string | Yes| No| Script type of the language, for example, **Hans**.
**System capability**: SystemCapability.Global.I18n| +| region | string | Yes| No| Region associated with the locale, for example, **CN**.
**System capability**: SystemCapability.Global.I18n| +| baseName | string | Yes| No| Basic key information about the locale, which consists of the language, script, and region, for example, **zh-Hans-CN**.
**System capability**: SystemCapability.Global.I18n| +| caseFirst | string | Yes| No| Whether case is taken into account for the locale's collation rules. The value can be **upper**, **lower**, or **false**.
**System capability**: SystemCapability.Global.I18n| +| calendar | string | Yes| No| Calendar for the locale. The value can be any of the following: buddhist, chinese, coptic, dangi, ethioaa, ethiopic, gregory, hebrew, indian, islamic, islamic-umalqura, islamic-tbla, islamic-civil, islamic-rgsa, iso8601, japanese, persian, roc, islamicc.
**System capability**: SystemCapability.Global.I18n| +| collation | string | Yes| No| Rule for sorting regions. The value can be any of the following: big5han, compat, dict, direct, ducet, eor, gb2312, phonebk, phonetic, pinyin, reformed, searchjl, stroke, trad, unihan, zhuyin.
**System capability**: SystemCapability.Global.I18n| +| hourCycle | string | Yes| No| Time system for the locale. The value can be any of the following: h12, h23, h11, and h24.
**System capability**: SystemCapability.Global.I18n| +| numberingSystem | string | Yes| No| Numbering system for the locale. The value can be any of the following: adlm, ahom, arab, arabext, bali, beng, bhks, brah, cakm, cham, deva, diak, fullwide, gong, gonm, gujr, guru, hanidec, hmng, hmnp, java, kali, khmr, knda, lana, lanatham, laoo, latn, lepc, limb, mathbold, mathdbl, mathmono, mathsanb, mathsans, mlym, modi, mong, mroo, mtei, mymr, mymrshan, mymrtlng, newa, nkoo, olck, orya, osma, rohg, saur, segment, shrd, sind, sinh, sora, sund, takr, talu, tamldec, telu, thai, tibt, tirh, vaii, wara, wcho.
**System capability**: SystemCapability.Global.I18n| +| numeric | boolean | Yes| No| Whether to apply special collation rules for numeric characters.
**System capability**: SystemCapability.Global.I18n| + + +### constructor + +constructor(locale: string, options?: options) + +Creates a Locale object. + +**System capability**: SystemCapability.Global.I18n + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | locale | string | Yes| A string containing locale information, including the language, optional script, and region.| + | options | options | No| Options for creating the **Locale** object.| + +- Example + ``` + var locale = new Intl.Locale("zh-CN"); + ``` + + +### toString + +toString(): string Converts locale information to a string. -- Return values +**System capability**: SystemCapability.Global.I18n + +- Return value + | Type| Description| + | -------- | -------- | + | string | String containing locale information.| + +- Example + ``` + var locale = new Intl.Locale("zh-CN"); + locale.toString(); + ``` + + +### maximize + +maximize(): Locale + +Maximizes information of the **Locale** object. If the script and locale information is missing, add the information. + +**System capability**: SystemCapability.Global.I18n + +- Return value + | Type| Description| + | -------- | -------- | + | [Locale](#locale) | **Locale** object with the maximized information.| + +- Example + ``` + var locale = new Intl.Locale("zh-CN"); + locale.maximize(); + ``` + - - - - - - - - - -

Type

-

Description

-

string

-

String containing locale information.

-
+### minimize +minimize(): Locale -- Example +Minimizes information of the **Locale** object. If the script and locale information is present, delete the information. - ``` - var locale = new Intl.Locale("zh-CN"); - locale.toString(); - ``` - - -### maximize - -maximize\(\): Locale - -Maximizes information of the **Locale** object. If the script and locale information is missing, add the information. - -- Return values - - - - - - - - - - -

Type

-

Description

-

Locale

-

Locale object with the maximized information.

-
+**System capability**: SystemCapability.Global.I18n +- Return value + | Type| Description| + | -------- | -------- | + | [Locale](#locale) | **Locale** object with the minimized information.| -- Example +- Example + ``` + var locale = new Intl.Locale("zh-CN"); + locale.minimize(); + ``` - ``` - var locale = new Intl.Locale("zh-CN"); - locale.maximize(); - ``` +## DateTimeFormat -### minimize - -minimize\(\): Locale - -Minimizes information of the **Locale** object. If the script and locale information is present, delete the information. - -- Return values - - - - - - - - - - -

Type

-

Description

-

Locale

-

Locale object with the minimized information.

-
- - -- Example - - ``` - var locale = new Intl.Locale("zh-CN"); - locale.minimize(); - ``` - - -## DateTimeFormat - -### constructor - -constructor\(locale: string, options?: DateTimeOptions\) - -Creates a **DateTimeOptions** object for the specified locale. - -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

locale

-

string

-

Yes

-

A string containing locale information, including the language, optional script, and locale.

-

options

-

DateTimeOptions

-

No

-

Options for creating a DateTimeFormat object.

-
- - -- Example - - ``` - var datefmt= new Intl.DateTimeFormat("zh-CN", { dateStyle: 'full', timeStyle: 'medium' }); - ``` - - -### constructor - -constructor\(locales: Array, options?: DateTimeOptions\) - -Creates a **DateTimeOptions** object for the specified array of locales. - -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

locales

-

Array<string>

-

Yes

-

An array of strings containing locale information.

-

options

-

DateTimeOptions

-

No

-

Options for creating a DateTimeFormat object.

-
- - -- Example - - ``` - var datefmt= new Intl.DateTimeFormat(["ban", "zh"], { dateStyle: 'full', timeStyle: 'medium' }); - ``` - - -### format - -format\(date: Date\): string + +### constructor + +constructor(locale: string, options?: DateTimeOptions) + +Creates a **DateTimeOptions** object for the specified locale. + +**System capability**: SystemCapability.Global.I18n + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | locale | string | Yes| A string containing locale information, including the language, optional script, and region.| + | options | [DateTimeOptions](#datetimeoptions) | No| Options for creating a **DateTimeFormat** object.| + +- Example + ``` + var datefmt= new Intl.DateTimeFormat("zh-CN", { dateStyle: 'full', timeStyle: 'medium' }); + ``` + + +### constructor + +constructor(locales: Array<string>, options?: DateTimeOptions) + +Creates a **DateTimeOptions** object for the specified locale. + +**System capability**: SystemCapability.Global.I18n + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | locales | Array<string> | Yes| An array of strings containing locale information.| + | options | [DateTimeOptions](#datetimeoptions) | No| Options for creating a **DateTimeFormat** object.| + +- Example + ``` + var datefmt= new Intl.DateTimeFormat(["ban", "zh"], { dateStyle: 'full', timeStyle: 'medium' }); + ``` + + +### format + +format(date: Date): string Formats the specified date and time. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

date

-

Date

-

Yes

-

Date and time to be formatted.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

string

-

A string containing the formatted date and time.

-
- - -- Example - - ``` - var date = new Date(2021, 11, 17, 3, 24, 0); - var datefmt = new Intl.DateTimeFormat("en-GB"); - datefmt.format(date); - ``` - - -### formatRange - -formatRange\(fromDate: Date, toDate: Date\): string +**System capability**: SystemCapability.Global.I18n + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | date | Date | Yes| Date and time to be formatted.| + +- Return value + | Type| Description| + | -------- | -------- | + | string | A string containing the formatted date and time.| + +- Example + ``` + var date = new Date(2021, 11, 17, 3, 24, 0); + var datefmt = new Intl.DateTimeFormat("en-GB"); + datefmt.format(date); + ``` + + +### formatRange + +formatRange(fromDate: Date, toDate: Date): string Formats the specified date range. -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

startDate

-

Date

-

Yes

-

Start date and time to be formatted.

-

endDate

-

Date

-

Yes

-

End date and time to be formatted.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

string

-

A string containing the formatted date and time range.

-
- - -- Example - - ``` - var startDate = new Date(2021, 11, 17, 3, 24, 0); - var endDate = new Date(2021, 11, 18, 3, 24, 0); - var datefmt = new Intl.DateTimeFormat("en-GB"); - datefmt.formatRange(startDate, endDate); - ``` - - -### resolvedOptions - -resolvedOptions\(\): DateTimeOptions - -Obtains the formatting options for **DateTimeFormat** object. - -- Return values - - - - - - - - - - -

Type

-

Description

-

DateTimeOptions

-

Formatting options for DateTimeFormat objects.

-
- - -- Example - - ``` - var datefmt = new Intl.DateTimeFormat("en-GB"); - datefmt.resolvedOptions(); - ``` - - -## DateTimeOptions - -Provides the options for the **DateTimeFormat** object. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Parameter Type

-

Readable

-

Writable

-

Description

-

locale

-

string

-

Yes

-

No

-

Locale, for example, zh-Hans-CN.

-

dateStyle

-

string

-

Yes

-

Yes

-

Date display format. The value can be long, short, medium, or full.

-

timeStyle

-

string

-

Yes

-

Yes

-

Time display format. The value can be long, short, medium, or full.

-

hourCycle

-

string

-

Yes

-

Yes

-

Time system for the locale. The value can be h11, h12, h23, or h24.

-

timeZone

-

string

-

Yes

-

Yes

-

Time zone represented by a valid IANA time zone ID.

-

numberingSystem

-

string

-

Yes

-

Yes

-

Numbering system for the locale. The value can be any of the following: adlm, ahom, arab, arabext, bali, beng, bhks, brah, cakm, cham, deva, diak, fullwide, gong, gonm, gujr, guru, hanidec, hmng, hmnp, java, kali, khmr, knda, lana, lanatham, laoo, latn, lepc, limb, mathbold, mathdbl, mathmono, mathsanb, mathsans, mlym, modi, mong, mroo, mtei, mymr, mymrshan, mymrtlng, newa, nkoo, olck, orya, osma, rohg, saur, segment, shrd, sind, sinh, sora, sund, takr, talu, tamldec, telu, thai, tibt, tirh, vaii, wara, and wcho.

-

hour12

-

boolean

-

Yes

-

Yes

-

Whether to use the 12-hour clock.

-

weekday

-

string

-

Yes

-

Yes

-

Workday display format. The value can be long, short, or narrow.

-

era

-

string

-

Yes

-

Yes

-

Era display format. The value can be long, short, or narrow.

-

year

-

string

-

Yes

-

Yes

-

Year display format. The value can be numeric or 2-digit.

-

month

-

string

-

Yes

-

Yes

-

Month display format. The value can be numeric, 2-digit, long, short, or narrow.

-

day

-

string

-

Yes

-

Yes

-

Day display format. The value can be numeric or 2-digit.

-

hour

-

string

-

Yes

-

Yes

-

Hour display format. The value can be numeric or 2-digit.

-

minute

-

string

-

Yes

-

Yes

-

Minute display format. The value can be numeric or 2-digit.

-

second

-

string

-

Yes

-

Yes

-

Second display format. The value can be numeric or 2-digit.

-

timeZoneName

-

string

-

Yes

-

Yes

-

Localized representation of a time zone name.

-

dayPeriod

-

string

-

Yes

-

Yes

-

Time period display format. The value can be long, short, or narrow.

-

localeMatcher

-

string

-

Yes

-

Yes

-

Locale matching algorithm. The value can be lookup or best fit.

-

formatMatcher

-

string

-

Yes

-

Yes

-

Format matching algorithm. The value can be basic or best fit.

-
- -## NumberFormat - -### constructor - -constructor\(locale: string, options?: NumberOptions\) - -Creates a **NumberFormat** object for the specified locale. - -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

locale

-

string

-

Yes

-

A string containing locale information, including the language, optional script, and locale.

-

options

-

NumberOptions

-

No

-

Options for creating a NumberFormat object.

-
- -- Example - - ``` - var numfmt = new Intl.NumberFormat("en-GB", {style:'decimal', notation:"scientific"}); - ``` - - -### constructor - -constructor\(locales: Array, options?: NumberOptions\) - -Creates a **NumberFormat** object for the specified array of locales. - -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

locales

-

Array<string>

-

Yes

-

An array of strings containing locale information.

-

options

-

NumberOptions

-

No

-

Options for creating a NumberFormat object.

-
- - -- Example - - ``` - var numfmt = new Intl.NumberFormat(["en-GB", "zh"], {style:'decimal', notation:"scientific"}); - ``` - - -### format - -format\(number: number\): string; +**System capability**: SystemCapability.Global.I18n + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | startDate | Date | Yes| Start date and time to be formatted.| + | endDate | Date | Yes| End date and time to be formatted.| + +- Return value + | Type| Description| + | -------- | -------- | + | string | A string containing the formatted date and time range.| + +- Example + ``` + var startDate = new Date(2021, 11, 17, 3, 24, 0); + var endDate = new Date(2021, 11, 18, 3, 24, 0); + var datefmt = new Intl.DateTimeFormat("en-GB"); + datefmt.formatRange(startDate, endDate); + ``` + + +### resolvedOptions + +resolvedOptions(): DateTimeOptions + +Obtains the formatting options for **DateTimeFormat** object. + +**System capability**: SystemCapability.Global.I18n + +- Return value + | Type| Description| + | -------- | -------- | + | [DateTimeOptions](#datetimeoptions) | Formatting options for **DateTimeFormat** objects.| + +- Example + ``` + var datefmt = new Intl.DateTimeFormat("en-GB"); + datefmt.resolvedOptions(); + ``` + + +## DateTimeOptions + +Provides the options for the **DateTimeFormat** object. + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| locale | string | Yes| No| Locale, for example, **zh-Hans-CN**.
**System capability**: SystemCapability.Global.I18n| +| dateStyle | string | Yes| Yes| Date display format. The value can be **long**, **short**, **medium**, or **full**.
**System capability**: SystemCapability.Global.I18n| +| timeStyle | string | Yes| Yes| Time display format. The value can be **long**, **short**, **medium**, or **full**.
**System capability**: SystemCapability.Global.I18n| +| hourCycle | string | Yes| Yes| Time system for the locale. The value can be any of the following: h11, h12, h23, h24.
**System capability**: SystemCapability.Global.I18n| +| timeZone | string | Yes| Yes| Time zone represented by a valid IANA time zone ID.
**System capability**: SystemCapability.Global.I18n| +| numberingSystem | string | Yes| Yes| Numbering system for the locale. The value can be any of the following: adlm, ahom, arab, arabext, bali, beng, bhks, brah, cakm, cham, deva, diak, fullwide, gong, gonm, gujr, guru, hanidec, hmng, hmnp, java, kali, khmr, knda, lana, lanatham, laoo, latn, lepc, limb, mathbold, mathdbl, mathmono, mathsanb, mathsans, mlym, modi, mong, mroo, mtei, mymr, mymrshan, mymrtlng, newa, nkoo, olck, orya, osma, rohg, saur, segment, shrd, sind, sinh, sora, sund, takr, talu, tamldec, telu, thai, tibt, tirh, vaii, wara, wcho.
**System capability**: SystemCapability.Global.I18n| +| hour12 | boolean | Yes| Yes| Whether to use the 12-hour clock.
**System capability**: SystemCapability.Global.I18n| +| weekday | string | Yes| Yes| Workday display format. The value can be **long**, **short**, or **narrow**.
**System capability**: SystemCapability.Global.I18n| +| era | string | Yes| Yes| Era display format. The value can be **long**, **short**, or **narrow**.
**System capability**: SystemCapability.Global.I18n| +| year | string | Yes| Yes| Year display format. The value can be **numeric** or **2-digit**.
**System capability**: SystemCapability.Global.I18n| +| month | string | Yes| Yes| Month display format. The value can be any of the following: numeric, 2-digit, long, short, narrow.
**System capability**: SystemCapability.Global.I18n| +| day | string | Yes| Yes| Day display format. The value can be **numeric** or **2-digit**.
**System capability**: SystemCapability.Global.I18n| +| hour | string | Yes| Yes| Hour display format. The value can be **numeric** or **2-digit**.
**System capability**: SystemCapability.Global.I18n| +| minute | string | Yes| Yes| Minute display format. The value can be **numeric** or **2-digit**.
**System capability**: SystemCapability.Global.I18n| +| second | string | Yes| Yes| Seconds display format. The value can be **numeric** or **2-digit**.
**System capability**: SystemCapability.Global.I18n| +| timeZoneName | string | Yes| Yes| Localized representation of a time zone name.
**System capability**: SystemCapability.Global.I18n| +| dayPeriod | string | Yes| Yes| Time period display format. The value can be **long**, **short**, or **narrow**.
**System capability**: SystemCapability.Global.I18n| +| localeMatcher | string | Yes| Yes| Locale matching algorithm. The value can be **lookup** or **best fit**.
**System capability**: SystemCapability.Global.I18n| +| formatMatcher | string | Yes| Yes| Format matching algorithm. The value can be **basic** or **best fit**.
**System capability**: SystemCapability.Global.I18n| + + +## NumberFormat + + +### constructor + +constructor(locale: string, options?: NumberOptions) + +Creates a **NumberFormat** object for the specified locale. + +**System capability**: SystemCapability.Global.I18n + +Parameters +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| locale | string | Yes| A string containing locale information, including the language, optional script, and region.| +| options | [NumberOptions](#numberoptions) | No| Options for creating a **NumberFormat** object.| + +- Example + ``` + var numfmt = new Intl.NumberFormat("en-GB", {style:'decimal', notation:"scientific"}); + ``` + + +### constructor + +constructor(locales: Array<string>, options?: NumberOptions) + +Creates a **NumberFormat** object for the specified locale. + +**System capability**: SystemCapability.Global.I18n + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | locales | Array<string> | Yes| An array of strings containing locale information.| + | options | [NumberOptions](#numberoptions) | No| Options for creating a **NumberFormat** object.| + +- Example + ``` + var numfmt = new Intl.NumberFormat(["en-GB", "zh"], {style:'decimal', notation:"scientific"}); + ``` + + +### format + +format(number: number): string; Formats a number. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

number

-

number

-

Yes

-

Number to be formatted.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

string

-

Formatted number.

-
- - -- Example - - ``` - var numfmt = new Intl.NumberFormat(["en-GB", "zh"], {style:'decimal', notation:"scientific"}); - numfmt.format(1223); - ``` - - -### resolvedOptions - -resolvedOptions\(\): NumberOptions - -Obtains the options of the **NumberFormat** object. - -- Return values - - - - - - - - - - -

Type

-

Description

-

NumberOptions

-

Options of the NumberFormat object.

-
- - -- Example - - ``` - var numfmt = new Intl.NumberFormat(["en-GB", "zh"], {style:'decimal', notation:"scientific"}); - numfmt.resolvedOptions(); - ``` - - -## NumberOptions +**System capability**: SystemCapability.Global.I18n + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | number | number | Yes| Number to be formatted.| + +- Return value + | Type| Description| + | -------- | -------- | + | string | Formatted number.| + + +- Example + ``` + var numfmt = new Intl.NumberFormat(["en-GB", "zh"], {style:'decimal', notation:"scientific"}); + numfmt.format(1223); + ``` + + +### resolvedOptions + +resolvedOptions(): NumberOptions + +Obtains the options of the **NumberFormat** object. + +**System capability**: SystemCapability.Global.I18n + +- Return value + | Type| Description| + | -------- | -------- | + | [NumberOptions](#numberoptions) | Formatting options for **NumberFormat** objects.| + + +- Example + ``` + var numfmt = new Intl.NumberFormat(["en-GB", "zh"], {style:'decimal', notation:"scientific"}); + numfmt.resolvedOptions(); + ``` + + +## NumberOptions Provides the device capability. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Parameter Type

-

Readable

-

Writable

-

Description

-

locale

-

string

-

Yes

-

No

-

Locale, for example, zh-Hans-CN.

-

currency

-

string

-

Yes

-

Yes

-

Currency unit, for example, EUR, CNY, or USD.

-

currencySign

-

string

-

Yes

-

Yes

-

Currency unit symbol. The value can be symbol, narrowSymbol, code, or name.

-

currencyDisplay

-

string

-

Yes

-

Yes

-

Currency display mode. The value can be symbol, narrowSymbol, code, or name.

-

unit

-

string

-

Yes

-

Yes

-

Unit name, for example, meter, inch, or hectare.

-

unitDisplay

-

string

-

Yes

-

Yes

-

Unit display format. The value can be long, short, or medium.

-

unitUsage

-

string

-

Yes

-

Yes

-

Unit use case. The value can be any of the following: 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, and volume-vehicle-fuel.

-

signDisplay

-

string

-

Yes

-

Yes

-

Number sign display format. The value can be auto, never, always, or expectZero.

-

compactDisplay

-

string

-

Yes

-

Yes

-

Compact display format. The value can be long or short.

-

notation

-

string

-

Yes

-

Yes

-

Number notation. The value can be standard, scientific, engineering, or compact.

-

localeMatcher

-

string

-

Yes

-

Yes

-

Locale matching algorithm. The value can be lookup or best fit.

-

style

-

string

-

Yes

-

Yes

-

Number display format. The value can be decimal, currency, percent, or unit.

-

numberingSystem

-

string

-

Yes

-

Yes

-

Numbering system for the locale. The value can be any of the following: adlm, ahom, arab, arabext, bali, beng, bhks, brah, cakm, cham, deva, diak, fullwide, gong, gonm, gujr, guru, hanidec, hmng, hmnp, java, kali, khmr, knda, lana, lanatham, laoo, latn, lepc, limb, mathbold, mathdbl, mathmono, mathsanb, mathsans, mlym, modi, mong, mroo, mtei, mymr, mymrshan, mymrtlng, newa, nkoo, olck, orya, osma, rohg, saur, segment, shrd, sind, sinh, sora, sund, takr, talu, tamldec, telu, thai, tibt, tirh, vaii, wara, and wcho.

-

useGrouping

-

boolean

-

Yes

-

Yes

-

Whether to use grouping for display.

-

miniumumIntegerDigits

-

number

-

Yes

-

Yes

-

Minimum number of digits allowed in the integer part of a number. The value ranges from 1 to 21.

-

miniumumFractionDigits

-

number

-

Yes

-

Yes

-

Minimum number of digits in the fraction part of a number. The value ranges from 0 to 20.

-

maxiumumFractionDigits

-

number

-

Yes

-

Yes

-

Maximum number of digits in the fraction part of a number. The value ranges from 1 to 21.

-

miniumumSignificantDigits

-

number

-

Yes

-

Yes

-

Minimum number of the least significant digits. The value ranges from 1 to 21.

-

maxiumumSignificantDigits

-

number

-

Yes

-

Yes

-

Maximum number of the least significant digits. The value ranges from 1 to 21.

-
- -## Collator8+ - -### constructor8+ - -constructor\(\) - -Creates a **Collator** object. - -- Example - - ``` - var collator = new Intl.Collator(); - ``` - - -### constructor8+ - -constructor\(locale: string | Array, options?: CollatorOptions\) - -Creates a **Collator** object based on the specified locale and options. +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| locale | string | Yes| No| Locale, for example, **zh-Hans-CN**.
**System capability**: SystemCapability.Global.I18n| +| currency | string | Yes| Yes| Currency unit, for example, **EUR**, **CNY**, or **USD**.
**System capability**: SystemCapability.Global.I18n| +| currencySign | string | Yes| Yes| Currency unit symbol. The value can be **symbol**, **narrowSymbol**, **code**, or **name**.
**System capability**: SystemCapability.Global.I18n| +| currencyDisplay | string | Yes| Yes| Currency display mode. The value can be **symbol**, **narrowSymbol**, **code**, or **name**.
**System capability**: SystemCapability.Global.I18n| +| unit | string | Yes| Yes| Unit name, for example, **meter**, **inch**, or **hectare**.
**System capability**: SystemCapability.Global.I18n| +| unitDisplay | string | Yes| Yes| Unit display format. The value can be **long**, **short**, or **medium**.
**System capability**: SystemCapability.Global.I18n| +| unitUsage | string | Yes| Yes| Unit usage scenario. The value can be any of the following: 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.
**System capability**: SystemCapability.Global.I18n| +| signDisplay | string | Yes| Yes| Number sign display format. The value can be **auto**, **never**, always**, or **expectZero**.
**System capability**: SystemCapability.Global.I18n| +| compactDisplay | string | Yes| Yes| Compact display format. The value can be **long** or **short**.
**System capability**: SystemCapability.Global.I18n| +| notation | string | Yes| Yes| Number formatting specification. The value can be **standard**, **scientific**, engineering**, or **compact**.
**System capability**: SystemCapability.Global.I18n| +| localeMatcher | string | Yes| Yes| Locale matching algorithm. The value can be **lookup** or **best fit**.
**System capability**: SystemCapability.Global.I18n| +| style | string | Yes| Yes| Number display format. The value can be **decimal**, **currency**, **percent**, or **unit**.
**System capability**: SystemCapability.Global.I18n| +| numberingSystem | string | Yes| Yes| Numbering system for the locale. The value can be any of the following: adlm, ahom, arab, arabext, bali, beng, bhks, brah, cakm, cham, deva, diak, fullwide, gong, gonm, gujr, guru, hanidec, hmng, hmnp, java, kali, khmr, knda, lana, lanatham, laoo, latn, lepc, limb, mathbold, mathdbl, mathmono, mathsanb, mathsans, mlym, modi, mong, mroo, mtei, mymr, mymrshan, mymrtlng, newa, nkoo, olck, orya, osma, rohg, saur, segment, shrd, sind, sinh, sora, sund, takr, talu, tamldec, telu, thai, tibt, tirh, vaii, wara, wcho.
**System capability**: SystemCapability.Global.I18n| +| useGrouping | boolean | Yes| Yes| Whether to use grouping for display.
**System capability**: SystemCapability.Global.I18n| +| miniumumIntegerDigits | number | Yes| Yes| Minimum number of digits allowed in the integer part of a number. The value ranges from **1** to **21**.
**System capability**: SystemCapability.Global.I18n| +| miniumumFractionDigits | number | Yes| Yes| Minimum number of digits in the fraction part of a number. The value ranges from **1** to **20**.
**System capability**: SystemCapability.Global.I18n| +| maxiumumFractionDigits | number | Yes| Yes| Maximum number of digits in the fraction part of a number. The value ranges from **1** to **21**.
**System capability**: SystemCapability.Global.I18n| +| miniumumSignificantDigits | number | Yes| Yes| Minimum number of the least significant digits. The value ranges from **1** to **21**.
**System capability**: SystemCapability.Global.I18n| +| maxiumumSignificantDigits | number | Yes| Yes| Maximum number of the least significant digits. The value ranges from **1** to **21**.
**System capability**: SystemCapability.Global.I18n| -Parameters - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

locale

-

string|Array<string>

-

Yes

-

A string containing locale information, including the language, optional script, and locale.

-

options

-

CollatorOptions

-

No

-

Options for creating a Collator object.

-
- -- Example - - ``` - var collator = new Intl.Collator("zh-CN", {"localeMatcher": "lookup", "usage": "sort"}); - ``` - - -### compare8+ - -compare\(first: string, second: string\): number - -Compares two strings based on the sorting policy of the **Collator**. - -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

first

-

string

-

Yes

-

First string to compare.

-

second

-

string

-

Yes

-

Second string to compare.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

number

-

Comparison result. If the value is a negative number, the first string is before the second string. If the value of number is 0, the first string is equal to the second string. If the value of number is a positive number, the first string is after the second string.

-
- - -- Example - - ``` - var collator = new intl.Collator("zh-Hans"); - collator.compare("first", "second"); - ``` - - -### resolvedOptions8+ - -resolvedOptions\(\): CollatorOptions - -Returns properties reflecting the locale and collation options of a **Collator** object. - -- Return values - - - - - - - - - - -

Type

-

Description

-

CollatorOptions

-

Properties of the Collator object.

-
- - -- Example - - ``` - var collator = new intl.Collator("zh-Hans"); - var options = collator.resolvedOptions(); - ``` - - -## CollatorOptions8+ - -Represents the properties of a **Collator** object. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Parameter Type

-

Readable

-

Writable

-

Description

-

localeMatcher

-

string

-

Yes

-

Yes

-

Locale matching algorithm. The value can be lookup or best fit.

-

usage

-

string

-

Yes

-

Yes

-

Whether the comparison is for sorting or for searching. The value can be sort or search.

-

sensitivity

-

string

-

Yes

-

Yes

-

Differences in the strings that lead to non-zero return values. The value can be base, accent, case, or variant.

-

ignorePunctuation

-

boolean

-

Yes

-

Yes

-

Whether punctuation is ignored. The value can be true or false.

-

collation

-

string

-

Yes

-

Yes

-

Sorting policy. The value can be any of the following: big5han, compat, dict, direct, ducet, eor, gb2312, phonebk, phonetic, pinyin, reformed, searchjl, stroke, trad, unihan, and zhuyin.

-

numeric

-

boolean

-

Yes

-

Yes

-

Whether numeric collation is used. The value can be true or false.

-

caseFirst

-

string

-

Yes

-

Yes

-

Whether upper case or lower case is sorted first. The value can be upper, lower, or false.

-
- -## PluralRules8+ - -### constructor8+ - -constructor\(\) - -Create a **PluralRules** object. - -- Example - - ``` - var pluralRules = new Intl.PluralRules(); - ``` - - -### constructor8+ - -constructor\(locale: string | Array, options?: PluralRulesOptions\) - -Creates a **PluralRules** object based on the specified locale and options. +## Collator8+ + + +### constructor8+ + +constructor() + +Creates a Collator object. + +**System capability**: SystemCapability.Global.I18n + +- Example + ``` + var collator = new Intl.Collator(); + ``` + + +### constructor8+ + +constructor(locale: string | Array<string>, options?: CollatorOptions) + +Creates a Collator object. + +**System capability**: SystemCapability.Global.I18n + +- Parameters + + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | locale | string\|Array<string> | Yes| A string containing locale information, including the language, optional script, and region.| + | options | [CollatorOptions](#collatoroptions) | No| Options for creating a **Collator** object.| + +- Example + ``` + var collator = new Intl.Collator("zh-CN", {"localeMatcher": "lookup", "usage": "sort"}); + ``` + + +### compare8+ + +compare(first: string, second: string): number + +Compares two strings based on the sorting policy of the **Collator** object. + +**System capability**: SystemCapability.Global.I18n + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | first | string | Yes| First string to compare.| + | second | string | Yes| Second string to compare.| + +- Return value + | Type| Description| + | -------- | -------- | + | number | Comparison result. If the value is a negative number, the first string is before the second string. If the value of number is **0**, the first string is equal to the second string. If the value of number is a positive number, the first string is after the second string.| + +- Example + ``` + var collator = new Intl.Collator("zh-Hans"); + collator.compare("first", "second"); + ``` + + +### resolvedOptions8+ + +resolvedOptions(): CollatorOptions + +Returns properties reflecting the locale and collation options of a **Collator** object. + +**System capability**: SystemCapability.Global.I18n + +- Return value + | Type| Description| + | -------- | -------- | + | [CollatorOptions](#collatoroptions) | Properties of the **Collator** object.| + +- Example + ``` + var collator = new Intl.Collator("zh-Hans"); + var options = collator.resolvedOptions(); + ``` + + +## CollatorOptions8+ + +Represents the properties of a **Collator** object. + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| localeMatcher | string | Yes| Yes| Locale matching algorithm. The value can be **lookup** or **best fit**.
**System capability**: SystemCapability.Global.I18n| +| usage | string | Yes| Yes| Whether the comparison is for sorting or for searching. The value can be **sort** or **search**.
**System capability**: SystemCapability.Global.I18n| +| sensitivity | string | Yes| Yes| Differences in the strings that lead to non-zero return values. The value can be **base**, **accent**, **case**, or **variant**.
**System capability**: SystemCapability.Global.I18n| +| ignorePunctuation | boolean | Yes| Yes| Whether punctuation is ignored. The value can be **true** or **false**.
**System capability**: SystemCapability.Global.I18n| +| collation | string | Yes| Yes| Rule for sorting regions. The value can be any of the following: big5han, compat, dict, direct, ducet, eor, gb2312, phonebk, phonetic, pinyin, reformed, searchjl, stroke, trad, unihan, zhuyin.
**System capability**: SystemCapability.Global.I18n| +| numeric | boolean | Yes| Yes| Whether numeric collation is used. The value can be **true** or **false**.
**System capability**: SystemCapability.Global.I18n| +| caseFirst | string | Yes| Yes| Whether upper case or lower case is sorted first. The value can be **upper**, **lower**, or **false**.
**System capability**: SystemCapability.Global.I18n| + + +## PluralRules8+ + + +### constructor8+ + +constructor() + +Create a **PluralRules** object. + +**System capability**: SystemCapability.Global.I18n + +- Example + ``` + var pluralRules = new Intl.PluralRules(); + ``` + + +### constructor8+ + +constructor(locale: string | Array<string>, options?: PluralRulesOptions) + +Create a **PluralRules** object. + +**System capability**: SystemCapability.Global.I18n Parameters +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| locale | string\|Array<string> | Yes| A string containing locale information, including the language, optional script, and region.| +| options | [PluralRulesOptions](#pluralrulesoptions) | No| Options for creating a **PluralRules** object.| + +- Example + ``` + var pluralRules= new Intl.PluraRules("zh-CN", {"localeMatcher": "lookup", "type": "cardinal"}); + ``` - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

locale

-

string|Array<string>

-

Yes

-

A string containing locale information, including the language, optional script, and locale.

-

options

-

PluralRulesOptions

-

No

-

Options for creating a PluralRules object.

-
- -- Example - - ``` - var pluralRules= new Intl.PluraRules("zh-CN", {"localeMatcher": "lookup", "type": "cardinal"}); - ``` - - -### select8+ - -select\(n: number\): string + +### select8+ + +select(n: number): string Obtains a string that represents the singular-plural type of the specified number. -- Parameters - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

n

-

number

-

Yes

-

Number for which the singular-plural type is to be obtained.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

string

-

Singular-plural type. The options are as follows: zero, one, two, few, many, and others.

-
- - -- Example - - ``` - var pluralRules = new intl.PluralRules("zh-Hans"); - pluralRules.select(1); - ``` - - -## PluralRulesOptions8+ - -Represents the properties of a **PluralRules** object. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Parameter Type

-

Readable

-

Writable

-

Description

-

localeMatcher

-

string

-

Yes

-

Yes

-

Locale matching algorithm. The value can be lookup or best fit.

-

type

-

string

-

Yes

-

Yes

-

Sorting type. The value can be cardinal or ordinal.

-

minimumIntegerDigits

-

number

-

Yes

-

Yes

-

Minimum number of digits allowed in the integer part of a number. The value ranges from 1 to 21.

-

minimumFractionDigits

-

number

-

Yes

-

Yes

-

Minimum number of digits in the fraction part of a number. The value ranges from 0 to 20.

-

maximumFractionDigits

-

number

-

Yes

-

Yes

-

Maximum number of digits in the fraction part of a number. The value ranges from 1 to 21.

-

minimumSignificantDigits

-

number

-

Yes

-

Yes

-

Minimum number of the least significant digits. The value ranges from 1 to 21.

-

maximumSignificantDigits

-

number

-

Yes

-

Yes

-

Maximum number of the least significant digits. The value ranges from 1 to 21.

-
- -## RelativeTimeFormat8+ - -### constructor8+ - -constructor\(\) - -Creates a **RelativeTimeFormat** object. - -- Example - - ``` - var relativetimefmt = new Intl.RelativeTimeFormat(); - ``` - - -### constructor8+ - -constructor\(locale: string | Array, options?: RelativeTimeFormatInputOptions\) - -Creates a **RelativeTimeFormat** object based on the specified locale and options. +**System capability**: SystemCapability.Global.I18n + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | n | number | Yes| Number for which the singular-plural type is to be obtained.| + +- Return value + | Type| Description| + | -------- | -------- | + | string | Singular-plural type. The value can be any of the following: one, two, few, many, others.| + +- Example + ``` + var pluralRules = new Intl.PluralRules("zh-Hans"); + pluralRules.select(1); + ``` + + +## PluralRulesOptions8+ + +Represents the properties of a **PluralRules** object. + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| localeMatcher | string | Yes| Yes| Locale matching algorithm. The value can be **lookup** or **best fit**.
**System capability**: SystemCapability.Global.I18n| +| type | string | Yes| Yes| Sorting type. The value can be **cardinal** or **ordinal**.
**System capability**: SystemCapability.Global.I18n| +| minimumIntegerDigits | number | Yes| Yes| Minimum number of digits allowed in the integer part of a number. The value ranges from **1** to **21**.
**System capability**: SystemCapability.Global.I18n| +| minimumFractionDigits | number | Yes| Yes| Minimum number of digits in the fraction part of a number. The value ranges from **0** to **20**.
**System capability**: SystemCapability.Global.I18n| +| maximumFractionDigits | number | Yes| Yes| Maximum number of digits in the fraction part of a number. The value ranges from **1** to **21**.
**System capability**: SystemCapability.Global.I18n| +| minimumSignificantDigits | number | Yes| Yes| Minimum number of the least significant digits. The value ranges from **1** to **21**.
**System capability**: SystemCapability.Global.I18n| +| maximumSignificantDigits | number | Yes| Yes| Maximum number of the least significant digits. The value ranges from **1** to **21**.
**System capability**: SystemCapability.Global.I18n| + + +## RelativeTimeFormat8+ + + +### constructor8+ + +constructor() + +Creates a **RelativeTimeFormat** object. + +**System capability**: SystemCapability.Global.I18n + +- Example + ``` + var relativetimefmt = new Intl.RelativeTimeFormat(); + ``` + + +### constructor8+ + +constructor(locale: string | Array<string>, options?: RelativeTimeFormatInputOptions) + +Creates a **RelativeTimeFormat** object. + +**System capability**: SystemCapability.Global.I18n Parameters +| Name| Type| Mandatory| Description| +| -------- | -------- | -------- | -------- | +| locale | string\|Array<string> | Yes| A string containing locale information, including the language, optional script, and region.| +| options | [RelativeTimeFormatInputOptions](#relativetimeformatinputoptions) | No| Options for creating a **RelativeTimeFormat** object.| + +- Example + ``` + var relativeTimeFormat = new Intl.RelativeTimeFormat("zh-CN", {"localeMatcher": "lookup", "numeric": "always", "style": "long"}); + ``` + - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

locale

-

string|Array<string>

-

Yes

-

A string containing locale information, including the language, optional script, and locale.

-

options

-

RelativeTimeFormatInputOptions

-

No

-

Options for creating a RelativeTimeFormat object.

-
- -- Example - - ``` - var relativeTimeFormat = new Intl.RelativeTimeFormat("zh-CN", {"localeMatcher": "lookup", "numeric": "always", "style": "long"}); - ``` - - -### format8+ - -format\(value: numeric, unit: string\): string +### format8+ + +format(value: numeric, unit: string): string Formats the value and unit based on the specified locale and formatting options. -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

value

-

numeric

-

Yes

-

Value to format.

-

unit

-

string

-

Yes

-

Unit to format. The value can be year, quarter, month, week, day, hour, minute, or second.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

string

-

Relative time after formatting.

-
- - -- Example - - ``` - var relativetimefmt = new Intl.RelativeTimeFormat("zh-CN"); - relativetimefmt.format(3, "quarter") - ``` - - -### formatToParts8+ - -formatToParts\(value: numeric, unit: string\): Array - -Returns an array of **RelativeTimeFormat** objects in parts for locale-aware formatting. - -- Parameters - - - - - - - - - - - - - - - - - - - -

Name

-

Type

-

Mandatory

-

Description

-

value

-

numeric

-

Yes

-

Value to format.

-

unit

-

string

-

Yes

-

Unit to format. The value can be year, quarter, month, week, day, hour, minute, or second.

-
- -- Return values - - - - - - - - - - -

Type

-

Description

-

Array<Object>

-

An array of RelativeTimeFormat objects in parts.

-
- - -- Example - - ``` - var relativetimefmt = new Intl.RelativeTimeFormat("en", {"numeric": "auto"}); - var parts = relativetimefmt.format(10, "seconds"); - ``` - - -### resolvedOptions8+ - -resolvedOptions\(\): RelativeTimeFormatResolvedOptions - -Obtains the formatting options for **RelativeTimeFormat** objects. - -- Return values - - - - - - - - - - -

Type

-

Description

-

RelativeTimeFormatResolvedOptions

-

Formatting options for RelativeTimeFormat objects.

-
- - -- Example - - ``` - var relativetimefmt= new Intl.RelativeTimeFormat("en-GB"); - relativetimefmt.resolvedOptions(); - ``` - - -## RelativeTimeFormatInputOptions8+ - -Represents the properties of a **RelativeTimeFormat** object. - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Parameter Type

-

Readable

-

Writable

-

Description

-

localeMatcher

-

string

-

Yes

-

Yes

-

Locale matching algorithm. The value can be lookup or best fit.

-

numeric

-

string

-

Yes

-

Yes

-

Format of the output message. The value can be always or auto.

-

style

-

string

-

Yes

-

Yes

-

Length of the internationalized message. The value can be long, short, or narrow.

-
- -## RelativeTimeFormatResolvedOptions8+ - -Represents the properties of a **RelativeTimeFormat** object. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Name

-

Parameter Type

-

Readable

-

Writable

-

Description

-

locale

-

string

-

Yes

-

Yes

-

A string containing locale information, including the language, optional script, and locale.

-

numeric

-

string

-

Yes

-

Yes

-

Format of the output message. The value can be always or auto.

-

style

-

string

-

Yes

-

Yes

-

Length of the internationalized message. The value can be long, short, or narrow.

-

numberingSystem

-

string

-

Yes

-

Yes

-

Numbering system.

-
+**System capability**: SystemCapability.Global.I18n + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | value | numeric | Yes| Value to format.| + | unit | string | Yes| Unit to format. The value can be any of the following: year, quarter, month, week, day, hour, minute, second.| + +- Return value + | Type| Description| + | -------- | -------- | + | string | Relative time after formatting.| + +- Example + ``` + var relativetimefmt = new Intl.RelativeTimeFormat("zh-CN"); + relativetimefmt.format(3, "quarter") + ``` + + +### formatToParts8+ + +formatToParts(value: numeric, unit: string): Array<Object> + +Returns an array of RelativeTimeFormat objects in parts for locale-aware formatting. + +**System capability**: SystemCapability.Global.I18n + +- Parameters + | Name| Type| Mandatory| Description| + | -------- | -------- | -------- | -------- | + | value | numeric | Yes| Value to format.| + | unit | string | Yes| Unit to format. The value can be any of the following: year, quarter, month, week, day, hour, minute, second.| + +- Return value + | Type| Description| + | -------- | -------- | + | Array<Object> | An array of **RelativeTimeFormat** objects in parts.| + +- Example + ``` + var relativetimefmt = new Intl.RelativeTimeFormat("en", {"numeric": "auto"}); + var parts = relativetimefmt.format(10, "seconds"); + ``` + + +### resolvedOptions8+ + +resolvedOptions(): RelativeTimeFormatResolvedOptions + +Obtains the formatting options for **RelativeTimeFormat** objects. + +**System capability**: SystemCapability.Global.I18n + +- Return value + | Type| Description| + | -------- | -------- | + | [RelativeTimeFormatResolvedOptions](#relativetimeformatresolvedoptions) | Formatting options for **RelativeTimeFormat** objects.| + +- Example + ``` + var relativetimefmt= new Intl.RelativeTimeFormat("en-GB"); + relativetimefmt.resolvedOptions(); + ``` + + +## RelativeTimeFormatInputOptions8+ + +Represents the properties of a **RelativeTimeFormat** object. + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| localeMatcher | string | Yes| Yes| Locale matching algorithm. The value can be **lookup** or **best fit**.
**System capability**: SystemCapability.Global.I18n| +| numeric | string | Yes| Yes| Format of the output message. The value can be **always** or **auto**.
**System capability**: SystemCapability.Global.I18n| +| style | string | Yes| Yes| Length of an internationalized message. The value can be **long**, **short**, or **narrow**.
**System capability**: SystemCapability.Global.I18n| + + +## RelativeTimeFormatResolvedOptions8+ + +Represents the properties of a **RelativeTimeFormat** object. + +| Name| Type| Readable| Writable| Description| +| -------- | -------- | -------- | -------- | -------- | +| locale | string | Yes| Yes| A string containing locale information, including the language, optional script, and region.
**System capability**: SystemCapability.Global.I18n| +| numeric | string | Yes| Yes| Format of the output message. The value can be **always** or **auto**.
**System capability**: SystemCapability.Global.I18n| +| style | string | Yes| Yes| Length of an internationalized message. The value can be **long**, **short**, or **narrow**.
**System capability**: SystemCapability.Global.I18n| +| numberingSystem | string | Yes| Yes| Numbering system.
**System capability**: SystemCapability.Global.I18n|