lokalise / i18n-ally-jetbrains-docs

6 stars 4 forks source link

Support for scoped namespace in a JS/TS file #48

Open aranard opened 9 months ago

aranard commented 9 months ago

When using react-i18next, the useTranslation() hook can accept one or more namespaces, where the first namespace becomes the default scope for the current file.

For example, this is valid syntax:

const { t } = useTranslation('ns1');
t('key'); // finds key from ns1

and this is as well:

const { t } = useTranslation(['ns1', 'ns2']);
t('key'); // finds key from ns1
t('ns1:key'); // finds key from ns1
t('ns2:key2'); // finds key from ns2

Is there some way to recreate this behavior of having a default scoped namespace with the Jetbrains plugin? I've only had partial success with defining a template as t('%namespace%:%key%', %map%), which then means the plugin expects %namespace% is always provided (which as you can see above, is not necessary in react-i18next).

Taking it a step farther, if it were possible to do the above - I'd also like to be able to define a custom scope (rather than react-i18next's useTranslation function) that would add parity with this feature I contributed to the VS Code extension.

Thanks!