I am following this tutorial by Alex Edwards for including translations in my Go 1.22 project. It's great, until it comes to running this command:
package translations
//go:generate gotext -srclang=en-US update -out=catalog.go -lang=en-US,it-IT github.com/myCompany/myProject/package
For what I have understood, if I want to cover more packages I just need to add them at the end, like this
package translations
//go:generate gotext -srclang=en-US update -out=catalog.go -lang=en-US,it-IT github.com/myCompany/myProject/package1 github.com/myCompany/myProject/package2 github.com/myCompany/myProject/package3
as it's said also in the tutorial
Lastly, we have the fully-qualified module path for the package(s) that you want to create translations for (in this case bookstore.example.com/cmd/www). You can list multiple packages if necessary, separated by a whitespace character.
I think it could easily become kinda ugly, since the number of packages will easily grow.
The ideal solution for me could be something like this, including all sub-packages
package translations
//go:generate gotext -srclang=en-US update -out=catalog.go -lang=en-US,it-IT github.com/myCompany/myProject/mainPackage/...
I tried passing also ./../...
and similar stuff as package, but none of them works. I'm literally stuck here.
Any ideas?
gotext
uses loader#Config.FromArgs
which doesn't support wildcards.
So no, either list them all or patch gotext
.
You can do //go:generate go run anything.go
and build whatever list you need programatically. The source is pretty easy to copy and adapt.