gilbsgilbs / babel-plugin-i18next-extract

Babel plugin that statically extracts i18next and react-i18next translation keys.
https://i18next-extract.netlify.com
MIT License
159 stars 37 forks source link

Ability to extract plurals from defaultValues #207

Open janis-github opened 2 years ago

janis-github commented 2 years ago

Is your feature request related to a problem? Please describe.

Currently this excellent plugin supports only the one basic form of default value: "defaultValue". i18next supports a buch of suffixes for defaultValue: https://www.i18next.com/translation-function/essentials#overview-options That would allow to maintain the default locale translations file be 100% generated from the source.

Similar approach could apply to contexts as well.

Describe the solution you'd like

It would be very nice if I could do something like this in code:

t("key", {
  defaultValue_zero: "no data",
  defaultValue_one: "One",
  defaultValue_other: "many",
  count: myCount
})

And it would produce:

{
  key_zero: "no data",
  key_one: "One",
  key_other: "many",
}

Describe alternatives you've considered

Now, there are two options (both suboptimal): 1) Add plurals manually to the translations file. 2) Do the pluralization in source.

Additional context

I'd be happy to do PR if someone could guide which parts should be changed. One thing I found I could do is make parseTCallOptions return the extracted defaults but not sure how to integrate them with the rest of the code.

janis-github commented 2 years ago

Just noticed the #167 which asks for the same feature...