Skip to content

Issue with French culture #179

@OhSoGood

Description

@OhSoGood

Hi,

I've been happily using SmartFormat for a while (thank you very much for it!), just to realize I was always on English culture (I'm using SmartFormat v2.7 on .NET 4.7).

Switching to French, I realized that the implementation of PluralRules.DualFromZeroToTwo (used in French) did not take into account the 'c' parameter like PluralRules.DualOneOther (used in English).

Ex:
Smart.Format("{0:|One item|Two items}", 1") returns 'One item' as expected, but
Smart.Format(new CultureInfo("fr"), "{0:|Un objet|Deux objets}", 1") returns an empty string instead of 'Un objet'.

This is because DualFromZeroToTwo is too simplistic and should be written like DualOneOther.

// This is DualOneOther original code
private static PluralRuleDelegate DualOneOther => (n, c) =>
        {
            if (c == 2) return n == 1 ? 0 : 1;
            if (c == 3) return n == 0 ? 0 : n == 1 ? 1 : 2;
            if (c == 4) return n < 0 ? 0 : n == 0 ? 1 : n == 1 ? 2 : 3;
            return -1;
        };// Dual: one (n == 1), other

// This is my proposal for DualFromZeroToTwo 
private static PluralRuleDelegate DualFromZeroToTwo => (n, c) => 
        {
            if (c == 2) return n < 2 ? 0 : 1;
            if (c == 3) return n == 0 ? 0 : n < 2 ? 1 : 2;
            if (c == 4) return n < 0 ? 0 : n == 0 ? 1 : n < 2 ? 2 : 3;
            return -1;
        };// DualFromZeroToTwo: one (n == 0..2 fractionate and n != 2), other

In the meantime, I'll stick to English as the current lib's code is erroneous for French and other 'DualFromZeroToTwo' cultures.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions