babel-plugin-i18next-extract icon indicating copy to clipboard operation
babel-plugin-i18next-extract copied to clipboard

Ability to extract translations from objects

Open eric-burel opened this issue 2 years ago • 3 comments

This PR brings an improvement to the "variable keys" scenarion (https://i18next-extract.netlify.app/#/faq?id=how-to-deal-with-variable-keys).

It lets you define object keys that will systematically be considered as i18n token. It works exactly like a t function call, with custom names for the function, but using an object field instead.

Limitations:

  • it still throws a warning when you call the "t" function with the variable afterward const myItem = { i18nToken: "foobar" }; t(myItem.i18nToken); // will trigger a false positive warning
  • it only supports the most basic scenario, of having just a key. So { i18nToken: "foobar"} is supported but not { i18nToken: ["foobar", { someValue: 42 } ]. It could be easily extended by considering the token value exactly like t function arguments but I am not familiar enough with both i18n and this plugin.
  • not sure if I am traversing the tree right. There might be slightly more performance alternatives to visit fields?

eric-burel avatar Aug 12 '21 09:08 eric-burel

Hey thanks for the PR. I'll look into it in ~2 weeks as I'm currently on vacation. Please remind me if I forget 😊.

gilbsgilbs avatar Aug 12 '21 09:08 gilbsgilbs

Enjoy the vacations! And thanks for this package in the first place, the contributor experience is outstanding given how complex a Babel plugin can be, the testing in particular is great.

eric-burel avatar Aug 12 '21 09:08 eric-burel

That one comment really made my day 🥲. Thanks.

gilbsgilbs avatar Aug 12 '21 20:08 gilbsgilbs