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/message: catalog.Var between two substitutions #70438

Open
AlphaLxy opened this issue Nov 19, 2024 · 3 comments
Open

x/text/message: catalog.Var between two substitutions #70438

AlphaLxy opened this issue Nov 19, 2024 · 3 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@AlphaLxy
Copy link

AlphaLxy commented Nov 19, 2024

Go version

go version go1.21.4 darwin/arm64

Output of go env in your module/workspace:

GO111MODULE='on'
GOARCH='arm64'
GOBIN='/Users/xxx/go/bin'
GOCACHE='/Users/xxx/Library/Caches/go-build'
GOENV='/Users/xxx/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/xxx/go/pkg/mod'
GOOS='darwin'
GOPATH='/Users/xxx/go'
GOROOT='/opt/homebrew/opt/go/libexec'
GOSUMDB='sum.golang.google.cn'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/opt/go/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.21.4'
GCCGO='gccgo'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/dev/null'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/b1/0fd1b6hs7lz0fm_mh346lybm0000gn/T/go-build2121787907=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

golang.org/x/text=v0.20.0

I use catalog.Var between two %d substitutions.

lang := language.English
v := catalog.Var("var", catalog.String("value"))
message.Set(lang, "key1", v, catalog.String("%d %d\n"))              // two %d
message.Set(lang, "key2", v, catalog.String("%d ${var} %d\n"))       // var between two %d
message.Set(lang, "key3", v, catalog.String("%d %d ${var}\n"))       // var after two %d
message.Set(lang, "key4", v, catalog.String("%[1]d ${var} %[2]d\n")) // var between two %[?]d

printer := message.NewPrinter(lang)
printer.Printf("key1", 1, 2) // 1 2
printer.Printf("key2", 1, 2) // 1 %!(EXTRA int=2)value%!(EXTRA int=2) 2
printer.Printf("key3", 1, 2) // 1 2 value
printer.Printf("key4", 1, 2) // 1 value 2

What did you see happen?

1 2
1 %!(EXTRA int=2)value%!(EXTRA int=2) 2
1 2 value
1 value 2

What did you expect to see?

1 2
1 value 2
1 2 value
1 value 2
@gopherbot gopherbot added this to the Unreleased milestone Nov 19, 2024
@gabyhelp
Copy link

Related Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

@AlphaLxy
Copy link
Author

Seems that

func (p *printer) doPrintf(fmt string) {
	for p.fmt.Parser.SetFormat(fmt); p.fmt.Scan(); {
		switch p.fmt.Status {
		case format.StatusText:
			p.WriteString(p.fmt.Text())
		case format.StatusSubstitution:
			p.printArg(p.Arg(p.fmt.ArgNum), p.fmt.Verb)

do not set p.fmt.Reordered.

@dmitshur dmitshur added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Nov 20, 2024
@dmitshur
Copy link
Contributor

CC @mpvl.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants