openlibrary icon indicating copy to clipboard operation
openlibrary copied to clipboard

Arabic (ar) pluralization incorrect in message file

Open tfmorris opened this issue 7 months ago • 4 comments

Problem

A native Arabic speaker should verify this, but the current declaration of Plural-forms appears incorrect for Arabic and it should be six forms, not three, per https://github.com/ergenius/gettext-po-samples/blob/596e24c081dd88cf4644dd4d11ff90de1814daad/po/ar.po#L13 and some other Internet references.

The canonical CLDR definition is here: https://www.unicode.org/cldr/charts/48/supplemental/language_plural_rules.html#ar

The current declaration is: https://github.com/internetarchive/openlibrary/blob/4f4def6691ac3fda9b747f1775613812f5b1d53b/openlibrary/i18n/ar/messages.po#L15

and should instead be:

"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) ? 4 : 5)))));\n"

Reproducing the bug

  1. Go to ...
  2. Do ...
  • Expected behavior:
  • Actual behavior:

Context

  • Browser (Chrome, Safari, Firefox, etc):
  • OS (Windows, Mac, etc):
  • Logged in (Y/N):
  • Environment (prod, dev, local): prod

Breakdown

Implementation Details (for maintainers)

Requirements Checklist

  • [ ]

Related files

Stakeholders


Instructions for Contributors

  • Please run these commands to ensure your repository is up to date before creating a new branch to work on this issue and each time after pushing code to Github, because the pre-commit bot may add commits to your PRs upstream.

tfmorris avatar Apr 28 '26 18:04 tfmorris

[!WARNING] I have absolutely no context, though sharing a response from claude in case it is of any help to someone trying to solve this i18n issue:

Opinion on Arabic Plural-Forms in OpenLibrary

Yes, the proposed change is correct. Here's my assessment with high confidence:

The fix is right

Arabic genuinely has six plural forms in the Unicode CLDR / gettext convention, not three:

  • 0: zero (e.g., "0 كتاب")
  • 1: one (singular, "كتاب واحد")
  • 2: two (dual form, "كتابان" — Arabic has a distinct grammatical dual)
  • 3: few (3–10, "3 كتب" uses the plural of paucity)
  • 4: many (11–99, takes singular accusative: "11 كتاباً")
  • 5: other (100, 101, 102… — back to singular form)

The dual is the key tell that three forms is wrong. Arabic morphology distinguishes singular, dual, and plural as separate grammatical numbers, and the plural itself splits into "plural of paucity" (3–10) versus larger counts, with 11–99 grammatically requiring a singular noun in the accusative. A three-form rule (like nplurals=3; plural=(n==0 ? 0 : n==1 ? 1 : 2)) collapses all of that and produces grammatically wrong strings for any count ≥ 2.

The exact formula proposed

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) ? 4 : 5)))));

This matches the canonical gettext/CLDR rule for Arabic and is what you'll find in GNU gettext's documentation and most major i18n projects (Mozilla, Translate Toolkit, Drupal, etc.). It's correct as written.

One caveat worth flagging in the PR

Changing nplurals from 3 to 6 is a breaking change for the .po file's msgstr arrays. Every existing pluralized message in ar/messages.po currently has three msgstr[0] / msgstr[1] / msgstr[2] entries. After the header change, every plural entry needs six slots (msgstr[0] through msgstr[5]), and the existing translations need to be remapped:

  • old [0] (was n==0) → new [0]
  • old [1] (was n==1) → new [1]
  • old [2] (was everything else) → needs to be split across new [2], [3], [4], [5], ideally by a native speaker

If you only update the header without expanding the msgstr arrays, msgfmt will either error out or silently fall back to msgstr[0] for the missing indexes, which is worse than the status quo. So the issue is correctly diagnosed but the fix is a two-part job: header + reflow all plural entries (and probably a translator pass to fill in the new dual / few / many forms properly).

That's worth calling out in the issue thread before someone opens a one-line PR that breaks the build.

mekarpeles avatar May 02 '26 04:05 mekarpeles

I'm not sure what the formula should look like programmatically but I'm a native arabic speaker (lebanese dialect) and below are my comments on what Claude hallucinated: ( (k-i-t-a-b) كتاب means book by the way. )

0: zero (e.g., "0 كتاب") - no, there is no zero form. 1: one (singular, "كتاب واحد") - this is correct 2: two (dual form, "كتابان" — Arabic has a distinct grammatical dual) - also correct 3: few (3–10, "3 كتب" uses the plural of paucity) 3-99 is the "many form" when counting a number of object. for example ,"3 كتب" - almost correct 4: many (11–99, takes singular accusative: "11 كتاباً") - this is completely wrong 5: other (100, 101, 102… — back to singular form) - "100 كتاب" - kinda....

so the correct number of plural forms in my opinion should be: 1: one (singular, "كتاب") (k-i-t-a-b) 2: two (dual form, "كتابان" — Arabic has a distinct grammatical dual) (k-i-t-a-b-a-n) 3: many (3–99, "3 كتب") (k-o-t-o-b) 4: more than 100+ (back to singular form, "100 كتاب") (k-i-t-a-b)

If you want to say books in general you say "كتب" (k-o-t-o-b)

Then you have to consider the numbers' gender when counting, that will add a few more forms for the numbers 3-11 and some numbers over 100. Here is a better explanation about that: https://thearabicpages.com/2021/08/02/the-grammar-of-using-arabic-numbers/

Below is a quote from a wikipedia article about Grammatical number but I'm 90% sure that that is only dialect specific and does not apply to standard arabic. (https://en.wikipedia.org/wiki/Grammatical_number) "Some dialects of Arabic have a few nouns that exhibit a five-way distinction of general, singulative, dual, plurative, and greater plural. In Damascus Arabic:[190]

dəbbān – "fly/flies" (general)
dəbbāne – "fly" (singulative)
dəbbāntēn – "two flies" (dual)
dəbbānāt – "flies" (plurative)
dababīn – "many flies" (greater plural)"

Hope this is in any way helpful.

AmandaElRayes avatar Jun 02 '26 18:06 AmandaElRayes

Hi @cdrini and @mekarpeles! I'd like to work on this issue.

My understanding of the fix: The Arabic messages.po file currently declares only 3 plural forms, but Arabic requires 6 per the Unicode CLDR standard. The fix is to update the Plural-Forms header in openlibrary/i18n/ar/messages.po to:

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) ? 4 : 5)))));

This aligns with the CLDR definition and the pattern referenced in the issue.

Could I be assigned to this issue? Thank you!

joannajiang711 avatar Jun 08 '26 21:06 joannajiang711

@joannajiang711 feel free to open a PR though better to check-in on approach earlier rather than later (as you are doing) so @cdrini can offer feedback. You're doing the right thing!

mekarpeles avatar Aug 04 '26 03:08 mekarpeles