Fix Arabic plural rule to match CLDR (#816)#1289
Open
apoorvdarshan wants to merge 1 commit into
Open
Conversation
The hand-maintained rule in babel/messages/plurals.py had the "many" (form 4) and "other" (form 5) categories swapped relative to CLDR, so generated Arabic catalogs selected the wrong plural for any n whose n%100 is in 11..99 (e.g. 11, 50, 99, 111). Align it with the CLDR-derived rule that Babel already ships.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #816.
Problem
babel/messages/plurals.pykeeps a hand-maintained table of gettextPlural-Formsrules. Its Arabic (ar) rule has the "many" (form 4) and "other" (form 5) categories swapped relative to Unicode CLDR:CLDR assigns many to
n % 100in11..99and other to the rest, but the table assigns form 4 ton % 100in0..2instead. As a result, generated Arabic catalogs pick the wrong plural for anynwhosen % 100is 11–99 (e.g. 11, 50, 99, 111, 999). This also disagrees with the CLDR-derived rule that Babel itself ships (Locale('ar').plural_form).Fix
One line — align the rule with CLDR:
This matches the standard gettext Arabic
Plural-Formsused by Weblate/Transifex.Testing
test_get_plural_arabic, which asserts the corrected expression and cross-checks that the hand-maintained rule agrees with Babel's CLDR-derivedLocale('ar').plural_formacross a range ofn(0, 1, 2, 3, 10, 11, 50, 99, 100, 101, 102, 111, 999, 1000). It fails onmasterand passes with this change.6202 passed). The only failure in a full run is the pre-existing, system-timezone-dependenttest_get_timezone_name_misc(issue test_get_timezone_name_misc fails when system TZ isn't UTC #935), which fails identically onmasterhere and is unrelated to this change.ruffis clean on the changed files.Disclosure: this change was prepared with the assistance of an AI tool (Claude Code). I verified the rule against Babel's own CLDR data, added and ran the regression test, ran the suites and linter, and take responsibility for the contribution and will respond to review feedback personally.