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-08-18 09:49:17 +0200
commit4a5197ed48b22a24c5e150b9308ee4c149bec89e (patch)
tree92dd59fa06cf18b0aa0a3ac0193637dc2606e6e9 /gotext.go
parenttunnel: use conn.BindSocketToInterface type (diff)
downloadwireguard-windows-4a5197ed48b22a24c5e150b9308ee4c149bec89e.tar.xz
wireguard-windows-4a5197ed48b22a24c5e150b9308ee4c149bec89e.zip
locale: sync translations and rework enumeration
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