elixir-gettext / gettext

Internationalization and localization support for Elixir.
https://hexdocs.pm/gettext
461 stars 87 forks source link

`expo.msguniq` merges translations with different plurals #384

Closed alexanderttalvarez closed 9 months ago

alexanderttalvarez commented 9 months ago

In version 0.24.0, the expo.msguniq command is merging translations with different plurals. For example, let's consider the following case:

msgid "1 review"
msgid_plural "%{reviews_count} of %{reviews_total} reviews"
msgstr[0] "1 opinión"
msgstr[1] "%{reviews_count} de %{reviews_total} opiniones"

msgid "1 review"
msgid_plural "%{reviews_showing} reviews of %{reviews_total}"
msgstr[0] "1 opinión"
msgstr[1] "%{reviews_showing} opinones sobre %{reviews_total}"

After using the command, it generates:

msgid "1 review"
msgid_plural "%{reviews_total} reviews"
msgstr[0] "1 opinión"
msgstr[1] "%{reviews_total} opiniones"

We are losing one translation.

It's not possible to use mix gettext.extract either. It produces an error: found duplicate on line 169 for msgid: '1 review' and msgid_plural: '%{reviews_count} of %{reviews_total} reviews'

Which is not true, because the plurals are different. Only the msgid is the same.

Is that a bug? Thanks.

maennchen commented 9 months ago

This behavior is intentional.

Until recently (#379) this library behaved wrong and looked at it as distinct translations. Unfortunately that is not how GNU gettext defines it to work.

Now the msgid has to be unique.

You can verify this the following way:

test.po

msgid ""
msgstr ""
"Project-Id-Version: POEdit test project\n"
"POT-Creation-Date: \n"
"PO-Revision-Date: \n"
"Last-Translator: Meg Buque\n"
"Language-Team: Elixir <dummy@example.com>\n"
"Language: it\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 1.7.6\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Poedit-SourceCharset: UTF-8\n"

msgid "1 review"
msgid_plural "%{reviews_count} of %{reviews_total} reviews"
msgstr[0] "1 opinión"
msgstr[1] "%{reviews_count} de %{reviews_total} opiniones"

msgid "1 review"
msgid_plural "%{reviews_showing} reviews of %{reviews_total}"
msgstr[0] "1 opinión"
msgstr[1] "%{reviews_showing} opinones sobre %{reviews_total}"
msguniq test.po                                                                                                                                                                                                                                (⎈ |gke_sustema-operations-apps_europe-west6-a_apps-cluster:default)
msgid ""
msgstr ""
"Project-Id-Version: POEdit test project\n"
"POT-Creation-Date: \n"
"PO-Revision-Date: \n"
"Last-Translator: Meg Buque\n"
"Language-Team: Elixir <dummy@example.com>\n"
"Language: it\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 1.7.6\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"X-Poedit-SourceCharset: UTF-8\n"

#, fuzzy
msgid "1 review"
msgid_plural "%{reviews_count} of %{reviews_total} reviews"
msgstr[0] ""
"#-#-#-#-#  test.po (POEdit test project)  #-#-#-#-#\n"
"1 opinión\n"
"#-#-#-#-#  test.po (POEdit test project)  #-#-#-#-#\n"
"1 opinión"
msgstr[1] ""
"#-#-#-#-#  test.po (POEdit test project)  #-#-#-#-#\n"
"%{reviews_count} de %{reviews_total} opiniones\n"
"#-#-#-#-#  test.po (POEdit test project)  #-#-#-#-#\n"
"%{reviews_showing} opinones sobre %{reviews_total}"

(Note that only one message is left.)

To work around this, you'll have to work with the msgctxt or a different domain.

maennchen commented 9 months ago

@whatyouhide I'm temporarily pining this issue since more people could stumble upon this when updating.

whatyouhide commented 9 months ago

@maennchen yeah it sounds good. Thanks for giving @alexanderttalvarez context here, great job 🙃

alexanderttalvarez commented 9 months ago

Ok, I understand now. Thanks for your explanation 😃. We'll have to find a way to addapt our translations.

I'm closing the issue then.