nuxt-modules / i18n

I18n module for Nuxt
https://i18n.nuxtjs.org
MIT License
1.7k stars 474 forks source link

Tree shake messages #2859

Open GalacticHypernova opened 5 months ago

GalacticHypernova commented 5 months ago

Describe the feature

In an app with a lot of translatable content importing the whole language file, even if lazily, will introduce huge network overhead, and most of the time would even be unnecessary, as there will likely be a slight portion of the messages in use for every page. Furthermore, it could introduce data leaks, the most notable example being admin pages having their translation sent to the client. Tree shaking the messages will ensure there is minimal overhead and minimal data sent to the client, which will not compromise data integrity and still allow to use lazy loading as much as possible.

Additional information

Final checks

GalacticHypernova commented 3 months ago

@BobbieGoede I have an idea that could potentially make this work. How about handling the conversion of the message files to a JS file with certain exports, and then using them in the files? That way the bundler could take care of the code splitting, and since some exports won't be used, the will not be included.