aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/gotext.go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-07-27 11:51:31 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2020-07-28 14:52:19 +0200
commit1d3d60edcb512f2ffc9e543e4cbe0bc7a9bfc013 (patch)
tree32b9faf0b5ad149d02b4af1256499998f14792bf /gotext.go
parenttunnel: use conn.BindSocketToInterface type (diff)
downloadwireguard-windows-master.tar.xz
wireguard-windows-master.zip
locale: sync translations and rework enumerationHEADmaster
We now enumerate directories in locale/ and rename them if Crowdin is giving us a different language code. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'gotext.go')
-rw-r--r--gotext.go39
1 files changed, 37 insertions, 2 deletions
diff --git a/gotext.go b/gotext.go
index e9a59aea..d61ce393 100644
--- a/gotext.go
+++ b/gotext.go
@@ -1,5 +1,5 @@
// +build generate
-//go:generate go run gotext.go -srclang=en update -out=zgotext.go -lang=en,de,fr,it,ja,ru,sl,zh-CN
+//go:generate go run gotext.go
/* SPDX-License-Identifier: MIT
*
@@ -9,12 +9,47 @@
package main
import (
+ "encoding/json"
"io/ioutil"
"os"
"os/exec"
+ "path/filepath"
+ "strings"
+
+ "golang.org/x/text/message/pipeline"
)
func main() {
+ langDirs, err := ioutil.ReadDir("locales")
+ if err != nil {
+ panic(err)
+ }
+ var langs []string
+ for _, dir := range langDirs {
+ if !dir.IsDir() {
+ continue
+ }
+ lang := dir.Name()
+ if jsonData, err := ioutil.ReadFile(filepath.Join("locales", lang, "messages.gotext.json")); err == nil {
+ var translations pipeline.Messages
+ if err := json.Unmarshal(jsonData, &translations); err != nil {
+ panic(err)
+ }
+ lang = translations.Language.String()
+ if lang != dir.Name() {
+ err = os.Rename(filepath.Join("locales", dir.Name()), filepath.Join("locales", lang))
+ if err != nil {
+ panic(err)
+ }
+ }
+ } else if os.IsNotExist(err) {
+ panic(err)
+ }
+ langs = append(langs, lang)
+ }
+ if len(langs) == 0 {
+ panic("no locales found")
+ }
gotext, err := ioutil.TempFile("", "gotext*.exe")
if err != nil {
panic(err)
@@ -29,7 +64,7 @@ func main() {
if err != nil {
panic(err)
}
- cmd = exec.Command(gotextFilename, os.Args[1:]...)
+ cmd = exec.Command(gotextFilename, "-srclang=en", "update", "-out=zgotext.go", "-lang="+strings.Join(langs, ","))
cmd.Env = append(os.Environ(), "GOOS=windows", "GOARCH=amd64", "CGO_ENABLED=1", "CC=x86_64-w64-mingw32-gcc")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr