arabic plural forms for gettext

when translating software using gettext one has to pay attention to plurals, languages differ in how they treat singular and plural forms, gettext tries to be as accomodating as possible by allowing arbitirary rules for each language.

I suppose the rules of plural in arabic are well known enough and it is time we came up with a standard gettext expression to put as a header in all our po files.

different classes of numbers in arabic

  1. 0
  2. 1
  3. 2
  4. 3-10 + (100^n) : n >= 0
  5. 11-99 + (100^n) : n >= 0 or 1,2 + (100^n) : n >= 1
  6. 100^n : n >= 1

so how to express this lovely pattern in the C like expression needed for PO files?

nplurals = 6;
plural = n == 0 ? 0 :
         n == 1 ? 1 :

         n == 2 ? 2 :
         (n % 100 >= 3 && n % 100 <= 10) ? 3 :
         (n % 100 >= 11 && n % 100 <= 99) || (n % 100 == 1) || (n % 100 ==2) ? 4 :
         5;

pretty isn't it? time to review the whole language me thinks, anyways.

if you're using kbabel

  • go to settings -> configure kbabel
  • and make Number of singluar/plural forms equal 5
  • then in the GNU plural form header add the expression above

if you're not using kbabel you can edit the header manualy, open the po file in a text editor, find the plural form line and change it to look like this

"Plural-Forms: nplurals=6; plural=n==0 ? 0 : n==1 ? 1 : n==2 ? 2 : (n % 100 >=3 && n % 100 <=10) ? 3 : (n % 100 >=11 && n % 100 <=99) || (n % 100==1) || (n % 100==2) ? 4 : 5;\n"

example

  • 0 -> لا تعليقات
  • 1 -> تعليق واحد
  • 2 -> تعليقان
  • 3 -> تعليقات
  • 4 -> تعليقا
  • 5 -> ???

The cases are actually five, as zero and three-to-nine use the same form of plural, but since لا تعليقات has more meaning in Arabic than صفر تعليقات, I thought they could be separated.