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: printer.Printf works but printer.Print does not (all variants of print/printf) #41781

Open
kalbasit opened this issue Oct 4, 2020 · 2 comments
Labels
NeedsInvestigation
Milestone

Comments

@kalbasit
Copy link

@kalbasit kalbasit commented Oct 4, 2020

When using the message printer, I can translate fine with the Printf variants (Sprintf, Fprintf, Printf) but I don't get the translation for the Print variants (Sprint, Fprint, Print).

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

$ go version
go version go1.14.7 linux/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/yl/.cache/go/cache"
GOENV="/yl/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/yl/.cache/ktmr/go:/yl/.cache/go/path"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/nix/store/y456vnv1032n1fx4bmh1b54m2br4c6jq-go-1.14.7/share/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/nix/store/y456vnv1032n1fx4bmh1b54m2br4c6jq-go-1.14.7/share/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/yl/code/stories/keeptruckin/SLB-962/github.com/KeepTruckin/kt/src/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-static-libstdc++"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/run/user/2000/go-build560714827=/tmp/go-build -gno-record-gcc-switches"

What did you do?

The following code is also available on the playground: https://play.golang.org/p/FHjZ3a8ug51

package main

import (
	"fmt"

	"golang.org/x/text/language"
	"golang.org/x/text/message"
)

func init() {
	message.SetString(language.English, "Book Now", "Book Now")
	message.SetString(language.French, "Book Now", "Réserver Maintenant")
	message.SetString(language.Spanish, "Book Now", "Reserve Ahora")
}

func main() {
	tags := []language.Tag{language.English, language.French, language.Spanish}

	for _, tag := range tags {
		p := message.NewPrinter(tag)
		fmt.Printf("==== %s ====\n", tag)

		fmt.Print("p.Print(\"Book Now\"): ")
		p.Print("Book Now")
		fmt.Println("")

		fmt.Print("p.Printf(\"Book Now\"): ")
		p.Printf("Book Now")
		fmt.Println("")
	}
}

What did you expect to see?

==== en ====
p.Print("Book Now"): Book Now
p.Printf("Book Now"): Book Now
==== fr ====
p.Print("Book Now"): Réserver Maintenant
p.Printf("Book Now"): Réserver Maintenant
==== es ====
p.Print("Book Now"): Reserve Ahora
p.Printf("Book Now"): Reserve Ahora

What did you see instead?

==== en ====
p.Print("Book Now"): Book Now
p.Printf("Book Now"): Book Now
==== fr ====
p.Print("Book Now"): Book Now
p.Printf("Book Now"): Réserver Maintenant
==== es ====
p.Print("Book Now"): Book Now
p.Printf("Book Now"): Reserve Ahora

@kaskavalci mentioned this problem in #26767 (comment)

cc @mpvl

@gopherbot gopherbot added this to the Unreleased milestone Oct 4, 2020
@dmitshur dmitshur added the NeedsInvestigation label Oct 13, 2020
AlexanderYastrebov added a commit to AlexanderYastrebov/text that referenced this issue Oct 16, 2021
@gopherbot
Copy link

@gopherbot gopherbot commented Oct 16, 2021

Change https://golang.org/cl/356314 mentions this issue: x/text: translate messages formatted via non-printf methods

@mpvl
Copy link
Contributor

@mpvl mpvl commented Nov 2, 2021

Translations are only done for format strings or substitutions in %m. So this is intentional.

In my opinion, also translating strings for Print variants is undesirable. But even if it is, this would now be a backwards incompatible change.

To print without a message, one can use p.Printf("%m", str).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation
Projects
None yet
Development

No branches or pull requests

4 participants