8000 Consider switching back to `Intl` browser APIs for internationalization · Issue #49143 · angular/angular · GitHub
[go: up one dir, main page]

Skip to content

Consider switching back to Intl browser APIs for internationalization #49143

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
json-derulo opened this issue Feb 20, 2023 · 3 comments
Closed
Assignees
Labels
area: i18n Issues related to localization and internationalization breaking changes
Milestone

Comments

@json-derulo
Copy link
Contributor
json-derulo commented Feb 20, 2023

Which @angular/* package(s) are relevant/related to the feature request?

common

Description

Back in the days Angular used Intl APIs in their pipes, but due to different browser implementations this led to many issues. So in 2017, Angular decided to go for a custom implementation, which I think was the right decision at the time. But today we are in a quite different situation. Internet Explorer support has been dropped from Angular, browser support has evolved and the browsers heavily worked on unification of their APIs. In my opinion, it should be re-evaluated whether to switch back to the Intl APIs.

This would have an effect to all pipes which require locale data, namely date, currency, decimal and percent. For developers who don't use compile-time translations it's quite inconvenient to feed those pipes with locale data. Developers need to import from @angular/common/locales/{localeId}, and register the data with registerLocaleData(). When supporting multiple locales, either they all need to be added to the bundle (which bloats up the bundle size), or alternatively they can be loaded with a dynamic import. With the latter solution, additional chunks containing the locale data for each language are generated. Those chunks need to be loaded at runtime depending on the locale of the user. This can lead to missing locale data during the time when the main bundle is already loaded, but the request loading the chunk with the locale data is still pending. The handling of locale data is the main reason why I personally don’t use any of these Angular pipes anymore and wrote own pipes instead based on Intl. I assume I’m not the only one.

Additionally, after a quick search in the GitHub issues, I found that there are some issues with the implementation of the pipes, which could be resolved: #47479 #48279 #48250 #45409 #54114 and more

To list some of the benefits:

  • Implementation is much simpler
  • Locale data of any locale supported out of the box
    • Angular wouldn't need to care about locales at all -> less maintenance effort
    • Developers wouldn't need any additional code to register locale data
    • The application wouldn't need to load any code related to to locale data
    • In general, less pitfalls for the developers
  • Falls back to browser default locale if no locale is specified
  • Reduced bundle size, because code to register and process locale data at runtime can be removed

Proposed solution

Angular refactors existing pipes to use the Intl.* browser APIs. As this might lead to breaking changes, maybe it would make sense to offer them as an opt-in.

Angular could also consider adding new pipes based on the Intl APIs such as country, language, relativeTime, ..., as they should be relatively easy to implement and maintain.

Alternatives considered

Could also be solved by a community npm package. I'm currently developing one, feedback is very welcome!
https://github.com/json-derulo/angular-ecmascript-intl

@AndrewKushnir AndrewKushnir added the area: i18n Issues related to localization and internationalization label Feb 24, 2023
@ngbot ngbot bot added this to the needsTriage milestone Feb 24, 2023
@lana-white
Copy link

I agree. I find it ridiculous that I cannot dynamically load a LOCALE_ID and have to manually import it using @angular/common/locales/{localeId} as mentioned above. I do not require the locale data for translations, all I need this for is number, currency, percent and date pipe formatting. Why isn't there an option to just make the built in currency/number pipes to work without importing the whole locale package?? The local ID and currency code are both something I get from an API.

I have had to write my own custom pipes as well just using the Intl.* browser APIs as well.

Please allow for dynamic locales!!!

@JeanMeche
Copy link
Member
JeanMeche commented Sep 1, 2024

I'm closing this in favor of #54470, hoping we can land this in the next major.

@JeanMeche JeanMeche closed this as not planned Won't fix, can't repro, duplicate, stale Sep 1, 2024
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Oct 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: i18n Issues related to localization and internationalization breaking changes
Projects
None yet
Development

No branches or pull requests

4 participants
0