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: language.TraditionalChinese.Parent() != language.Chinese #25603

Closed
nicksnyder opened this issue May 28, 2018 · 9 comments
Closed

Comments

@nicksnyder
Copy link

@nicksnyder nicksnyder commented May 28, 2018

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

go version go1.10.2 darwin/amd64

Does this issue reproduce with the latest release?

Yes

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/nick/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/nick/dev/gopath"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.10.2/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.10.2/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/l6/djg_zw1j5lgbwz4h5q92lnwr0000gn/T/go-build319403565=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

package main

import "fmt"
import "golang.org/x/text/language"

func main() {
	hans := language.SimplifiedChinese.Parent() == language.Chinese
	hant := language.TraditionalChinese.Parent() == language.Chinese
	fmt.Println(hans, hant) // true, false
}

What did you expect to see?

I expected language.TraditionalChinese.Parent() == language.Chinese

What did you see instead?

language.TraditionalChinese.Parent() == language.Und

@meirf
Copy link
Contributor

@meirf meirf commented May 28, 2018

The code that's causing the divergent behavior has the following explanation:

// The parent for an base-script pair with a non-default script is
// "und" instead of the base language."
@nicksnyder
Copy link
Author

@nicksnyder nicksnyder commented May 28, 2018

I guess my real question is “why?”

@meirf
Copy link
Contributor

@meirf meirf commented May 28, 2018

cc @mpvl

@ALTree
Copy link
Member

@ALTree ALTree commented May 29, 2018

That comment seems to rule out the possibility that the behaviour you're observing is a bug. In general we don't use the issue tracker for questions, it's just for actual bugs.

I guess my real question is “why?”

Are you just curious, or the observed (and documented) behaviour is causing you troubles?

@nicksnyder
Copy link
Author

@nicksnyder nicksnyder commented May 29, 2018

Ultimately I am questioning the correctness/usefulness of this behavior.

A simple reading of the godoc doesn’t give any guidance to this behavior so I think the expected behavior described above is reasonable and the actual behavior is surprising.

As a user of this API, this caused an unexpected bug (which I was able to workaround): nicksnyder/go-i18n#107

If this is indeed working as intended then I think better documentation would satisfy me. I am also personally curious to understand the rational for this particular behavior.

@ALTree
Copy link
Member

@ALTree ALTree commented May 29, 2018

Okay, leaving this open then. Package owner @mpvl is likely the one that can answer your questions and make a decision about this.

@gopherbot
Copy link

@gopherbot gopherbot commented Oct 29, 2018

Change https://golang.org/cl/145437 mentions this issue: language: improve docs for Parent

@mpvl
Copy link
Member

@mpvl mpvl commented Oct 29, 2018

This behavior is defined in http://unicode.org/reports/tr35/#Parent_Locales

The parent relationship is used to determine fallback data, or fields that can be inherited from "parent" languages. Generally this corresponds to stripping away the last part of a BCP 47 tag, but not always. In general, single-component tags typically apply some default script. For instance, Dutch is typically written in Latin script, so no use to write nl-Latn. However, some languages are commonly written in more than one script, and it would be bad for a user to fall back on a language for which the script is not understood. In the case of zh and zh_Hant it is even worse, as they do not only imply a different script, but also, with high likelihood, a different language (cmn_Hans and yue_Hant, respectively). I guess zh is still widely used as there is still a decent amount of mutual intelligibility between the written form of Chinese languages if written in the same script. But one should not assume mutual intelligibility between different scripts. Hence.

@nicksnyder
Copy link
Author

@nicksnyder nicksnyder commented Oct 29, 2018

Thanks for the explanation! The proposed documentation looks good to me.

@golang golang locked and limited conversation to collaborators Oct 29, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.