amannn / next-intl

🌐 Internationalization (i18n) for Next.js
https://next-intl-docs.vercel.app
MIT License
2.58k stars 236 forks source link

Lazy-load intl-messageformat #1083

Closed EliasVal closed 5 months ago

EliasVal commented 5 months ago

Is your feature request related to a problem? Please describe.

While building my Next.js app, I noticed that intl-messageformat is taking up quite a bit of space.

page.tsx with useTranslations: image

page.tsx without useTranslations: image

Bundle analyzer result with useTranslaions: image

Describe the solution you'd like

Either have the option to somehow opt-out of formatting, or lazy-load it on the client.

Describe alternatives you've considered

Haven't looked into any other solutions.

amannn commented 5 months ago

Thanks you for the question! It's indeed planned to get rid of intl-messageformat on the client side, please see https://github.com/amannn/next-intl/issues/962.

For the time being, staying with translations within Server Components can be an alternative to avoid loading int-messageformat on the client side.

Hope this helps!

EliasVal commented 5 months ago

@amannn Thanks for the quick reply and the amazing work on the package! What's the progress on #705 ? (And as for your comment on an issue I posted a while back, the new option to opt out of the i18n routing works flawlessly!)

amannn commented 5 months ago

You can follow https://github.com/amannn/next-intl/pull/705 for the latest progress, but it's still a bit early. There are currently a few other priorities, but I'd like to get back to that PR as soon as I find the time. I can't really give an estimate currently, but the feature is rather months away I guess.

Since it's quite a change, there might be an opt-in experimental flag in the future to get feedback from early adopters. Might take a bit for the feature to stabilize, also icu-to-json that's mentioned in the PR is experimental at this point.

If you subscribe to the PR or the issue, I can keep you in the loop!

And as for your comment on an issue I posted a while back, the new option to opt out of the i18n routing works flawlessly!

Cool, that's nice to hear! 🙌