Skip to content

Fix compact decimal plural selection after rounding - #1430

Open
0718lol wants to merge 1 commit into
python-babel:masterfrom
0718lol:fix/compact-plural-after-rounding
Open

0718lol wants to merge 1 commit into
python-babel:masterfrom
0718lol:fix/compact-plural-after-rounding

Conversation

@0718lol

@0718lol 0718lol commented Nov 4, 2026

Copy link
Copy Markdown

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 of 1 тысячи, and Polish 1900 renders as 2 tysiące instead of 2 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 mila to mille, matching the rounded-value plural rule and Node's Intl formatter. The separate exact-1 pattern 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 --check pass. The new regression tests fail on the original implementation.

Developed and tested with Codex assistance.

Comment thread babel/numbers.py
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:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@akx akx self-assigned this Nov 4, 2026
@akx akx added this to the Babel 2.19 milestone Nov 4, 2026
@0718lol

0718lol commented Nov 4, 2026 via email

Copy link
Copy Markdown
Author

@akx

akx commented Nov 5, 2026

Copy link
Copy Markdown
Member

@0718lol Sorry, I can't read that (without Google Translate anyway). Are you able to enact the changes requested?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Compact decimal plural forms use the value before rounding

2 participants