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: generates catalog with package main, can't import it #30418

Closed
chetaldrich opened this issue Feb 26, 2019 · 2 comments
Closed

x/text: generates catalog with package main, can't import it #30418

chetaldrich opened this issue Feb 26, 2019 · 2 comments

Comments

@chetaldrich
Copy link

chetaldrich commented Feb 26, 2019

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, also the latest commit, since that seems more relevant given this

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

$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/chetaldrich/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/chetaldrich/code/gocode"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.11.4/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.11.4/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/chetaldrich/code/buyer-frontend/go.mod"
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/gk/00k__7v13yv4c03zby3z0vwm0000gn/T/go-build187191772=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Run go generate with the following code:

package main

//go:generate gotext -srclang=en update -out=catalog/catalog.go -lang=en,es

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

func main() {
	p := message.NewPrinter(language.Spanish)
	p.Printf("American")
}

You'll also need a file called locales/es/messages.gotext.json with the following contents:

{
    "language": "es",
    "messages": [
      {
        "id": "American",
        "message": "American",
        "translation": "Americana",
      }
    ]
}

What did you expect to see?

A catalog.go file with package catalog so I could import it in my main class.

What did you see instead?

A catalog.go file with package main, which I can't import.

I'm suspecting this has something to do with the fact that the file itself is in package main, but it's not clear from any documentation in the godoc or elsewhere how to actually change this if that's possible.

For context, I was following this guide when trying to integrate this into my project, since this offered a bit more information than the documentation does at present.

cc @mpvl since it seems like you're the maintainer

@gopherbot gopherbot added this to the Unreleased milestone Feb 26, 2019
@bcmills
Copy link
Contributor

bcmills commented Feb 28, 2019

Per https://godoc.org/golang.org/x/text/cmd/gotext:

Usage:

gotext update <package>* [-out <gofile>]

In this invocation you're not passing an explicit package name, so presumably gotext is inferring it from the package in the current working directory.

@bcmills
Copy link
Contributor

bcmills commented Feb 28, 2019

//go:generate generates additional files for the package containing the source file in which the comment appears. If you want to generate source code for ./catalog, then the //go:generate comment belongs in a source file within the catalog subdirectory.

@bcmills bcmills closed this as completed Feb 28, 2019
@golang golang locked and limited conversation to collaborators Feb 28, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants