Plume icon indicating copy to clipboard operation
Plume copied to clipboard

i18n: when 0 likes or reshare displaied, translations says "One"

Open floreal opened this issue 5 years ago • 11 comments
trafficstars

An Image worth more than a description: image See templates/posts/details.rs.html#L82

  • Plume version: master

  • Operating system: Linux

  • Web Browser: Firefox

floreal avatar Apr 11 '20 18:04 floreal

Can you try with another language than french to see if you can reproduce? Because it seems to work fine in English. So maybe the issue is more with the French translation.

elegaanz avatar Apr 12 '20 15:04 elegaanz

image

As i can see here are the entries in the translation files:

en.po:

msgid "One like"
msgid_plural "{0} likes"
msgstr[0] ""
msgstr[1] ""

fr.po:

msgid "One like"
msgid_plural "{0} likes"
msgstr[0] "Un like"
msgstr[1] "{0} likes"

where does macro i18n!() comes from ?

floreal avatar Apr 13 '20 12:04 floreal

We wrote i18n for Plume, it comes from the gettext-macros crate: https://github.com/Plume-org/gettext-macros/blob/main/src/lib.rs#L462

And judging by what I see, it is more an issue with the "Plural-Forms" header in the fr.po file, that is either incorrect, or not parsed correctly by the Rust gettext implementation…

elegaanz avatar Apr 13 '20 12:04 elegaanz

Unfortunately, Plural-Forms settings was overwritten...

% rg Plural-Forms ~/host/Downloads/fr.po
13:"Plural-Forms: nplurals=2; plural=(n > 1);\n"

KitaitiMakoto avatar Apr 30 '20 13:04 KitaitiMakoto

Noooooo!

Then there are two solutions I can see:

  • editing this .po file in build.rs ouselves, at every compilation.
  • signaling the issue to Crowdin so that they can fix it.

And they are not mutually exclusive, we can do both.

elegaanz avatar Apr 30 '20 14:04 elegaanz

Actually Crowdin is right about french using plurals for n > 1. Zero is singular in french, which means the correct translations would be msgstr[0] "{0} like" which means losing the all letters "Un"

trinity-1686a avatar May 02 '20 04:05 trinity-1686a

Oh, really? Thank you for important information.

KitaitiMakoto avatar May 02 '20 04:05 KitaitiMakoto

Actually Crowdin is right about french using plurals for n > 1. Zero is singular in french, which means the correct translations would be msgstr[0] "{0} like" which means losing the all letters "Un"

I feel stupid right now, for not noticing it before… :sweat_smile:

elegaanz avatar May 02 '20 10:05 elegaanz

Would it work with that?

msgid "One like"
msgid_plural "{0} likes"
msgstr[0] "Aucun like"
msgstr[1] "Un likes"

floreal avatar May 03 '20 11:05 floreal

Maybe, because the header says nplurals=2, so there may be two different plurals for French if I read this correctly

elegaanz avatar May 03 '20 12:05 elegaanz

nplurals count how many variations there are, including singular, 2 is 1 singular plus 1 plural. @floreal your proposition would not work :

  • if like > 1 it returns "Un likes"
  • else (so if likes ⩽1) it returns "Aucun like".

If we want to have "Aucun", "Un" or any number, there have to be 3 plurals (not that it requires changing all other french translation strings to have the same number of variations, and there is still the problem about Crowdin overwriting Plural-Forms):

"Plural-Forms: nplurals=3; plural=(n > 1 ? 2 : n);\n"

msgid "One like"
msgid_plural "{0} likes"
msgstr[0] "Aucun like"
msgstr[1] "Un like"
msgstr[2] "{0} likes"

(Not so) Short explanation of how plurals works in gettext : nplurals describes how many variations there are. If its, say, 5, there are 5 variations, so each translations requieres to have msgstr[0] to msgstr[4].
plural is the formula that gives what msgstr has to be used, it must returns an integer < nplurals. For most languages it can be n != 1 or n > 1 as they have only 1 plural (and 1 singular), false would be considered as 0, and true as 1 (as usually done in C). For more complex plural forms, one can use <inequality> ? <if it was true> : <if it was false> formula, like a C inline if statement. Imbrication is possible as many as you want (see Russian version for how complex it can get). I'll name res what was returned by the formula
msgstr[res] is chosen as the correct translation, based on the return value of plural.

trinity-1686a avatar May 03 '20 17:05 trinity-1686a