Repository navigation
Conversation
akx
requested changes
Nov 4, 2026
| 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: |
Member
There was a problem hiding this comment.
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).
Author
|
可以的 我觉得你的想法很有道理
…---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: ***@***.***>
|
This branch has not been deployed
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 #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.