Repository navigation
Register Macedonian plural rule under mk and fix 111, 211, ... - #538
Merged
Merged
Conversation
Contributor
Author
|
AppVeyor failure is unrelated to this change: the unpinned |
Macedonian was registered under "mb", which is not an ISO 639-1 code, so plural formatting with mk or mk-MK cultures threw "IsoLangToDelegate not found for mk". The rule also compared the whole value with 11, so 111, 211, ... resolved to one. CLDR uses i % 10 = 1 and i % 100 != 11 for one.
axunonb
force-pushed
the
fix/macedonian-plural-rule
branch
from
December 5, 2026 16:33
9bec391 to
d4db6c2
Compare
axunonb
pushed a commit
that referenced
this pull request
Dec 5, 2026
Macedonian was registered under "mb", which is not an ISO 639-1 code, so plural formatting with mk or mk-MK cultures threw "IsoLangToDelegate not found for mk". The rule also compared the whole value with 11, so 111, 211, ... resolved to one. CLDR uses i % 10 = 1 and i % 100 != 11 for one.
axunonb
added a commit
that referenced
this pull request
Dec 5, 2026
* Fix: Apply absolute value logic in `PluralRules` This PR addresses a long-standing inconsistency in the pluralization logic used by `PluralRules`. Previously, the implementation did not explicitly evaluate the absolute value of the input number, contrary to the CLDR specification. This led to incorrect plural category resolution for negative numbers, which typically defaulted to the `OTHER` category. #### Changes - The decimal argument passed to all `PluralRules` delegates is now transformed to its absolute value before evaluation. - This change ensures that plural category resolution aligns with CLDR expectations, particularly because locales with plural forms depend on numeric value regardless of sign. #### Impact - Fixes incorrect plural category resolution for negative numbers in locales such as `DualOneOther`, where the number of plural word variants influences the outcome. - May affect pluralization behavior in edge cases across multiple locales. Unit tests have been updated to reflect the corrected logic. - The change affects `PluralLocalizationFormatter` and `TimeFormatter`. - **Thoroughly test the new version in your localization workflows**, especially if you rely on custom pluralization delegates or locale-specific plural form resolution. This change may surface previously masked edge cases. #### Versioning - The PR will be published with a new **minor version**, as this change corrects a bug but may alter behavior in downstream formatting logic. #### Background See discussion in #503 and #497 for context. * Fix: Use absolute value for plural category selection CLDR plural rules are defined on the absolute value of a number (operand n = |N|, UTS #35 "Plural Operands"). The formatters passed signed values to the rules, so negative numbers could select the wrong category. For example, -1 in en produced "There are -1 items" instead of "There is -1 item". Changes - PluralLocalizationFormatter and TimeTextInfo pass Math.Abs(value) to the plural rule. The formatted output still shows the signed value. - PluralRules: removed the negative-value checks in DualOneOther (4 words), DualFromZeroToTwo (2 words), GetWordsCount4Value and Tachelhit. Built-in callers never pass negative values to them. - PluralRuleDelegate documents that its value argument is the absolute value. - Updated the -1 expectations in PluralLocalizationFormatterTests (en, fr, tr). Impact - Changes output for negative numbers in every locale whose plural rules depend on the value. Tests cover en, fr and tr. - Custom PluralRuleDelegates used through the formatters receive the absolute value. - Custom PluralRuleDelegates called directly with negative numbers receive the signed value, and the rules listed above can return a different category than before. Versioning - Visible output change for negative numbers. Proposed as a minor release (e.g. 3.7.0). Background: #503, #497 * Register Macedonian plural rule under mk and fix 111, 211, ... (#538) Macedonian was registered under "mb", which is not an ISO 639-1 code, so plural formatting with mk or mk-MK cultures threw "IsoLangToDelegate not found for mk". The rule also compared the whole value with 11, so 111, 211, ... resolved to one. CLDR uses i % 10 = 1 and i % 100 != 11 for one. --------- Co-authored-by: Leng Niu <344562942+vtxe02023274@users.noreply.github.com>
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.
Macedonian is registered under
"mb", which is not an ISO 639-1 code.CultureInfo("mk").TwoLetterISOLanguageNameismk, so plural formatting withmkormk-MKthrows:The
Macedonianrule also compared the whole value with 11 (value != 11), so 111, 211, 311, ... resolved toone. CLDR hasonefori % 10 = 1 and i % 100 != 11(1, 21, 101 areone; 11, 111, 211 areother), the same asIntl.PluralRules("mk").Changes:
mkvalue % 100 != 11in the ruleTest_Macedoniancoversmkandmk-MK, with both a culture provider andplural(mk). Before the change both cases throw; with only the key fixed they fail on 111. Both pass now.Full test run: 1,037 passed on net6.0 and 1,032 on net462. The two remaining failures (
Explicit_Formatter_With_Not_Enough_Parameters_Should_ThrowandPluralization_With_Changed_SplitChar) depend on the UI culture of this machine and fail the same way on unchangedmain.