babel-plugin-i18next-extract
babel-plugin-i18next-extract copied to clipboard
Ability to extract translations from objects
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 liket
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?
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 😊.
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.
That one comment really made my day 🥲. Thanks.