Skip to content

Register Macedonian plural rule under mk and fix 111, 211, ... - #538

Merged
axunonb merged 1 commit into
axuno:mainfrom
vtxe02023274:fix/macedonian-plural-rule
Dec 5, 2026
Merged

axunonb merged 1 commit into
axuno:mainfrom
vtxe02023274:fix/macedonian-plural-rule

Conversation

@vtxe02023274

Copy link
Copy Markdown
Contributor

Macedonian is registered under "mb", which is not an ISO 639-1 code. CultureInfo("mk").TwoLetterISOLanguageName is mk, so plural formatting with mk or mk-MK throws:

IsoLangToDelegate not found for mk (Parameter 'twoLetterIsoLanguageName')

The Macedonian rule also compared the whole value with 11 (value != 11), so 111, 211, 311, ... resolved to one. CLDR has one for i % 10 = 1 and i % 100 != 11 (1, 21, 101 are one; 11, 111, 211 are other), the same as Intl.PluralRules("mk").

Changes:

  • Register the rule under mk
  • Use value % 100 != 11 in the rule

Test_Macedonian covers mk and mk-MK, with both a culture provider and plural(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_Throw and Pluralization_With_Changed_SplitChar) depend on the UI culture of this machine and fail the same way on unchanged main.

@vtxe02023274

Copy link
Copy Markdown
Contributor Author

AppVeyor failure is unrelated to this change: the unpinned dotnet add package AltCover now resolves 9.0.189 (published Nov 18), whose MSBuild task is built for net10.0 and fails to load on the image (MSB4062, System.Runtime 10.0.0.0). The solution builds fine before that step. Pinning AltCover to 9.0.145 or adding the .NET 10 SDK to the image should fix it

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
axunonb force-pushed the fix/macedonian-plural-rule branch from 9bec391 to d4db6c2 Compare December 5, 2026 16:33
@axunonb
axunonb merged commit 699fef3 into axuno:main Dec 5, 2026
6 checks passed
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants