i18next / i18next-gettext-converter

converts gettext .mo or .po to 18next json format and vice versa
MIT License
196 stars 56 forks source link

When converting from JSON to PO, all underscores are treated as plurals or context #335

Open paulschreiber opened 2 months ago

paulschreiber commented 2 months ago

🐛 Bug Report

I am not sure if this:

When converting from JSON to PO, all underscores are treated as plurals.

To Reproduce

If we have some JSON like this:

{
  "welcome": {
    "title": "hello",
    "hello_world": "yay",
    "sample_one": "{{count}} shoe",
    "sample_other": "{{count}} shoes"
  },
  "soil": {
    "bedrock": "Bedrock",
    "rock_fragment": {
      "VOLUME_0_1": "0–1%",
      "VOLUME_1_60": "35–60%",
      "VOLUME_60": ">60%"
    }
  }
}

It converts to PO like this:

msgctxt "0"
msgid "soil##rock##VOLUME"
msgstr "0–1%"

msgctxt "1"
msgid "soil##rock##VOLUME"
msgid_plural "soil##rock##VOLUME"
msgstr[0] ""
msgstr[1] "35–60%"

msgid "welcome##title"
msgstr "hello"

msgid "soil##bedrock"
msgstr "Bedrock"

msgid "soil##rock##VOLUME"
msgid_plural "soil##rock##VOLUME"
msgstr[0] ""
msgstr[1] ">60%"

msgctxt "world"
msgid "welcome##hello"
msgstr "yay"

msgctxt "one"
msgid "welcome##sample"
msgstr "{{count}} shoe"

msgctxt "other"
msgid "welcome##sample"
msgstr "{{count}} shoes"
i18next-conv i18next-conv  -l en -s en.json -t en.po

If this is expected bahviour, is there a way to get the behaviour I describe? I noted this option

.option('-P, --plurals <path>', 'Specify path to plural forms definitions')

But can't find an example of what that file should look like or how it behaves.

Expected behavior

Only keys ending in _one and _other are treated as plurals

resulting in po like this:

msgid "soil##rock_fragment##VOLUME_0_1"
msgstr "0–1%"

msgid "soil##rock_fragment##VOLUME_35_60"
msgstr[1] "35–60%"

msgid "soil##rock_fragment##VOLUME_60"
msgstr[1] ">60%"

msgid "welcome##title"
msgstr "hello"

msgid "soil##bedrock"
msgstr "Bedrock"

msgid "welcome##hello_world"
msgstr "yay"

msgctxt "one"
msgid "welcome##sample"
msgstr "{{count}} shoe"

msgctxt "other"
msgid "welcome##sample"
msgstr "{{count}} shoes"

Your Environment

paulschreiber commented 2 months ago

I was able to work around this with these options:

  ctxSeparator: '',
  compatibilityJSON: 'v4',