i18next-scanner icon indicating copy to clipboard operation
i18next-scanner copied to clipboard

Handle namespaces automatically

Open bboure opened this issue 4 years ago • 4 comments

🚀 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

bboure avatar Jun 29 '20 07:06 bboure

You can find a workaround in the meantime here: https://github.com/i18next/i18next-scanner/issues/142#issuecomment-610640269

montogeek avatar Jun 29 '20 08:06 montogeek

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.

bboure avatar Jun 29 '20 18:06 bboure

No workaround found?

DannyvanHolten avatar Dec 14 '21 23:12 DannyvanHolten

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

pigareva avatar Feb 17 '22 11:02 pigareva