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

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

Open
paulschreiber opened this issue Sep 10, 2024 · 1 comment

Comments

@paulschreiber
Copy link

paulschreiber commented Sep 10, 2024

🐛 Bug Report

I am not sure if this:

  • a bug in i18next-conv
  • a bug in i18next
  • expected behaviour

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

  • runtime version: node v20.13.1
  • i18next version: i18next-conv 15.0.0
  • os: macOS 14.6.1
@paulschreiber paulschreiber changed the title When converting from JSON to PO, all underscores are treated as plurals When converting from JSON to PO, all underscores are treated as plurals or context Sep 10, 2024
@paulschreiber
Copy link
Author

I was able to work around this with these options:

  ctxSeparator: '',
  compatibilityJSON: 'v4',

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

No branches or pull requests

1 participant