Repository navigation
Emit digits for =<DecimalFormat pattern>= replace rules - #15
Merged
synesthesiam merged 1 commit intoNov 17, 2026
Merged
Conversation
A =...= replacement whose target is a DecimalFormat pattern (=#,##0=, =#,##,##0=, =0=) was treated as a ruleset-name replacement and looked up as a ruleset. No such ruleset exists, so the lookup raised RulesetNotFoundError and the number produced no output. CLDR uses these pattern replacements as the fallback once a language runs out of spelled-out words (English spellout-cardinal routes 1e18 and up through =#,##0=) and for digit-based ordinal rulesets (Hindi digits-ordinal-masculine spells 7 as "7वाँ"). Every such input failed with NoRuleForNumberError across the public API, including when the ruleset was requested by name. Detect a DecimalFormat pattern (only #, 0, grouping commas and a decimal point, never a letter) and render it with the existing format_decimal helper, which was defined and tested but never wired into the engine, instead of recursing into a non-existent ruleset.
Member
|
Thanks! |
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.
Emit digits for
=<DecimalFormat pattern>=replace rulesWhat
An RBNF
=...=replace rule whose target is a DecimalFormat pattern (=#,##0=,=#,##,##0=,=#,##0.#=,=0=) currently raisesNoRuleForNumberErrorinstead of emitting the grouped digits. Two user-reachable effects:RbnfEngine.for_language("en").format_number(10**18)raisesNoRuleForNumberErroronmain. The Englishspellout-cardinalrule for1000000000000000000is=#,##0=, so every value ≥ 1e18 fails. 86 of 87 bundled languages fail at 1e18 before this change.digits-ordinal-*rulesets are entirely broken.for_language("hi").format_number(7, ruleset_names=["digits-ordinal-masculine"])raisesNoRuleForNumberErroronmain. These non-private rulesets (Hindi=#,##,##0=वाँ, Ewe, etc.) are the common written ordinal form and were unusable for every input.After the fix:
enformat_number(10**18)→1,000,000,000,000,000,000hiformat_number(7, ruleset_names=["digits-ordinal-masculine"])→7वाँWhy
In ICU RBNF,
=pattern=means "format the number with this DecimalFormat pattern" (grouped digits), not "substitute a ruleset." The engine instead treated the pattern string as aruleset_nameand recursed intoiter_format_number(..., ruleset_name="#,##0"), which has no matching ruleset →RulesetNotFoundError→ the ruleset is skipped →NoRuleForNumberError. The repo already shipsformat_decimal(decimal_format.py, covered bytest_decimal_format.py) for exactly this, but it was never wired into the engine.Fix
In the
ReplaceRulePartbranch, if the replace target matches a DecimalFormat pattern (^[#0,.]+$), emitformat_decimal(number, pattern); otherwise recurse as before. The regex is unambiguous: ruleset names always contain letters, and across all 87 bundled languages the only letterless replace targets are#,##,##0,#,##0,#,##0.#, and0.Tests
Adds
test_replace_with_decimal_format_patternplus a 1e18 assertion intest_en.py. Full suite passes (128 tests); both new assertions fail onmainand pass with the fix. No regression in existing spellout output (cardinals, ordinals, fractions, years verified unchanged).