aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/gotext.go
diff options
context:
space:
mode:
Diffstat (limited to 'gotext.go')
-rw-r--r--gotext.go49
1 files changed, 42 insertions, 7 deletions
diff --git a/gotext.go b/gotext.go
index 156fb4e9..db39bdd3 100644
--- a/gotext.go
+++ b/gotext.go
@@ -1,21 +1,56 @@
-// +build generate
-//go:generate go run gotext.go -srclang=en update -out=zgotext.go -lang=en,fr,it,ja,sl
+//go:build generate
+
+//go:generate go run gotext.go
/* SPDX-License-Identifier: MIT
*
- * Copyright (C) 2020 WireGuard LLC. All Rights Reserved.
+ * Copyright (C) 2019-2022 WireGuard LLC. All Rights Reserved.
*/
package main
import (
- "io/ioutil"
+ "encoding/json"
"os"
"os/exec"
+ "path/filepath"
+ "strings"
+
+ "golang.org/x/text/message/pipeline"
)
func main() {
- gotext, err := ioutil.TempFile("", "gotext*.exe")
+ langDirs, err := os.ReadDir("locales")
+ if err != nil {
+ panic(err)
+ }
+ var langs []string
+ for _, dir := range langDirs {
+ if !dir.IsDir() {
+ continue
+ }
+ lang := dir.Name()
+ if jsonData, err := os.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 := os.CreateTemp("", "gotext*.exe")
if err != nil {
panic(err)
}
@@ -29,8 +64,8 @@ func main() {
if err != nil {
panic(err)
}
- cmd = exec.Command(gotextFilename, os.Args[1:]...)
- cmd.Env = append(os.Environ(), "GOOS=windows", "GOARCH=amd64", "CGO_ENABLED=1", "CC=x86_64-w64-mingw32-gcc")
+ cmd = exec.Command(gotextFilename, "-srclang=en", "update", "-out=zgotext.go", "-lang="+strings.Join(langs, ","))
+ cmd.Env = append(os.Environ(), "GOOS=windows", "GOARCH=amd64")
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err = cmd.Run()