nicksnyder / go-i18n

Translate your Go program into multiple languages.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to generate translations for multiple packages inside same module

plastikfan opened this issue · comments

I am creating a cli (template) project which contains multiple packages and trying to figure out the correct workflow for this scenario. I am following the instructions in this blog article internationalization i18n go, and am a little perplexed as to how to apply the go generate instruction to work accross package boundaries:

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

My project structure is this:

.
├── go.mod
├── go.sum
├── LICENSE
├── README.md
├── src
│   └── app
│       ├── command
│       │   ├── root-cmd.go
│       │   ├── version.go
│       │   └── widget-cmd.go
│       └── main
│           ├── app_suite_test.go
│           ├── greeting.go
│           ├── greeting_test.go
│           └── main.go
└── Taskfile.yml

So how should I proceed from here? I was intending to create the catalog directory under the src directory, but I have no idea if this would be correct or work.

  • I assume only 1 source file should contain this go generate instruction, but does it work accross package boundaries?
  • if it doesnt wok accross package boundaries, can we just pick an entry point inside each package and have 1 file in each package that contains the go generate? (I assume we could then merge the created files for a combined transtion at the end)

Actually, I also have another question about writing library packages designed for i18n, but I'll keep that for another issue, so that responses can be focused.

Appreciate any help, cheers.