i18next-scanner
i18next-scanner copied to clipboard
For <Trans> without key specified, and there is interpolation, the generated key incorrectly contains replacement tags
Version
- i18next: 17.0.6
- i18next-scanner: 2.10.2
- react-i18next : 10.11.4
Configuration
{
debug: "true",
lngs: ["en"],
attr: false,
func: {
extensions: [".js"],
list: ["t", "props.t", "i18n.t"],
},
trans: {
extensions: [".js"],
fallbackKey: true,
},
keySeparator: false,
nsSeparator: false,
}
When the <Trans> component is used without specifying a key, and there is interpolation, the {{variables}} end up having replacement tags and i18next is unable to find the translation key.
<Trans>My name is {{name}}</Trans>
a) Key that works :
{ "My name is {{name}}" : "Mein name ist {{name}}" }
b) Generated key that does not work, I think due to replacement tag <1></1>:
{ "My name is <1>{{name}}</1>" : "Mein name ist <1>{{name}}</1>" }
Here is the codesandbox : https://codesandbox.io/s/restless-bush-il5nq?fontsize=14
Thank you. If this is not a bug, perhaps I may be missing some configuration on the application side to get i18next to be able to pick up b)?
It is probably related to https://github.com/i18next/i18next-scanner/issues/125#issuecomment-474678819 and https://github.com/i18next/react-i18next/blob/master/CHANGELOG.md#800.
You can apply the workaround temporarily, I will make the change for react-i18next v8 (or later versions) in a future release.
Is this still on the roadmap? (the referred workaround is not that robust, and quite hacky...) I'd say that this is basically a bug about supporting react-i18next >v8