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

jsx-lexer: Don't extract a variable identifier in i18nKey as key

Open raine opened this issue 3 years ago • 2 comments
trafficstars

Why am I submitting this PR

Hello,

Updated to latest i18next-parser in our largeish project. There are few instances where we have <Trans> component with a variable as i18nKey for whatever reason. The latest i18next-parser started extracting those variables like so:

 <Trans
  i18nKey={titleTextKey}
  components={{
    rating_type: productRating,
  }}
/>

"titleTextKey": ""

Does not seem like the correct behavior for me hence the fix but please comment. Thanks!

Does it fix an existing ticket?

Not sure.

Checklist

  • [x] only relevant code is changed (make a diff before you submit the PR)
  • [x] tests are included and pass: yarn test (see details here)
  • [ ] documentation is changed or added

raine avatar Jan 17 '22 09:01 raine

Thanks for the PR. I believe a more consistent fix would be to throw a warning. You can see here and here.

Would you mind adding the warning and a test?

karellm avatar Jan 18 '22 02:01 karellm

@karellm Thanks for the input. How does it look now? https://github.com/i18next/i18next-parser/pull/506/commits/94536c82ed80eaf05e1f4bd6a8bf54378d1be6cb

raine avatar Jan 18 '22 11:01 raine