()
| 32 | type translation map[string]any |
| 33 | |
| 34 | func main() { |
| 35 | log.SetFlags(log.Lshortfile) |
| 36 | |
| 37 | token := os.Getenv("WEBLATE_TOKEN") |
| 38 | if token == "" { |
| 39 | log.Fatal("Need environment variable WEBLATE_TOKEN") |
| 40 | } |
| 41 | |
| 42 | curValidLangs := make(map[string]struct{}) |
| 43 | for _, lang := range loadValidLangs() { |
| 44 | curValidLangs[lang] = struct{}{} |
| 45 | } |
| 46 | log.Println(curValidLangs) |
| 47 | |
| 48 | resp := req("https://hosted.weblate.org/api/components/syncthing/gui/statistics/", token) |
| 49 | var statRes struct { |
| 50 | Results []stat |
| 51 | } |
| 52 | if err := json.NewDecoder(resp.Body).Decode(&statRes); err != nil { |
| 53 | log.Fatal(err) |
| 54 | } |
| 55 | resp.Body.Close() |
| 56 | |
| 57 | names := make(map[string]string) |
| 58 | |
| 59 | var langs []string |
| 60 | for _, stat := range statRes.Results { |
| 61 | code := reformatLanguageCode(stat.Code) |
| 62 | pct := 100 * stat.Translated / stat.Total |
| 63 | if _, valid := curValidLangs[code]; pct < 75 || !valid && pct < 95 { |
| 64 | log.Printf("Language %q too low completion ratio %d%%", code, pct) |
| 65 | } else { |
| 66 | langs = append(langs, code) |
| 67 | names[code] = stat.Name |
| 68 | } |
| 69 | if code == "en" { |
| 70 | continue |
| 71 | } |
| 72 | |
| 73 | log.Printf("Updating language %q", code) |
| 74 | |
| 75 | resp := req("https://hosted.weblate.org/api/translations/syncthing/gui/"+stat.Code+"/file/", token) |
| 76 | bs, err := io.ReadAll(resp.Body) |
| 77 | if err != nil { |
| 78 | log.Fatal(err) |
| 79 | } |
| 80 | resp.Body.Close() |
| 81 | |
| 82 | var t translation |
| 83 | if err := json.Unmarshal(bs, &t); err != nil { |
| 84 | log.Fatal(err) |
| 85 | } |
| 86 | |
| 87 | fd, err := os.Create("lang-" + code + ".json") |
| 88 | if err != nil { |
| 89 | log.Fatal(err) |
| 90 | } |
| 91 | fd.Write(bs) |
nothing calls this directly
no test coverage detected