diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 9 | ||||
-rw-r--r-- | transifex/Makefile | 8 | ||||
-rw-r--r-- | transifex/main.go | 124 | ||||
-rw-r--r-- | transifex/messages.json | 29 |
5 files changed, 169 insertions, 2 deletions
@@ -2,3 +2,4 @@ bitmask-systray locales/*/out.gotext.json .*.swp *.exe +transifex/transifex @@ -31,17 +31,22 @@ get_deps: sudo apt install libgtk-3-dev libappindicator3-dev golang pkg-config -LANGS ?= $(foreach path,$(wildcard locales/*/messages.gotext.json),$(patsubst locales/%/messages.gotext.json,%,$(path))) +LANGS ?= $(foreach path,$(wildcard locales/*),$(patsubst locales/%,%,$(path))) empty := space := $(empty) $(empty) lang_list := $(subst $(space),,$(foreach lang,$(LANGS),$(lang),)) -locales: catalog.go +locales: $(foreach lang,$(LANGS),get_$(lang)) catalog.go generate_locales: $(foreach lang,$(LANGS),locales/$(lang)/out.gotext.json) + make -C transifex locales/%/out.gotext.json: systray.go notificator.go gotext update -lang=$* catalog.go: $(foreach lang,$(LANGS),locales/$(lang)/messages.gotext.json) gotext update -lang=$(lang_list) -out catalog.go + +get_%: + make -C transifex build + curl -L -X GET --user "api:${API_TOKEN}" "https://www.transifex.com/api/2/project/bitmask/resource/RiseupVPN/translation/${subst -,_,$*}/?file" | transifex/transifex t2g locales/$*/ diff --git a/transifex/Makefile b/transifex/Makefile new file mode 100644 index 0000000..aad1d3e --- /dev/null +++ b/transifex/Makefile @@ -0,0 +1,8 @@ + +all: build generate_json + +build: + go build + +generate_json: + ./transifex g2t ../locales/en-US/out.gotext.json messages.json diff --git a/transifex/main.go b/transifex/main.go new file mode 100644 index 0000000..37bae97 --- /dev/null +++ b/transifex/main.go @@ -0,0 +1,124 @@ +package main + +import ( + "encoding/json" + "fmt" + "os" + "path" + + "golang.org/x/text/message/pipeline" +) + +const ( + outGotext = "out.gotext.json" + messagesGotext = "messages.gotext.json" +) + +type transifex map[string]string + +func main() { + if len(os.Args) < 2 { + panic("g2t or t2g should be passed as argument") + } + + switch os.Args[1] { + case "g2t": + g2t(func(m pipeline.Message) string { return m.Message.Msg }) + case "lang2t": + g2t(func(m pipeline.Message) string { return m.Translation.Msg }) + case "t2g": + t2g() + default: + panic("g2t or t2g should be passed as argument") + } +} + +func g2t(getMessage func(pipeline.Message) string) { + if len(os.Args) < 4 { + panic(fmt.Sprintf("usage: %s g2t inFile outFile", os.Args[0])) + } + + inF, err := os.Open(os.Args[2]) + if err != nil { + panic(fmt.Sprintf("Can't open input file %s: %v", os.Args[2], err)) + } + outF, err := os.Create(os.Args[3]) + if err != nil { + panic(fmt.Sprintf("Can't open output file %s: %v", os.Args[3], err)) + } + + toTransifex(inF, outF, getMessage) +} + +func t2g() { + if len(os.Args) < 3 { + panic(fmt.Sprintf("usage: %s t2g localeFolder", os.Args[0])) + } + + origF, err := os.Open(path.Join(os.Args[2], outGotext)) + if err != nil { + panic(fmt.Sprintf("Can't open file %s/%s: %v", os.Args[3], outGotext, err)) + } + outF, err := os.Create(path.Join(os.Args[2], messagesGotext)) + if err != nil { + panic(fmt.Sprintf("Can't open output file %s/%v: %v", os.Args[3], messagesGotext, err)) + } + toGotext(origF, os.Stdin, outF) +} + +func toTransifex(inF, outF *os.File, getMessage func(pipeline.Message) string) { + messages := pipeline.Messages{} + dec := json.NewDecoder(inF) + err := dec.Decode(&messages) + if err != nil { + panic(fmt.Sprintf("An error ocurred decoding json: %v", err)) + } + + transfx := make(transifex) + for _, m := range messages.Messages { + transfx[m.ID[0]] = getMessage(m) + } + enc := json.NewEncoder(outF) + enc.SetIndent("", " ") + err = enc.Encode(transfx) + if err != nil { + panic(fmt.Sprintf("An error ocurred encoding json: %v", err)) + } +} + +func toGotext(origF, inF, outF *os.File) { + transfx := make(transifex) + dec := json.NewDecoder(inF) + err := dec.Decode(&transfx) + if err != nil { + panic(fmt.Sprintf("An error ocurred decoding json: %v", err)) + } + + messages := pipeline.Messages{} + dec = json.NewDecoder(origF) + err = dec.Decode(&messages) + if err != nil { + panic(fmt.Sprintf("An error ocurred decoding orig json: %v", err)) + } + + for k, v := range transfx { + found := false + for i, m := range messages.Messages { + if m.ID[0] == k { + messages.Messages[i].Translation.Msg = v + found = true + break + } + } + if !found { + fmt.Printf("The original document doesn't have id: %s\n", k) + } + } + + enc := json.NewEncoder(outF) + enc.SetIndent("", " ") + err = enc.Encode(messages) + if err != nil { + panic(fmt.Sprintf("An error ocurred encoding json: %v", err)) + } +} diff --git a/transifex/messages.json b/transifex/messages.json new file mode 100644 index 0000000..36a8c2f --- /dev/null +++ b/transifex/messages.json @@ -0,0 +1,29 @@ +{ + "About": "About", + "About...": "About...", + "Cancel": "Cancel", + "Cancel connection to {ApplicationName}": "Cancel connection to {ApplicationName}", + "Checking status...": "Checking status...", + "Connecting to {ApplicationName}": "Connecting to {ApplicationName}", + "Donate": "Donate", + "Donate...": "Donate...", + "Error starting VPN": "Error starting VPN", + "Help...": "Help...", + "Initialize error": "Initialize error", + "Missing authentication agent": "Missing authentication agent", + "Quit": "Quit", + "Retry": "Retry", + "Route traffic through": "Route traffic through", + "Stopping {ApplicationName}": "Stopping {ApplicationName}", + "Turn off": "Turn off", + "Turn on": "Turn on", + "Use {ApplicationName} {City} gateway": "Use {ApplicationName} {City} gateway", + "aboutText": "{ApplicationName} is an easy, fast, and secure VPN service from riseup.net. {ApplicationName} does not require a user account, keep logs, or track you in any way.\n\t \nThis service paid for entirely by donations from users like you. Please donate at https://riseup.net/vpn/donate.\n\t\t\nBy using this application, you agree to the Terms of Service available at https://riseup.net/tos. This service is provide as-is, without any warranty, and is intended for people who work to make the world a better place.\n\n\n{ApplicationName_1} version: {Version}", + "donationText": "The {ApplicationName} service is expensive to run. Because we don't want to store personal information about you, there is no accounts or billing for this service. But if you want the service to continue, donate at least $5 each month.\n\t\nDo you want to donate now?", + "errorMsg": "An error has ocurred initializing {ApplicationName}: {Err}", + "errorStartingVPN": "Can't connect to {ApplicationName}: {Err}", + "missingAuthAgent": "Could not find a polkit authentication agent. Please run one and try again.", + "{ApplicationName} blocking internet": "{ApplicationName} blocking internet", + "{ApplicationName} off": "{ApplicationName} off", + "{ApplicationName} on": "{ApplicationName} on" +} |