Multiple package problem inside "golang.org/x/text"

I am doing some tests with a package golang.org/x/text

and in particular with feature/plural

and its method MatchDigits

. That's what I'm doing:

package main

import (
    "fmt"

    "golang.org/x/text/feature/plural"
    "golang.org/x/text/language"
)

func main() {
    fmt.Println(plural.Cardinal.MatchDigits(language.French, []byte{1}, 1, 0)) // "1" -> should print 2 (One) but prints 0 (Other)
    fmt.Println(plural.Cardinal.MatchDigits(language.French, []byte{2}, 1, 0)) // "2" -> prints 0 (Other) the correct value
    fmt.Println(plural.Cardinal.MatchDigits(language.French, []byte{1, 0}, 2, 0)) // "10" -> prints 0 (Other) the correct value
}

      

And this is where I get the expected results from: http://www.unicode.org/cldr/charts/latest/supplemental/language_plural_rules.html#fr

I also tried in another language with more complex multiple rules like Czech and the output was wrong.

Am I missing something? I cannot find many examples on this package.

Thank!

EDIT:

After some tests, I found a good result for "1" using 0 as parameters exp

and scale

:

fmt.Println(plural.Cardinal.MatchDigits(language.French, []byte{1}, 0, 0)) // prints 2 (One), the correct value

      

But that doesn't match what it says and doesn't work when I try to use 1.5 with the same logic:

fmt.Println(plural.Cardinal.MatchDigits(language.French, []byte{1, 5}, 0, 1)) // prints 0 (Other), should print 2 (One)

      

+3


source to share





All Articles