Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ability to extract translations from objects #198

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

eric-burel
Copy link

@eric-burel eric-burel commented Aug 12, 2021

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?

@gilbsgilbs
Copy link
Owner

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 😊.

@eric-burel
Copy link
Author

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.

@gilbsgilbs
Copy link
Owner

gilbsgilbs commented Aug 12, 2021

That one comment really made my day 🥲. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants