-
Notifications
You must be signed in to change notification settings - Fork 25.4k
New issue
Have a question about this project?Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of serviceand privacy statement.We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use platformIntl
APIs in Angular's i18n subsystem
#54470
Comments
Intl
APIs in Angular's i18n subsystem
I think this is the right direction for all the listed reasons. 👍 Would it still be possible to customize e.g. date formats/logic? Thank you for the consideration. |
@kyubisationas of now, you could useLuxonandAngular Luxon:you can both configure thetimezoneandBCP-47 language code(just like it-CH or rm-CH). |
@massic80Thank you for the reference, but we would prefer using the native Date object (or in the future the temporal objects). |
@kyubisation |
You're welcome, I understand. I proposed it cause it's a "wrapper" for Intl, nothing "new":) |
While I don't object to this move to For example, Chrome currently does not provide support for the Welsh language,among others,when using I think as an opinionated framework, Angular should document how best to replace uses of all deprecated functions, including how to check for runtime support for the target locale, and how to handle cases where the locale data is not available (e.g., perhaps by dynamically checking during initialization and conditionally loading a polyfill). |
I have had a look at the implementation. As an example; The As mentioned, we would love to have a configuration possibility e.g. via DI, which is not possible at the moment, as e.g. the DatePipe directly calls |
getLocaleFirstDayOfWeek It shouldn't be marked as deprecated when you opt out of the new system. |
@KetecAngular has the same limitations, It needs to provide all those values via static imports. Luxon for example uses a default fallback for the cases where the API isn't supported: |
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
implementationReplacing the legacy implementation with data from locale files with the an
Intl
based implementation has several benefits.fa-AF-u-nu-latn
specifies Persian, Afghanistan,Western Digits).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 withIntl.formatNumber
,Intl.formatDate
,Intl.Plural
.Getters with none/partial replacements:
getLocaleWeekEndRange
&getLocaleFirstDayOfWeek
:Intl.getWeekInfo()
not supported by Firefox (122 ATM)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 rangedate-fns
Provides locale dataweekStartsOn
&firstWeekContainsDate
but not the weekend range.getLocaleDirection
:Intl.getTextInfo()
not supported by Firefox (122 ATM)rtl-detect
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
Intl
implementation for the i18n sub-system.#55283Related issues
Intl
browser APIs for internationalization#49143zh-Hant-TW
orzh-TW
locale in@angular/common
#54114Components
The text was updated successfully, but these errors were encountered: