Skip to content

Normalize negative inputs in generated JavaScript plural rules - #1414

Open
parijat1222q wants to merge 1 commit into
python-babel:masterfrom
parijat1222q:fix-javascript-negative-plural
Open

parijat1222q wants to merge 1 commit into
python-babel:masterfrom
parijat1222q:fix-javascript-negative-plural

Conversation

@parijat1222q

Copy link
Copy Markdown

Normalize n with Math.abs once before evaluating generated JavaScript plural rules. This matches Python's extract_operands and the Unicode definition of plural operands as absolute values.

For {'one': 'n is 1', 'few': 'n in 2..4'}, Python selects one for -1 and few for -2, while the current generated JavaScript selects other for both.

Update the generated-source expectations and add always-on normalization checks for empty, direct, integer, modulo and range rules. Four execution tests compare the generated function with Python for negative integers/fractions, zero and positive controls. They use Node.js when available and skip only those execution tests otherwise, without adding a required dependency. All four execution regressions fail on unchanged master.

Validation against 9a3ef47, Linux, imported CLDR 48.2:

  • All 19 configured Tox environments pass: CPython 3.8-3.15, PyPy 3.10, and the listed pytz/setuptools/Jinja variants, including coverage. CPython 3.15: 7,924 passed, 7 skipped, 2 expected failures. PyPy: 7,923 passed, 7 skipped, 3 expected failures.
  • Plural tests: 47 passed, including the Node.js 22.23.3 execution regressions.
  • Configured, pinned pre-commit hooks on all files, source/wheel build, and git diff --check pass.
  • Separate generated-JavaScript/Python comparison: 29,795 integer checks across 59 distinct cardinal/ordinal rules pass. Rules referencing existing unsupported compact-exponent operands were excluded from that extra comparison; they are not changed here.

Test runs used process-local TZ=UTC: two unrelated host-timezone assertions fail with Asia/Calcutta on both unchanged master and this branch. No tests were deselected. The existing pytest parametrization warning remains. Windows/macOS were not run locally; upstream CI is still pending.

Fixes #1413

Use absolute values before evaluating generated plural rules, matching
Python and the Unicode plural operand definition. Cover source output
and JavaScript execution for negative and positive inputs.

Fixes python-babel#1413

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.

Generated JavaScript plural rules misclassify negative counts

2 participants