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
Labels
FeatureRequest NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@fgm
Copy link

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.
@gopherbot gopherbot added this to the Unreleased milestone Dec 23, 2018
@agnivade agnivade added NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. FeatureRequest labels Jan 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

3 participants