You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think it is more a question than a bug. I installed then plugin and it is working well. In my case, I work on a big project and we use constants for i18n keys.
How to reproduce
I Have a file constants.js containing: const COMMON = { save: 'common-save', cancel: 'common-cancel', }
In my app.js, I do: t(COMMON.save);
I get the error "Couldn't evaluate i18next key. You should either make the key evaluable or skip the line using a skip comment...".
The FAQ already mentions that this is not supported and probably never will, but feel free to submit a PR if you think this isn't clear enough.
This is a babel plugin, therefore it can only perform static analysis. Resolving variables or symbols across modules might be doable in some very simple cases, yet babel is definitely not a good fit for such scenario. It might be possible, but it would add so much complexity and maintenance burden and hacks that it wouldn't be worth it.
I'm afraid you'll have to move away from variable keys if you want to use a static tool. Sorry. By the way, I don't think comment hints would be of any help in this case.
Describe the bug
Hi,
I think it is more a question than a bug. I installed then plugin and it is working well. In my case, I work on a big project and we use constants for i18n keys.
How to reproduce
I Have a file constants.js containing:
const COMMON = { save: 'common-save', cancel: 'common-cancel', }
In my app.js, I do:
t(COMMON.save);
I get the error "Couldn't evaluate i18next key. You should either make the key evaluable or skip the line using a skip comment...".
If I use
t('common-save')
, it works fine.Babel configuration:
"babel": { "presets": [ "react-app" ], "plugins": [ "@babel/plugin-proposal-optional-chaining", [ "@babel/plugin-proposal-decorators", { "legacy": true } ], "syntax-dynamic-import", [ "babel-plugin-styled-components", { "ssr": false, "displayName": true, "fileName": false, "minify": true, "pure": false, "transpileTemplateLiterals": false } ], "lodash", "inline-react-svg", [ "i18next-extract", { "nsSeparator": "-", "keySeparator": ".", "outputPath": "public/locales/{{locale}}/{{ns}}.json" } ] ] }
Expected behavior
I expect to the plugin is able to resolve constants.
Is it a way to use constants with the plugin? (without adding a comments everywhere).
Your environment
Thanks! Good work for this plugin!
The text was updated successfully, but these errors were encountered: