Skip to content

Commit 62f1f80

Browse files
authored
Merge pull request #11746 from spowelljr/translationWorkflow
Add GitHub Action to check if translations are valid
2 parents b49acef + e3326f8 commit 62f1f80

File tree

11 files changed

+166
-50
lines changed

11 files changed

+166
-50
lines changed

.github/workflows/docs.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@ on:
33
push:
44
branches:
55
- master
6-
6+
env:
7+
GOPROXY: https://proxy.golang.org
8+
GO_VERSION: 1.16.4
79
jobs:
810
generate-docs:
911
runs-on: ubuntu-18.04
1012
steps:
1113
- uses: actions/checkout@v2
1214
- uses: actions/setup-go@v2
1315
with:
14-
go-version: 1.16.4
16+
go-version: ${{env.GO_VERSION}}
1517
stable: true
1618
- name: gendocs
1719
run: |

.github/workflows/time-to-k8s.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ name: "time-to-k8s benchmark"
22
on:
33
release:
44
types: [released]
5+
env:
6+
GOPROXY: https://proxy.golang.org
7+
GO_VERSION: 1.16.4
58
jobs:
69
benchmark:
710
runs-on: ubuntu-18.04
@@ -11,7 +14,7 @@ jobs:
1114
run: git submodule update --init
1215
- uses: actions/setup-go@v2
1316
with:
14-
go-version: 1.16.4
17+
go-version: ${{env.GO_VERSION}}
1518
stable: true
1619
- name: Benchmark
1720
run: |

.github/workflows/translations.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Translations Validation
2+
on:
3+
pull_request:
4+
paths:
5+
- "translations/**"
6+
env:
7+
GOPROXY: https://proxy.golang.org
8+
GO_VERSION: 1.16.4
9+
jobs:
10+
unit_test:
11+
runs-on: ubuntu-20.04
12+
steps:
13+
- uses: actions/checkout@v2
14+
- uses: actions/setup-go@v2
15+
with:
16+
go-version: ${{env.GO_VERSION}}
17+
stable: true
18+
- name: Install libvirt
19+
run: |
20+
sudo apt-get update
21+
sudo apt-get install -y libvirt-dev
22+
- name: Download Dependencies
23+
run: go mod download
24+
- name: Unit Test
25+
env:
26+
TESTSUITE: unittest
27+
run: make test
28+
continue-on-error: false

hack/update/golang_version/update_golang_version.go

+14-14
Original file line numberDiff line numberDiff line change
@@ -45,39 +45,39 @@ const (
4545

4646
var (
4747
schema = map[string]update.Item{
48-
".github/workflows/iso.yml": {
48+
".github/workflows/build.yml": {
4949
Replace: map[string]string{
50-
`go-version: '.*`: `go-version: '{{.StableVersion}}'`,
50+
`GO_VERSION: '.*`: `GO_VERSION: '{{.StableVersion}}'`,
5151
},
5252
},
53-
".github/workflows/kic_image.yml": {
53+
".github/workflows/master.yml": {
5454
Replace: map[string]string{
55-
`go-version: '.*`: `go-version: '{{.StableVersion}}'`,
55+
`GO_VERSION: '.*`: `GO_VERSION: '{{.StableVersion}}'`,
5656
},
5757
},
58-
".github/workflows/build.yml": {
58+
".github/workflows/pr.yml": {
5959
Replace: map[string]string{
60-
`go-version: '.*`: `go-version: '{{.StableVersion}}'`,
60+
`GO_VERSION: '.*`: `GO_VERSION: '{{.StableVersion}}'`,
6161
},
6262
},
63-
".github/workflows/master.yml": {
63+
".github/workflows/docs.yml": {
6464
Replace: map[string]string{
65-
`go-version: '.*`: `go-version: '{{.StableVersion}}'`,
65+
`GO_VERSION: '.*`: `GO_VERSION: '{{.StableVersion}}'`,
6666
},
6767
},
68-
".github/workflows/pr.yml": {
68+
".github/workflows/time-to-k8s.yml": {
6969
Replace: map[string]string{
70-
`go-version: '.*`: `go-version: '{{.StableVersion}}'`,
70+
`GO_VERSION: '.*`: `GO_VERSION: '{{.StableVersion}}'`,
7171
},
7272
},
73-
".github/workflows/docs.yml": {
73+
".github/workflows/translations.yml": {
7474
Replace: map[string]string{
75-
`go-version: '.*`: `go-version: '{{.StableVersion}}'`,
75+
`GO_VERSION: '.*`: `GO_VERSION: '{{.StableVersion}}'`,
7676
},
7777
},
78-
".github/workflows/time-to-k8s.yml": {
78+
".github/workflows/pr_verified.yaml": {
7979
Replace: map[string]string{
80-
`go-version: '.*`: `go-version: '{{.StableVersion}}'`,
80+
`GO_VERSION: '.*`: `GO_VERSION: '{{.StableVersion}}'`,
8181
},
8282
},
8383
".travis.yml": {

pkg/minikube/translate/translate_test.go

+83
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ limitations under the License.
1717
package translate
1818

1919
import (
20+
"encoding/json"
21+
"os"
22+
"path/filepath"
23+
"regexp"
24+
"sort"
2025
"testing"
2126

2227
"golang.org/x/text/language"
@@ -97,3 +102,81 @@ func TestT(t *testing.T) {
97102
})
98103
}
99104
}
105+
106+
func TestTranslationFilesValid(t *testing.T) {
107+
languageFiles, err := filepath.Glob("../../../translations/*.json")
108+
if err != nil {
109+
t.Fatalf("failed to get translation files: %v", err)
110+
}
111+
for _, filename := range languageFiles {
112+
lang := filepath.Base(filename)
113+
t.Run(lang, func(t *testing.T) {
114+
contents, err := os.ReadFile(filename)
115+
if err != nil {
116+
t.Fatalf("unable to read file %s: %v", filename, err)
117+
}
118+
119+
// check if JSON is valid
120+
if valid := json.Valid(contents); !valid {
121+
t.Fatalf("%s does not contain valid json", filename)
122+
}
123+
124+
// convert file into map
125+
var entries map[string]string
126+
if err := json.Unmarshal(contents, &entries); err != nil {
127+
t.Fatalf("could not unmarshal file %s: %v", filename, err)
128+
}
129+
130+
// for each line
131+
for k, v := range entries {
132+
// if no translation, skip
133+
if v == "" {
134+
continue
135+
}
136+
137+
// get all variables (ex. {{.name}})
138+
keyVariables := distinctVariables(k)
139+
valueVariables := distinctVariables(v)
140+
141+
// check if number of original string and translated variables match
142+
if len(keyVariables) != len(valueVariables) {
143+
t.Errorf("line %q: %q has mismatching number of variables\noriginal string variables: %s; translated variables: %s", k, v, keyVariables, valueVariables)
144+
continue
145+
}
146+
147+
// for each variable in the original string
148+
for i, keyVar := range keyVariables {
149+
// check if translated string has same variable
150+
if keyVar != valueVariables[i] {
151+
t.Errorf("line %q: %q has mismatching variables\noriginal string variables: %s do not match translated variables: %s", k, v, keyVariables, valueVariables)
152+
break
153+
}
154+
}
155+
}
156+
})
157+
}
158+
}
159+
160+
func distinctVariables(line string) []string {
161+
re := regexp.MustCompile(`{{\..+?}}`)
162+
163+
// get all the variables from the string (possiible duplicates)
164+
variables := re.FindAllString(line, -1)
165+
distinctMap := make(map[string]bool)
166+
167+
// add them to a map to get distinct list of variables
168+
for _, variable := range variables {
169+
distinctMap[variable] = true
170+
}
171+
distinct := []string{}
172+
173+
// convert map into slice
174+
for k := range distinctMap {
175+
distinct = append(distinct, k)
176+
}
177+
178+
// sort the slice to make the comparison easier
179+
sort.Strings(distinct)
180+
181+
return distinct
182+
}

translations/de.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@
252252
"Failed to save config {{.profile}}": "",
253253
"Failed to save dir": "",
254254
"Failed to save stdin": "",
255-
"Failed to set NO_PROXY Env. Please use `export NO_PROXY=$NO_PROXY,{{.ip}}": "NO_PROXY Env konnte nicht festgelegt werden. Benutzen Sie `export NO_PROXY = $ NO_PROXY, {{. Ip}}",
255+
"Failed to set NO_PROXY Env. Please use `export NO_PROXY=$NO_PROXY,{{.ip}}": "NO_PROXY Env konnte nicht festgelegt werden. Benutzen Sie `export NO_PROXY = $ NO_PROXY, {{.ip}}",
256256
"Failed to set NO_PROXY Env. Please use `export NO_PROXY=$NO_PROXY,{{.ip}}`.": "",
257257
"Failed to setup certs": "",
258258
"Failed to start container runtime": "",
@@ -576,7 +576,7 @@
576576
"Target directory {{.path}} must be an absolute path": "",
577577
"Target {{.path}} can not be empty": "",
578578
"Test docs have been saved at - {{.path}}": "",
579-
"The \"{{.driver_name}}\" driver requires root privileges. Please run minikube using 'sudo minikube --vm-driver={{.driver_name}}": "Der Treiber \"{{.driver_name}}\" benötigt Root-Rechte. Führen Sie minikube aus mit 'sudo minikube --vm-driver = {{. Driver_name}}.",
579+
"The \"{{.driver_name}}\" driver requires root privileges. Please run minikube using 'sudo minikube --vm-driver={{.driver_name}}": "Der Treiber \"{{.driver_name}}\" benötigt Root-Rechte. Führen Sie minikube aus mit 'sudo minikube --vm-driver = {{.driver_name}}.",
580580
"The \"{{.driver_name}}\" driver should not be used with root privileges.": "",
581581
"The \"{{.name}}\" cluster has been deleted.": "Der Cluster \"{{.name}}\" wurde gelöscht.",
582582
"The \"{{.name}}\" cluster has been deleted.__1": "Der Cluster \"{{.name}}\" wurde gelöscht.",
@@ -714,7 +714,7 @@
714714
"Unable to load config: {{.error}}": "Konfig kann nicht geladen werden: {{.error}}",
715715
"Unable to load host": "",
716716
"Unable to load profile: {{.error}}": "",
717-
"Unable to parse \"{{.kubernetes_version}}\": {{.error}}": "\"{{.Kubernetes_version}}\" kann nicht geparst werden: {{.error}}",
717+
"Unable to parse \"{{.kubernetes_version}}\": {{.error}}": "\"{{.kubernetes_version}}\" kann nicht geparst werden: {{.error}}",
718718
"Unable to parse default Kubernetes version from constants: {{.error}}": "",
719719
"Unable to parse memory '{{.memory}}': {{.error}}": "",
720720
"Unable to parse oldest Kubernetes version from constants: {{.error}}": "",
@@ -943,4 +943,4 @@
943943
"{{.profile}} profile is not valid: {{.err}}": "",
944944
"{{.type}} is not yet a supported filesystem. We will try anyways!": "",
945945
"{{.url}} is not accessible: {{.error}}": ""
946-
}
946+
}

translations/es.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"\"{{.context}}\" context has been updated to point to {{.hostname}}:{{.port}}": "El contexto \"{{.context}}\" ha sido actualizado para apuntar a {{.hostname}}:{{.port}}",
44
"\"{{.machineName}}\" does not exist, nothing to stop": "\"{{.machineName}}\" no existe, nada para detener.",
55
"\"{{.name}}\" profile does not exist": "El perfil \"{{.name}}\" no existe.",
6-
"\"{{.name}}\" profile does not exist, trying anyways.": "El perfil \"{.name}\" no existe, intentando de todas formas.",
6+
"\"{{.name}}\" profile does not exist, trying anyways.": "El perfil \"{{.name}}\" no existe, intentando de todas formas.",
77
"'none' driver does not support 'minikube docker-env' command": "El controlador 'none' no soporta el comando 'minikube docker-env'.",
88
"'none' driver does not support 'minikube mount' command": "El driver 'none' no soporta el comando 'minikube mount'.",
99
"'none' driver does not support 'minikube podman-env' command": "El controlador 'none' no soporta el comando 'minikube podman-env'.",
@@ -40,7 +40,7 @@
4040
"Add machine IP to NO_PROXY environment variable": "Agregar una IP de máquina a la variable de entorno NO_PROXY",
4141
"Add, delete, or push a local image into minikube": "Agrega, elimina, o empuja una imagen local dentro de minikube, haciendo (add, delete, push) respectivamente.",
4242
"Add, remove, or list additional nodes": "Usa (add, remove, list) para agregar, eliminar o listar nodos adicionales.",
43-
"Adding node {{.name}} to cluster {{.cluster}}": "Agregando el nodo {{.name}} al cluster.",
43+
"Adding node {{.name}} to cluster {{.cluster}}": "Agregando el nodo {{.name}} al cluster {{.cluster}}.",
4444
"Additional help topics": "Temas de ayuda adicionales",
4545
"Additional mount options, such as cache=fscache": "Opciones de montaje adicionales, por ejemplo cache=fscache",
4646
"Adds a node to the given cluster config, and starts it.": "Agrega un nodo a la configuración de cluster dada e iniciarlo.",
@@ -947,4 +947,4 @@
947947
"{{.profile}} profile is not valid: {{.err}}": "",
948948
"{{.type}} is not yet a supported filesystem. We will try anyways!": "",
949949
"{{.url}} is not accessible: {{.error}}": ""
950-
}
950+
}

0 commit comments

Comments
 (0)