Open fgm opened 5 years ago
go version
$ go version go version go1.11.2 linux/amd64
go env
$ go env GOARCH="amd64" GOBIN="" GOCACHE="/home/fgm/.cache/go-build" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="linux" GOOS="linux" GOPATH="/home/fgm/go" GOPROXY="" GORACE="" GOROOT="/usr/local/go" GOTMPDIR="" GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64" GCCGO="gccgo" CC="gcc" CXX="g++" 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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build766242374=/tmp/go-build -gno-record-gcc-switches"
Prepare a simple app with exported strings using //go:generate gotext -srclang=en update -out=catalog/catalog.go -lang=fr
//go:generate gotext -srclang=en update -out=catalog/catalog.go -lang=fr
Invoke p.Printf("Hello, world") and debug what happens, until stepping into message.lookupAndFormat() until this fragment:
message.lookupAndFormat()
if p.catContext.Execute(id) == catalog.ErrNotFound { if p.catContext.Execute(msg) == catalog.ErrNotFound { p.Render(msg) return }
since in most cases id == msg, skip the second execution of p.catContext(msg) if the first execution returned catalog.ErrNotFound
id == msg
p.catContext(msg)
catalog.ErrNotFound
p.catContext.Execute(id)
p.catContext.Execute(msg)
if p.catContext.Execute(id) == catalog.ErrNotFound { if id == msg || p.catContext.Execute(msg) == catalog.ErrNotFound { p.Render(msg) return } }
CC: @mpvl
Still present in v0.3.2 (12/2018) and current master HEAD. I could prepare a PR if you so wish.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Prepare a simple app with exported strings using
//go:generate gotext -srclang=en update -out=catalog/catalog.go -lang=fr
Invoke p.Printf("Hello, world") and debug what happens, until stepping into
message.lookupAndFormat()
until this fragment:What did you expect to see?
since in most cases
id == msg
, skip the second execution ofp.catContext(msg)
if the first execution returnedcatalog.ErrNotFound
What did you see instead?
p.catContext.Execute(id)
returnedcatalog.ErrNotFound
, code performs the same work a second time asp.catContext.Execute(msg)
id == msg
, maybe like: