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

Ability to extract plurals from defaultValues

Open janis-github opened this issue 3 years ago • 1 comments

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 avatar Mar 01 '22 09:03 janis-github

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

janis-github avatar Mar 01 '22 10:03 janis-github