i18next-parser: reactNamespace doesn't support `useTranslation` hook
What I’m trying to do?
This code won’t evaluate useTranslation
hooks.
How am I doing it?
const { t } = useTranslation('home');
return <h1>{t(‘welcome’)}</h1>;
Here is my config file:
module.exports = {
contextSeparator: '_',
createOldCatalogs: true,
defaultNamespace: 't',
indentation: 2,
keepRemoved: false,
keySeparator: false,
namespaceSeparator: false,
lexers: {
js: ['JsxLexer'],
jsx: ['JsxLexer'],
default: ['JavascriptLexer']
},
lineEnding: 'auto',
locales: ['en', 'pt-br'],
output: './src/locales/$LOCALE/$NAMESPACE.json',
input: undefined,
reactNamespace: true,
sort: false,
useKeysAsDefaultValue: true,
verbose: false
};
The command I’m running:
i18next 'src/**/*.js' -c i18next-parser.config.js
What was the result?
t.json
"welcome”: "t__!NO_KEY_SEPARATOR!__welcome”,
What was I expecting?
home.json
"welcome”: "home__!NO_KEY_SEPARATOR!__welcome”,
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 2
- Comments: 29 (13 by maintainers)
Commits related to this issue
- fixes #161, correct regexp to extract namespace from withTranslation HOC — committed to Yuripetusko/i18next-parser by Yuripetusko 4 years ago
I’m currently running some tests. I’m also not sure about the necessity of this option
reactNamespace
altogether. It looks like it duplicate what is done here:https://github.com/i18next/i18next-parser/blob/master/src/lexers/javascript-lexer.js#L105
@luisrudge I’m curious why you set this option to true? You code doesn’t seem to rely on that feature at all. Do you need the
translate()
HOC as described in #69 ?@vincaslt It looks to me we can remove the
reactNamespace
option altogether.Why was this issue closed? The original issue by @luisrudge was about namespaces inside
useTranslation
, not about backtick support.useTranslation('home')
still doesn’t seem to work.Can I get a small code example that doesn’t work right that I could run tests on? From the code I can’t see that reactNamespace value has any effect on how namespace is extracted, so it’s weird.
I was running into the same problem. I would be interested in resolving the issue.
Got it, thanks for the clarification. PR is welcome!