Skip to content

Use platform Intl APIs in Angular's i18n subsystem #54470

@JeanMeche

Description

@JeanMeche

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 for yearStart and weekStart but not the weekend range
      • date-fns Provides locale data weekStartsOn & firstWeekContainsDate but not the weekend range.
  • getLocaleDirection : Intl.getTextInfo() not supported by Firefox (122 ATM)
  • 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

Related issues

Components

Metadata

Metadata

Assignees

Labels

area: i18nIssues related to localization and internationalization

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions