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

For <Trans> without key specified, and there is interpolation, the generated key incorrectly contains replacement tags

Open moopmonster opened this issue 5 years ago • 2 comments

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)?

moopmonster avatar Jul 24 '19 09:07 moopmonster

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.

cheton avatar Jul 25 '19 13:07 cheton

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

dzsodzso63 avatar Jan 20 '21 17:01 dzsodzso63