Skip to content

Duplicate PO entries when using gettext and plurals #2346

@garikkh

Description

@garikkh

Description

When using po-gettext and plural calls with identical strings, but different variables, it will create separate PO entries. These are technically invalid PO files since msgid should be unique.

Why isn't this a problem in the other PO formatter?

In the other PO formatter, msgid is the ICU string, which ends up being unique because the variable being used is there as well.

Verifications

  • I've checked the docs and this isn't covered there.
  • I've searched existing issues on GitHub.

Reproduction Steps

Run extract with plurals like this. In this example I have books and rocks, to showcase that the issue comes in basic strings as well as when you have placeholders like #.

<div>
  {plural(count, {
    one: "one book",
    other: "many books",
  })}
</div>
<div>
  {plural(anotherCount, {
    one: "one book",
    other: "many books",
  })}
</div>


<div>
  {plural(count, {
    one: "one rock",
    other: "# rocks",
  })}
</div>

<div>
  {plural(anotherCount, {
    one: "one rock",
    other: "# rocks",
  })}
</div>

Expected Behavior

Honestly, I'm not sure - but the resulting PO file for English looks like this:

#. js-lingui:icu=%7BanotherCount%2C+plural%2C+one+%7Bone+book%7D+other+%7Bmany+books%7D%7D&pluralize_on=anotherCount
#: src/App.tsx:68
msgid "one book"
msgid_plural "many books"
msgstr[0] "one book"
msgstr[1] "many books"

#. js-lingui:icu=%7BanotherCount%2C+plural%2C+one+%7Bone+rock%7D+other+%7B%23+rocks%7D%7D&pluralize_on=anotherCount
#: src/App.tsx:83
msgid "one rock"
msgid_plural "# rocks"
msgstr[0] "one rock"
msgstr[1] "# rocks"

#. js-lingui:icu=%7Bcount%2C+plural%2C+one+%7Bone+book%7D+other+%7Bmany+books%7D%7D&pluralize_on=count
#: src/App.tsx:61
msgid "one book"
msgid_plural "many books"
msgstr[0] "one book"
msgstr[1] "many books"

#. js-lingui:icu=%7Bcount%2C+plural%2C+one+%7Bone+rock%7D+other+%7B%23+rocks%7D%7D&pluralize_on=count
#: src/App.tsx:76
msgid "one rock"
msgid_plural "# rocks"
msgstr[0] "one rock"
msgstr[1] "# rocks"

IMO the compiler needs to be smart enough to combine if the ICU is identical except for variables. Since the extract/compile are in separate steps, this may be difficult.

Macro Support

Babel with babel-macro-plugin

Lingui Version

5.5.1

Babel Version

No response

Framework

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions