@angular/common
Version:
Angular - commonly needed directives and services
349 lines (348 loc) • 14.5 kB
TypeScript
/**
* The different format styles that can be used to represent numbers.
* Used by the function {@link getLocaleNumberFormat}.
*
* @experimental i18n support is experimental.
*/
export declare enum NumberFormatStyle {
Decimal = 0,
Percent = 1,
Currency = 2,
Scientific = 3,
}
/** @experimental */
export declare enum Plural {
Zero = 0,
One = 1,
Two = 2,
Few = 3,
Many = 4,
Other = 5,
}
/**
* Some languages use two different forms of strings (standalone and format) depending on the
* context.
* Typically the standalone version is the nominative form of the word, and the format version is in
* the genitive.
* See [the CLDR website](http://cldr.unicode.org/translation/date-time) for more information.
*
* @experimental i18n support is experimental.
*/
export declare enum FormStyle {
Format = 0,
Standalone = 1,
}
/**
* Multiple widths are available for translations: narrow (1 character), abbreviated (3 characters),
* wide (full length), and short (2 characters, only for days).
*
* For example the day `Sunday` will be:
* - Narrow: `S`
* - Short: `Su`
* - Abbreviated: `Sun`
* - Wide: `Sunday`
*
* @experimental i18n support is experimental.
*/
export declare enum TranslationWidth {
Narrow = 0,
Abbreviated = 1,
Wide = 2,
Short = 3,
}
/**
* Multiple widths are available for formats: short (minimal amount of data), medium (small amount
* of data), long (complete amount of data), full (complete amount of data and extra information).
*
* For example the date-time formats for the english locale will be:
* - `'short'`: `'M/d/yy, h:mm a'` (e.g. `6/15/15, 9:03 AM`)
* - `'medium'`: `'MMM d, y, h:mm:ss a'` (e.g. `Jun 15, 2015, 9:03:01 AM`)
* - `'long'`: `'MMMM d, y, h:mm:ss a z'` (e.g. `June 15, 2015 at 9:03:01 AM GMT+1`)
* - `'full'`: `'EEEE, MMMM d, y, h:mm:ss a zzzz'` (e.g. `Monday, June 15, 2015 at
* 9:03:01 AM GMT+01:00`)
*
* @experimental i18n support is experimental.
*/
export declare enum FormatWidth {
Short = 0,
Medium = 1,
Long = 2,
Full = 3,
}
/**
* Number symbol that can be used to replace placeholders in number patterns.
* The placeholders are based on english values:
*
* | Name | Example for en-US | Meaning |
* |------------------------|-------------------|---------------------------------------------|
* | decimal | 2,345`.`67 | decimal separator |
* | group | 2`,`345.67 | grouping separator, typically for thousands |
* | plusSign | `+`23 | the plus sign used with numbers |
* | minusSign | `-`23 | the minus sign used with numbers |
* | percentSign | 23.4`%` | the percent sign (out of 100) |
* | perMille | 234`‰` | the permille sign (out of 1000) |
* | exponential | 1.2`E`3 | used in computers for 1.2×10³. |
* | superscriptingExponent | 1.2`×`103 | human-readable format of exponential |
* | infinity | `∞` | used in +∞ and -∞. |
* | nan | `NaN` | "not a number". |
* | timeSeparator | 10`:`52 | symbol used between time units |
* | currencyDecimal | $2,345`.`67 | decimal separator, fallback to "decimal" |
* | currencyGroup | $2`,`345.67 | grouping separator, fallback to "group" |
*
* @experimental i18n support is experimental.
*/
export declare enum NumberSymbol {
Decimal = 0,
Group = 1,
List = 2,
PercentSign = 3,
PlusSign = 4,
MinusSign = 5,
Exponential = 6,
SuperscriptingExponent = 7,
PerMille = 8,
Infinity = 9,
NaN = 10,
TimeSeparator = 11,
CurrencyDecimal = 12,
CurrencyGroup = 13,
}
/**
* The value for each day of the week, based on the en-US locale
*
* @experimental
*/
export declare enum WeekDay {
Sunday = 0,
Monday = 1,
Tuesday = 2,
Wednesday = 3,
Thursday = 4,
Friday = 5,
Saturday = 6,
}
/**
* The locale id for the chosen locale (e.g `en-GB`).
*
* @experimental i18n support is experimental.
*/
export declare function getLocaleId(locale: string): string;
/**
* Periods of the day (e.g. `[AM, PM]` for en-US).
*
* @experimental i18n support is experimental.
*/
export declare function getLocaleDayPeriods(locale: string, formStyle: FormStyle, width: TranslationWidth): [string, string];
/**
* Days of the week for the Gregorian calendar (e.g. `[Sunday, Monday, ... Saturday]` for en-US).
*
* @experimental i18n support is experimental.
*/
export declare function getLocaleDayNames(locale: string, formStyle: FormStyle, width: TranslationWidth): string[];
/**
* Months of the year for the Gregorian calendar (e.g. `[January, February, ...]` for en-US).
*
* @experimental i18n support is experimental.
*/
export declare function getLocaleMonthNames(locale: string, formStyle: FormStyle, width: TranslationWidth): string[];
/**
* Eras for the Gregorian calendar (e.g. AD/BC).
*
* @experimental i18n support is experimental.
*/
export declare function getLocaleEraNames(locale: string, width: TranslationWidth): [string, string];
/**
* First day of the week for this locale, based on english days (Sunday = 0, Monday = 1, ...).
* For example in french the value would be 1 because the first day of the week is Monday.
*
* @experimental i18n support is experimental.
*/
export declare function getLocaleFirstDayOfWeek(locale: string): WeekDay;
/**
* Range of days in the week that represent the week-end for this locale, based on english days
* (Sunday = 0, Monday = 1, ...).
* For example in english the value would be [6,0] for Saturday to Sunday.
*
* @experimental i18n support is experimental.
*/
export declare function getLocaleWeekEndRange(locale: string): [WeekDay, WeekDay];
/**
* Date format that depends on the locale.
*
* There are four basic date formats:
* - `full` should contain long-weekday (EEEE), year (y), long-month (MMMM), day (d).
*
* For example, English uses `EEEE, MMMM d, y`, corresponding to a date like
* "Tuesday, September 14, 1999".
*
* - `long` should contain year, long-month, day.
*
* For example, `MMMM d, y`, corresponding to a date like "September 14, 1999".
*
* - `medium` should contain year, abbreviated-month (MMM), day.
*
* For example, `MMM d, y`, corresponding to a date like "Sep 14, 1999".
* For languages that do not use abbreviated months, use the numeric month (MM/M). For example,
* `y/MM/dd`, corresponding to a date like "1999/09/14".
*
* - `short` should contain year, numeric-month (MM/M), and day.
*
* For example, `M/d/yy`, corresponding to a date like "9/14/99".
*
* @experimental i18n support is experimental.
*/
export declare function getLocaleDateFormat(locale: string, width: FormatWidth): string;
/**
* Time format that depends on the locale.
*
* The standard formats include four basic time formats:
* - `full` should contain hour (h/H), minute (mm), second (ss), and zone (zzzz).
* - `long` should contain hour, minute, second, and zone (z)
* - `medium` should contain hour, minute, second.
* - `short` should contain hour, minute.
*
* Note: The patterns depend on whether the main country using your language uses 12-hour time or
* not:
* - For 12-hour time, use a pattern like `hh:mm a` using h to mean a 12-hour clock cycle running
* 1 through 12 (midnight plus 1 minute is 12:01), or using K to mean a 12-hour clock cycle
* running 0 through 11 (midnight plus 1 minute is 0:01).
* - For 24-hour time, use a pattern like `HH:mm` using H to mean a 24-hour clock cycle running 0
* through 23 (midnight plus 1 minute is 0:01), or using k to mean a 24-hour clock cycle running
* 1 through 24 (midnight plus 1 minute is 24:01).
*
* @experimental i18n support is experimental.
*/
export declare function getLocaleTimeFormat(locale: string, width: FormatWidth): string;
/**
* Date-time format that depends on the locale.
*
* The date-time pattern shows how to combine separate patterns for date (represented by {1})
* and time (represented by {0}) into a single pattern. It usually doesn't need to be changed.
* What you want to pay attention to are:
* - possibly removing a space for languages that don't use it, such as many East Asian languages
* - possibly adding a comma, other punctuation, or a combining word
*
* For example:
* - English uses `{1} 'at' {0}` or `{1}, {0}` (depending on date style), while Japanese uses
* `{1}{0}`.
* - An English formatted date-time using the combining pattern `{1}, {0}` could be
* `Dec 10, 2010, 3:59:49 PM`. Notice the comma and space between the date portion and the time
* portion.
*
* There are four formats (`full`, `long`, `medium`, `short`); the determination of which to use
* is normally based on the date style. For example, if the date has a full month and weekday
* name, the full combining pattern will be used to combine that with a time. If the date has
* numeric month, the short version of the combining pattern will be used to combine that with a
* time. English uses `{1} 'at' {0}` for full and long styles, and `{1}, {0}` for medium and short
* styles.
*
* @experimental i18n support is experimental.
*/
export declare function getLocaleDateTimeFormat(locale: string, width: FormatWidth): string;
/**
* Number symbol that can be used to replace placeholders in number formats.
* See {@link NumberSymbol} for more information.
*
* @experimental i18n support is experimental.
*/
export declare function getLocaleNumberSymbol(locale: string, symbol: NumberSymbol): string;
/**
* Number format that depends on the locale.
*
* Numbers are formatted using patterns, like `#,###.00`. For example, the pattern `#,###.00`
* when used to format the number 12345.678 could result in "12'345,67". That would happen if the
* grouping separator for your language is an apostrophe, and the decimal separator is a comma.
*
* <b>Important:</b> The characters `.` `,` `0` `#` (and others below) are special placeholders;
* they stand for the decimal separator, and so on, and are NOT real characters.
* You must NOT "translate" the placeholders; for example, don't change `.` to `,` even though in
* your language the decimal point is written with a comma. The symbols should be replaced by the
* local equivalents, using the Number Symbols for your language.
*
* Here are the special characters used in number patterns:
*
* | Symbol | Meaning |
* |--------|---------|
* | . | Replaced automatically by the character used for the decimal point. |
* | , | Replaced by the "grouping" (thousands) separator. |
* | 0 | Replaced by a digit (or zero if there aren't enough digits). |
* | # | Replaced by a digit (or nothing if there aren't enough). |
* | ¤ | This will be replaced by a currency symbol, such as $ or USD. |
* | % | This marks a percent format. The % symbol may change position, but must be retained. |
* | E | This marks a scientific format. The E symbol may change position, but must be retained. |
* | ' | Special characters used as literal characters are quoted with ASCII single quotes. |
*
* You can find more information
* [on the CLDR website](http://cldr.unicode.org/translation/number-patterns)
*
* @experimental i18n support is experimental.
*/
export declare function getLocaleNumberFormat(locale: string, type: NumberFormatStyle): string;
/**
* The symbol used to represent the currency for the main country using this locale (e.g. $ for
* the locale en-US).
* The symbol will be `null` if the main country cannot be determined.
*
* @experimental i18n support is experimental.
*/
export declare function getLocaleCurrencySymbol(locale: string): string | null;
/**
* The name of the currency for the main country using this locale (e.g. USD for the locale
* en-US).
* The name will be `null` if the main country cannot be determined.
*
* @experimental i18n support is experimental.
*/
export declare function getLocaleCurrencyName(locale: string): string | null;
/**
* The locale plural function used by ICU expressions to determine the plural case to use.
* See {@link NgPlural} for more information.
*
* @experimental i18n support is experimental.
*/
export declare function getLocalePluralCase(locale: string): (value: number) => Plural;
/**
* Rules used to determine which day period to use (See `dayPeriods` below).
* The rules can either be an array or a single value. If it's an array, consider it as "from"
* and "to". If it's a single value then it means that the period is only valid at this exact
* value.
* There is always the same number of rules as the number of day periods, which means that the
* first rule is applied to the first day period and so on.
* You should fallback to AM/PM when there are no rules available.
*
* Note: this is only available if you load the full locale data.
* See the {@linkDocs guide/i18n#i18n-pipes "I18n guide"} to know how to import additional locale
* data.
*
* @experimental i18n support is experimental.
*/
export declare function getLocaleExtraDayPeriodRules(locale: string): (Time | [Time, Time])[];
/**
* Day Periods indicate roughly how the day is broken up in different languages (e.g. morning,
* noon, afternoon, midnight, ...).
* You should use the function {@link getLocaleExtraDayPeriodRules} to determine which period to
* use.
* You should fallback to AM/PM when there are no day periods available.
*
* Note: this is only available if you load the full locale data.
* See the {@linkDocs guide/i18n#i18n-pipes "I18n guide"} to know how to import additional locale
* data.
*
* @experimental i18n support is experimental.
*/
export declare function getLocaleExtraDayPeriods(locale: string, formStyle: FormStyle, width: TranslationWidth): string[];
/**
* A representation of the time with hours and minutes
*
* @experimental i18n support is experimental.
*/
export declare type Time = {
hours: number;
minutes: number;
};
/**
* Finds the locale data for a locale id
*
* @experimental i18n support is experimental.
*/
export declare function findLocaleData(locale: string): any;