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
Translations are loaded for all layers to the client #2817
Comments
This is expected behaviour, all locale files are loaded and merged, this could be beneficial for locales sharing locale files (fewer and smaller requests). I might add functionality that merges all locale files per locale during the build step but this would only be possible if all files are static (as is the case in your reproduction). |
This is a problem, the final bundle should not have |
I think it should have a |
While this functionality could be improved, this behaviour is not a bug and is working as documented. I understand that this may be a deal breaker in your specific use case but it won't be prioritized/labeled the same as a bug. Maybe it's possible to workaround this issue by merging the files yourself at build time and filtering out the other locale files, of course if you have good ideas on how to implement this in the module itself we always welcome contributions. |
Sure, I will try fix it.
Then it's a fundamental design problem. Loading translations from all layers and merging them should not happen on the client.
It is a deal breaker for any big project that use layers. |
Do keep in mind that we also support dynamic locale files that could be fetching translations from a remote source at runtime. |
How does this affect merging local translation files? :) |
If translations are fetched from a remote source these remote sources could provide different translations at runtime, any layer can provide static and dynamic locale files in any order, merging those at build time wouldn't necessarily be desirable as translations could be added or removed at any point. I agree that it would be nice to merge all static locale files at build time, just pointing out that some users rely on the behaviour that you find a deal breaker. There are probably also projects that would prefer fetching the remote translations at build time, turning these static and merging it all, but that's not the current functionality. |
What do you mean by "translations could be added or removed at any point"? |
An example would be that some users use a headless CMS to provide translations, the dynamic locale files fetch these translations at runtime. If a translation from a dynamic locale resource at the beginning of the merge order is no longer present it should be removed from the final merged result unless overwritten, if a translation from a dynamic locale resource is added and at the end of the merge order it should be added and overwrites previous translations with the same keys in the final merged result. These projects don't want to rebuild their project whenever their translations change, which may not be performant but it is a valid use case all the same. |
Environment
Reproduction
https://stackblitz.com/edit/bobbiegoede-nuxt-i18n-starter-qj9tuc
Describe the bug
npm preview
You will see that the translations from all layers have been loaded.
Only 1 file with merged translations should be loaded.
Additional context
Logs
No response
The text was updated successfully, but these errors were encountered: