Skip to content

x/text/message: package level docs about MatchLanguage are unclear #27641

@svip

Description

@svip

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go1.11 linux/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

linux/amd64

What did you do?

I tried to use message.MatchLanguage("nl") to obtain language.Dutch, as per the example on its site.

See the following code for an example:

package main

import (
	"golang.org/x/text/message"
	"golang.org/x/text/language"
	"fmt"
)

func main() {
	nl := message.MatchLanguage("nl")
	fmt.Println(nl) // Prints "und", expected "nl"
	fmt.Println(language.Dutch) // Prints "nl" as expected
	p := message.NewPrinter(message.MatchLanguage("nl"))
	p.Printf("%.2f\n", 5000.00) // Prints "5,000.00", expected "5.000,00"

	p2 := message.NewPrinter(message.MatchLanguage("bn"))
	p2.Println(123456.78) // Prints "5,000.00", expected "১,২৩,৪৫৬.৭৮"
}

What did you expect to see?

I expected to receive language.Dutch, so that when I called p.Printf("%.2f\n", 5000.00), I would get "5.000,00", as Dutch uses "." for thousand separators and "," for decimal separators.

What did you see instead?

Instead message.MatchLanguage("nl") returned the und Tag rather than the Dutch Tag. And therefore when I called p.Printf() as per the example on the package's description, I got "5,000.00", which ironically matches the example in the description, but the example is wrong.

I also tried the third example in opening example, which also did not seem to produce the expected result.

It seems to me that message.MatchLanguage() either does not work or does not work as described.

Note: Making a new Printer with language.Dutch works as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions