-
-
Notifications
You must be signed in to change notification settings - Fork 37
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
feat(unplugin-vue-i18n): allow for a custom i18n block transform hook #387
Conversation
@kazupon I would very much appreciate your feedback on this approach. Should I open an issue for this PR as well? Thanks for your consideration 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution!
That sounds good!
We need the docs for that option in the readme before you can merge your PR.
https://github.com/intlify/bundle-tools/tree/main/packages/unplugin-vue-i18n#-options
Could you put it to docs? 🙏
Excellent. I was out last week, I'll work on updating it this week! Thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! :)
I've just released v5.0.0-beta.4 |
Background
My organization has been using Vue i18n for over 6 years now and it has been invaluable to the project. We recently upgraded to Vue 3 and ran into an issue with the latest version if i18n and it's newest plugins.
Due to the size of our application we've had a custom loader that runs before the Vue i18n plugin in Webpack. This allows us at build time to fetch the translations and then replace the
<i18n>
blocks with the correct format.Reasoning
Due to the size of our application, we can't feasibly put all the translations into our components during development so we create the slugs and then the translations are entered into our CMS by our content team. We could put translations in json files in the repo - but then it requires content folks to edit via JSON files and know how to use git etc. The ability to edit in a CMS alongside all other content is a better DX for content teams and to make that work the plugin needs this type of async hook
Additionally, this method allows us to compartmentalize the translations in the
<i18n>
blocks and the translations are bundled with each component's respective chunk.Example of our workflow:
Before
After
This PR aims to allow the plugin to accept a custom transform function that will modify the source before the plugin parses the
i18n
block.This is only necessary because it appears we read the file from disk during build and I'm unsure on how to modify the file before it reaches the Vuei18n plugin. If there's a better way to handle this please let me know. Thanks for your consideration!
To Do