英文:
Access to the same I18nContext from bundled components
问题
我尝试使用useTranslation钩子来访问捆绑组件内的i18n实例,但我收到了undefined。我期望收到i18n实例对象。
英文:
as mentioned in the title, I have a bundled UI kit and I would like to enable translation within the UI kit, as some of its molecule components require translations. I have tried to use the useTranslation hook to access the i18n config object, but it returns undefined. I also attempted to include it as an external in my ViteJS bundler, but I still get undefined i18n. I would like to ask if anyone else has had the same requirements and how they were able to achieve this. Thank you very much.
I tried using the useTranslation hook to access the i18n instance inside bundled components, but I received undefined. I'm expecting to receive the i18n instance object.
答案1
得分: 1
I was testing my UI-kit with the yarn link
command, which links the node_modules
folder into my main project. This created two react-i18next
Provider instances which prevented the bundled code from accessing the main Provider.
To resolve my issues, I used yalc
to install my package locally. Unlike yarn/npm
, yalc only copies the files specified in package.json
, instead of symlinking all the folders.
For everyone who has the same issue even when using yalc on a local environment, check if the react-i18next
entry is included in the bundler's externals.
英文:
I was testing my UI-kit with the yarn link
command, which links the node_modules
folder into my main project. This created two react-i18next
Provider instances which prevented the bundled code from accessing the main Provider.
To resolve my issues, I used yalc
to install my package locally. Unlike yarn/npm
, yalc only copies the files specified in package.json
, instead of symlinking all the folders.
For everyone have the same issue even using yalc on local environment. Control if react-i18next entry is put on bundler externals
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论