Skip to content
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

x/text/language: matcher doesn't match en-SG exactly to en #29884

humjosh opened this issue Jan 23, 2019 · 1 comment


Copy link

commented Jan 23, 2019

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

go version go1.11 darwin/amd64

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

amd64, macOS Sierra 10.12.6

What did you do?

package main

import (


func main() {
	preferredTags := []language.Tag{language.English, language.Malay}
	matcher := language.NewMatcher(preferredTags)

	locale := "en-SG;q=1.0, zh-Hant-HK;q=0.9, ms-SG;q=0.8, ja-SG;q=0.7, zh-Hans-SG;q=0.6, en-GB;q=0.5"
	tags, _, _ := language.ParseAcceptLanguage(locale)

	match, _, confidence := matcher.Match(tags...)
	fmt.Printf("Matched %v with confidence %v", match, confidence)

What did you expect to see?

Matched en with confidence Exact

What did you see instead?

Matched ms-u-rg-sgzzzz with confidence High

If you replace en-SG with en-US in the locale string, then it does indeed exactly match to en (en-u-rg-uszzzz)

@gopherbot gopherbot added this to the Unreleased milestone Jan 23, 2019

@FiloSottile FiloSottile changed the title x/text/language matcher doesn't match en-SG exactly to en x/text/language: matcher doesn't match en-SG exactly to en Jan 23, 2019


This comment has been minimized.

Copy link

commented Jan 23, 2019

/cc @mpvl

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
3 participants
You can’t perform that action at this time.