Today I learned about plural forms.
Before we go into the details, let’s start at the beginning: When building a product for an international user base – like we do, with our WordPress plugin picu – making sure that everything can be translated is essential. We have done that since day one and picu has been translated into various languages by our users and customers.
If this is completely new to you, and you would like to know more about how internationalization/translation for WordPress plugins work, start here.
Multiple plural forms
But a certain message wasn’t showing up as intended, even though he had seemingly translated everything already.
With a bit of back and forth, we found out it was a string with a plural form. Also, the string was only missing, if the number used in conjunction with that string was larger than 19. 🤔
After checking our code – not finding any clues of what might cause this – I downloaded and looked at the .po file containing the translations. I saw this:
Weirdly enough, there was more than one plural form showing up, which I had never seen before. This got me on the right track to learn more about plural forms! 💡
I have dabbled in a number of languages throughout my life: German, English, French, Chinese, Spanish and Turkish – but all of them know only two plural forms: singular and plural.
It turns out, there are many languages that use more than two plural forms. Romanian has a special case when the number ends in 00 or [2-9][0-9]. Arabic even knows six (!) different forms, with special cases for one, two, all numbers ending in 02, 03, … 10, all numbers ending in 11 … 99, and others. And there are many languages with other specific rules.
Now, on to the technical part:
In German the plural forms are defined like this:
nplurals=2; plural=(n != 1);
Pretty straight forward:
nplurals=2means: There are two plurals, the singular form and the plural form
plural=(n != 1)means: If the number is not 1, use the plural form, otherwise use the singular form
In Turkish it works pretty much the same way, even though the definition is slightly different:
nplurals=2; plural=(n > 1);
plural=(n > 1)means: Use the plural form when the number is larger than 1.
Quite interesting, no?
So, getting back to our inital support request: As we learned above, Romanian has three plural forms. The definition looks like this:
nplurals=3; plural=(n==1 ? 0 : (n==0 || (n%100 > 0 && n%100 < 20)) ? 1 : 2);
And, as another example, for Arabic the definition looks like this:
nplurals=6; plural=(n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : n%100>=3 && n%100<=10 ? 3 : n%100>=11 ? 4 : 5);
Head over to gnu.org’s page about gettext and plural forms to learn (much) more about languages and their plural forms.
Unfortunately – in our case – in Loco Translate the options are presented like you can see in the following screenshot. It is not as obvious as in PoEdit’s UI, seen above, and quite possibly the reason why Marius overlooked it, when translating.
Turns out, if the translation for the respective plural form is missing, nothing will be displayed. After we added the translation for the third plural form in Romanian, everything was working as expected.
Needless to say, Marius was very happy when presented with the solution. Case closed! Plus: We learned something new. 😊
Hopefully this post will help someone else out there who’s running into a similar problem.