-
Notifications
You must be signed in to change notification settings - Fork 18k
x/text: message.MatchLanguage does not return desired language #26766
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'll start looking into this |
Change https://golang.org/cl/127551 mentions this issue: |
I found a issue with your example, the correct fmt string is: I fixed the documentation. |
@belimawr it's not only that unfortunately. What is the output? Comma should be used as decimal separator but dot is used instead. MatchLanguage is falling back to English. If I use
|
OK, after reading the code and its tests it was more clear. We need to setup catalog otherwise it is always the default fallback language English. I think documentation should reflect this behavior. Following code works for English and Dutch with Dutch as the fallback language. It would be exteremly nice to have this in the sample code in documentation. c := catalog.NewBuilder(catalog.Fallback(language.Dutch))
c.SetString(language.Dutch, "", "")
c.SetString(language.English, "", "")
message.DefaultCatalog = c Edit: I think |
@kaskavalci I see your point. The thing is that the default catalog is empty and the fallback is English. I looked more at the code and documentation for catalog, and I'm not sure that the best method to get the language is If the objective of that piece of documentation is to show how to use p := message.NewPrinter(language.Make("nl"))
p.Printf("Hoogte: %.1f meter\n", 1244.9) // Prints Hoogte: 1.244,9 meter I created another issue #26767 before this investigation to improve the documentation, however now I'm not sure if it's a documentation issue, or a design issue. Edit: let's keep this discussion on #26767 as it does not seem to be an implementation issue anymore. |
What version of Go are you using (
go version
)?go version go1.10.3 darwin/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?What did you do?
Run the example on https://godoc.org/golang.org/x/text/message
Note: Slightly changed because example is not correct. Behavior is the same.
What did you expect to see?
It should print the desired output, comma as decimal deliminator.
Output is the following which is English formatting.
What did you see instead?
MatchLanguage fallsback to English as can be seen from here:
The text was updated successfully, but these errors were encountered: