-
Notifications
You must be signed in to change notification settings - Fork 26.6k
Description
In 2017 (#18284), it was chosen to drop the Intl
API in favor of custom i18N data extracted from the CLDR (@angular/common/locales/...
.
Since then the Intl
API has matured a lot and is now able to cover the feature provided by the framework.
Replacing the legacy i18n implementation with the Intl
API is move to shift the localisation responsability from the framework to the platform (browsers, Node or Cloud workers).
Benefits of switching to an Intl
implementation
Replacing the legacy implementation with data from locale files with the an Intl
based implementation has several benefits.
- No need to import locale files to add support for additional languages (default was only english)
- Bundle size improvements
- Support for extended locales which allow specifying numbering system, calendar extension etc (ie
fa-AF-u-nu-latn
specifies Persian, Afghanistan,Western Digits). - Support for IANA timezones when formating dates
Deprecations
This will lead to the deprecation of the following locale getters :
getCurrencySymbol(code: string, format: 'wide' | 'narrow', locale?: string)
getLocaleCurrencyCode(locale: string)
getLocaleCurrencyName(locale: string)
getLocaleCurrencySymbol(locale: string)
getLocaleDateFormat(locale: string, width: FormatWidth)
getLocaleDateTimeFormat(locale: string, width: FormatWidth)
getLocaleDayNames(locale: string, formStyle: FormStyle, width: TranslationWidth)
getLocaleDayPeriods(locale: string, formStyle: FormStyle, width: TranslationWidth)
getLocaleDirection(locale: string)
getLocaleEraNames(locale: string, width: TranslationWidth)
getLocaleExtraDayPeriodRules(locale: string): (Time | [Time, Time])
getLocaleExtraDayPeriods(locale: string, formStyle: FormStyle, width: TranslationWidth)
getLocaleFirstDayOfWeek(locale: string)
getLocaleId(locale: string)
getLocaleMonthNames(locale: string, formStyle: FormStyle, width: TranslationWidth)
getLocaleNumberFormat(locale: string, type: NumberFormatStyle)
getLocaleNumberSymbol(locale: string, symbol: NumberSymbol)
getLocalePluralCase: (locale: string) => (value: number)
getLocaleTimeFormat(locale: string, width: FormatWidth)
getLocaleWeekEndRange(locale: string)
getNumberOfCurrencyDigits(code: string)
Those functions, barring exceptions mentioned below, should be replacing by using the Intl
API with Intl.formatNumber
, Intl.formatDate
, Intl.Plural
.
Getters with none/partial replacements :
getLocaleWeekEndRange
&getLocaleFirstDayOfWeek
:Intl.getWeekInfo()
not supported by Firefox (122 ATM)-
- Alternatives
-
-
luxon
falls back to the ISO week definition (starts on monday, 4 days in week for the week year).
-
-
-
day.js
Provides locale data foryearStart
andweekStart
but not the weekend range
-
-
-
date-fns
Provides locale dataweekStartsOn
&firstWeekContainsDate
but not the weekend range.
-
getLocaleDirection
:Intl.getTextInfo()
not supported by Firefox (122 ATM)-
- Alternative :
rtl-detect
- Alternative :
getLocaleCurrencySymbol
/getLocaleCurrencyCode
: We recommend developers fully drop this function as currencies shouldn’t be determined from a locale.
Rolout plan
The feature will be enabled by default for new projects and opt-out on existing project when migrated with ng update
.
Schedule TBD.
Related PRs
- refactor(common): Deprecate Local Data API functions #54483
- feat(common): Add an
Intl
implementation for the i18n sub-system. #55283
Related issues
- i18n: document how to lazy load locale data on bootstrap of application #20487
- Missing space between currency code and value in currency pipe #2 #33803
- fix(common): support consistent locale and ISO formatting #39606
- Explore potential CLDR locale data byte savings by omitting trailing undefined values #42315
- Support IANA time zone for date formatting #48279
- CLDR version is out of date #48697
- Consider switching back to
Intl
browser APIs for internationalization #49143 - Datepipe formating with timezone - incorrect date in date when is winter time changed to summer time #49540
- Unable to use uncommon ISO localisation subtags #52177
- Unable to find
zh-Hant-TW
orzh-TW
locale in@angular/common
#54114 - Locale is not loaded automatically when using ng build, but it is when using ng serve #54320