From 4900c788c26070847fa802cdb4908f939003f1b3 Mon Sep 17 00:00:00 2001 From: sunyaozu Date: Fri, 5 Nov 2021 14:55:38 +0800 Subject: [PATCH] add collator, pluralRules, isRTL to i18n Signed-off-by: sunyaozu --- api/@ohos.i18n.d.ts | 9 +++ api/@ohos.intl.d.ts | 189 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 198 insertions(+) diff --git a/api/@ohos.i18n.d.ts b/api/@ohos.i18n.d.ts index 8e9598d253..477d94ec24 100644 --- a/api/@ohos.i18n.d.ts +++ b/api/@ohos.i18n.d.ts @@ -165,4 +165,13 @@ export class PhoneNumberFormat { */ format(number: string): string; } + +/** + * check whether the locale is an RTL locale. + * + * @param locale Indicates the locale to use. + * @return Returns true if the locale is an RTL locale and vice versa. + * @since 8 + */ +export function isRTL(locale: string): boolean; } \ No newline at end of file diff --git a/api/@ohos.intl.d.ts b/api/@ohos.intl.d.ts index 8755ac6814..fbd004e586 100755 --- a/api/@ohos.intl.d.ts +++ b/api/@ohos.intl.d.ts @@ -406,5 +406,194 @@ export class NumberFormat { */ resolvedOptions(): NumberOptions; } + +/** + * Provides the options of Collator + */ +export interface CollatorOptions { + /** + * The locale matching algorithm to use. + * Possible values are "lookup" and "best fit"; the default is "best fit". + */ + localeMatcher: string; + + /** + * Whether the comparison is for sorting or for searching for matching strings. + * Possible values are "sort" and "search"; the default is "sort". + */ + usage: string; + + /** + * Which differences in the strings should lead to non-zero result values. + * Possible values are "base", "accent", "case", "variant". + */ + sensitivity: string; + + /** + * Whether punctuation should be ignored. + * Possible values are true and false; the default is false. + */ + ignorePunctuation: boolean; + + /** + * Variant collations for certain locales. + */ + collation: string; + + /** + * Whether numeric collation should be used. + * Possible values are true and false; the default is false. + */ + numeric: boolean; + + /** + * Whether upper case or lower case should sort first. + * Possible values are "upper", "lower", or "false" (use the locale's default). + */ + caseFirst: string; +} + +/** + * Provides the API for collation. + */ +export class Collator { + /** + * A constructor used to create Collator object. + * + * @since 8 + */ + constructor(); + + /** + * A constructor used to create Collator Object; + * + * @param locale Indicates a character string containing the locale information, including + * the language and optionally the script and region, for the Collator object. + * @param options Indicates the options used to initialize Collator object. + * @since 8 + */ + constructor(locale: string, options?: CollatorOptions); + + /** + * A constructor used to create Collator Object; + * + * @param locale Indicates a character string Array containing the locales information, including + * the language and optionally the script and region, for the Collator object. + * @param option Indicates the options used to initialize Collator object. + * @since 8 + */ + constructor(locale: Array, option?: CollatorOptions); + + /** + * compares two strings according to the sort order of this Collator object + * + * @param first The first string to compare. + * @param second The second string to compare. + * @return Returns a number indicating how first compare to second: + * a negative value if string1 comes before string2; + * a positive value if string1 comes after string2; + * 0 if they are considered equal. + * @since 8 + */ + compare(first: string, second: string): number; + + /** + * Returns a new object with properties reflecting the locale and collation options computed + * during initialization of the object. + * + * @return Returns a CollatorOptions object reflecting the properties of this object. + * @since 8 + */ + resolvedOptions(): CollatorOptions; +} + +/** + * Provides the options of PluralRules + */ +export interface PluralRulesOptions { + /** + * The locale matching algorithm to use. + * Possible values are "lookup" and "best fit"; the default is "best fit". + */ + localeMatcher: string; + + /** + * The type to use. Possible values are: "cardinal", "ordinal" + */ + type: string; + + /** + * The minimum number of integer digits to use. + * Possible values are from 1 to 21; the default is 1. + */ + minimumIntegerDigits: number; + + /** + * The minimum number of fraction digits to use. + * Possible values are from 0 to 20; the default for plain number and percent formatting is 0; + */ + minimumFractionDigits: number; + + /** + * The maximum number of fraction digits to use. + * Possible values are from 0 to 20; + * the default for plain number formatting is the larger of minimumFractionDigits and 3; + */ + maximumFractionDigits: number; + + /** + * The minimum number of significant digits to use. + * Possible values are from 1 to 21; the default is 1. + */ + minimumSignificantDigits: number; + + /** + * The maximum number of significant digits to use. + * Possible values are from 1 to 21; the default is 21. + */ + maximumSignificantDigits: number; +} + +/** + * Provides the API for PluralRules. + */ +export class PluralRules { + /** + * A constructor used to create PluralRules object. + * + * @since 8 + */ + constructor(); + + /** + * A constructor used to create PluralRules object. + * + * @param locale Indicates a character string containing the locale information, including + * the language and optionally the script and region, for the PluralRules object. + * @param options Indicates the options used to initialize PluralRules object. + * @since 8 + */ + constructor(locale: string, options?: PluralRulesOptions); + + /** + * A constructor used to create PluralRules object. + * + * @param locale Indicates character strings containing the locales information, including + * the language and optionally the script and region, for the PluralRules object. + * @param options Indicates the options used to initialize PluralRules object. + * @since 8 + */ + constructor(locale: Array, options?: PluralRulesOptions); + + /** + * Returns a string indicating which plural rule to use for locale-aware formatting. + * + * @param number The number to get a plural rule for. + * @return A string representing the pluralization category of the number, + * can be one of zero, one, two, few, many or other. + * @since 8 + */ + select(number: number): string; +} } export default intl; \ No newline at end of file -- Gitee