i18next-scanner
i18next-scanner copied to clipboard
Handle namespaces automatically
🚀 Feature Proposal
Allow the scanner to automatically detect and generate the namespaces automatically, without needing to specify them in the ns
option.
Motivation
I have a (react-native) project with many namespaces. Basically, one per page/screen. That makes it cumbersome to have to update manually and list all the namespaces in the ns
option.
If I forget one, I get the error *** does not exist in the namespaces ***
. While this error is useful to identify the issue, it is still not ideal to have to add the namespaces manually since I have dozens of them.
Ideally, I would just like to pass an option to ns
(maybe false
) so that the plugin will just go ahead and generate any {{lng}}/{{ns}}.json
file I need, based on the usage.
Example
const [t] = useTranslate('myNamespace');
return <Text>{t('hello')}</Text>;
If myNamespace
exists (the file exists), it should just add the hello
key to it.
If not, it should create the file.
All this without the need to have to add myNamespace
anywhere in the options.
Thank you
You can find a workaround in the meantime here: https://github.com/i18next/i18next-scanner/issues/142#issuecomment-610640269
Thanks @montogeek but this is a different issue. I am using that solution along with useTranslation()
and it works great. However, I just want to avoid to have to specify manually all the namespaces in the scanner config. That should just be automatic with usage from the code.
No workaround found?
Unfortunately not, https://github.com/i18next/i18next-scanner/issues/142#issuecomment-610640269 - is not the same. It is about to use the first namespace from useTranslation
as a default namespace