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: support error and fmt.Stringer values #29400

Open
fgm opened this issue Dec 23, 2018 · 0 comments
Open

x/text: support error and fmt.Stringer values #29400

fgm opened this issue Dec 23, 2018 · 0 comments

Comments

@fgm
Copy link

@fgm fgm commented Dec 23, 2018

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

$ go version
go version go1.11.4 darwin/amd64

Does this issue reproduce with the latest release?

Yes, this is the latest release

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

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/fgm/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/fgm/src/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
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/0g/p780bc554njc4qj110_8rmbr0000gn/T/go-build831580697=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

What did you expect to see?

  • string values for err are extracted and translations running displays the error in french.

What did you see instead?

  • "panic: key argument is not a Reference"

Diagnostic

This happens because message.lookupAndFormat() can only handle plain strings and message.key (unexported type) as translation keys. It would make it easier to have translatable errors and other higher-level data if the switch handled error and fmt.Stringer values.

  • Values of type error could be converted to strings using their Error() method, and thereafter handled as strings (id, mgs = v, v)
  • Values implementing fmt.Stringer could be converted to strings using their String() method, and handled the same way.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

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