Repository navigation
Conversation
| plural_form = locale.plural_form(plural_number) | ||
| if plural_form not in compact_format: | ||
| plural_form = "other" | ||
| if scaled == 1 and "1" in compact_format: |
There was a problem hiding this comment.
Let's also use the rounded value here:
| if scaled == 1 and "1" in compact_format: | |
| if rounded == 1 and "1" in compact_format: |
and then change the tests accordingly and add
('fr', 1234, 0, 'mille'),
('fr', -1234, 0, '-1 millier'),
to the tests (this ought to match what Node ICU does).
|
可以的 我觉得你的想法很有道理
…---Original---
From: "Aarni ***@***.***>
Date: Wed, Nov 4, 2026 21:54 PM
To: ***@***.***>;
Cc: ***@***.******@***.***>;
Subject: Re: [python-babel/babel] Fix compact decimal plural selection after rounding (PR #1430)
@akx requested changes on this pull request.
In babel/numbers.py:
> @@ -692,8 +692,10 @@ def _get_compact_format( if index > 0 and abs(rounded) * divisor >= magnitudes[index - 1]: bumped = decimal.Decimal(magnitudes[index - 1]).copy_sign(number) return _get_compact_format(bumped, compact_format, locale, fraction_digits) - # if the remaining number is singular, use the singular format - plural_form = locale.plural_form(abs(scaled)) + # Select the plural form from the displayed number. Optional trailing + # fractional zeros are not rendered by the compact pattern. + plural_number = abs(rounded).normalize() + plural_form = locale.plural_form(plural_number) if plural_form not in compact_format: plural_form = "other" if scaled == 1 and "1" in compact_format:
Let's also use the rounded value here:
⬇️ Suggested change - if scaled == 1 and "1" in compact_format: + if rounded == 1 and "1" in compact_format:
and then change the tests accordingly and add
('fr', 1234, 0, 'mille'), ('fr', -1234, 0, '-1 millier'),
to the tests (this ought to match what Node ICU does).
—
Reply to this email directly, view it on GitHub, or unsubscribe.
Triage notifications, keep track of coding agent tasks and review pull requests on the go with GitHub Mobile for iOS and Android. Download it today!
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
|
@0718lol Sorry, I can't read that (without Google Translate anyway). Are you able to enact the changes requested? |
As requested in review: the special case should test the rounded display value instead of the scaled input, so e.g. fr 1234 with fraction_digits=0 formats as 'mille' (matching Node ICU), while fr -1234 keeps '-1 millier'. Adds the two French cases to test_compact_plural_uses_displayed_number and updates the matching expectation in test_compact.
|
Done, pushed as f6411c5:
Verification: the two new cases fail before the change and pass after. Full Sorry for the earlier reply in Chinese. This update was prepared with AI assistance under my direction, as disclosed in the PR description. |
There was a problem hiding this comment.
🟡 Changes recommended
The exact-1 pattern now applies to scaled values that round to 1, contradicting the description and requiring either a description update or restoration of the exact comparison.
1 open issue
What changed in this PR
Updates Babel’s compact decimal formatting to select plural forms from the rounded displayed value, addressing #1429.
Changes:
- Uses rounded values with optional trailing zeros removed for plural selection.
- Extends literal exact-
1pattern selection to values that round to 1. - Adds 13 regression cases across five locales and updates Italian and French expectations.
| File | Description |
|---|---|
| tests/test_numbers.py | Adds coverage for rounding, signs, retained fractions, and trimmed zeros. |
| tests/test_numbers_format_decimal.py | Updates Italian and French compact-format expectations. |
| babel/numbers.py | Uses normalized rounded values for plural rules and rounded values for exact-1 matching. |
Review effort: Balanced
| if plural_form not in compact_format: | ||
| plural_form = "other" | ||
| if scaled == 1 and "1" in compact_format: | ||
| if rounded == 1 and "1" in compact_format: |

Fixes #1429.
Select compact decimal plural forms using the rounded displayed value rather than the unrounded scaled value. Normalize optional fractional zeros before plural selection, since they are not displayed. For example, Russian 1100 now renders as
1 тысячаinstead of1 тысячи, and Polish 1900 renders as2 tysiąceinstead of2 tysiąca.Add 11 regression cases covering positive and negative values, retained fractions, trimmed zeros, and five locales. Update the existing Italian 1234 expectation from
1 milatomille, matching the rounded-value plural rule and Node's Intl formatter. The separate exact-1pattern selection is unchanged.Validation: CLDR 48.2 imported using the repository script; Python 3.12.15 on macOS; full suite: 7856 passed, 8 skipped, 2 xfailed. Ruff and
git diff --checkpass. The new regression tests fail on the original implementation.Developed and tested with Codex assistance.