翻译
如何添加翻译
所有翻译都存储在顶层的 translations
目录中。
添加新语言
- 在 translations 目录中添加一个新的 json 文件,使用您要添加翻译的语言的语言代码,例如法语使用 fr。
~/minikube$ touch translations/fr.json
~/minikube$ ls translations/
de.json es.json fr.json ja.json ko.json pl.json zh-CN.json
- 从根目录运行
make extract
,以 json 格式填充该文件,其中包含要翻译的字符串。
~/minikube$ make extract
go run cmd/extract/extract.go
Compiling translation strings...
Writing to de.json
Writing to es.json
Writing to fr.json
Writing to ja.json
Writing to ko.json
Writing to pl.json
Writing to zh-CN.json
Done!
- 将翻译后的字符串添加到 json 文件中,作为映射的值,其中英文短语是键。
~/minikube$ head translations/fr.json
{
"\"The '{{.minikube_addon}}' addon is disabled": "",
"\"{{.machineName}}\" does not exist, nothing to stop": "",
"\"{{.name}}\" profile does not exist, trying anyways.": "",
"'none' driver does not support 'minikube docker-env' command": "",
"'none' driver does not support 'minikube mount' command": "",
"'none' driver does not support 'minikube podman-env' command": "",
"'none' driver does not support 'minikube ssh' command": "",
"'{{.driver}}' driver reported an issue: {{.error}}": "",
- 将翻译添加到映射的值中,请记住,双大括号
{{}}
中的任何内容都是描述注入内容的变量名,不应翻译。
~/minikube$ vi translations/fr.json
{
[...]
"Amount of time to wait for a service in seconds": "",
"Amount of time to wait for service in seconds": "",
"Another hypervisor, such as VirtualBox, is conflicting with KVM. Please stop the other hypervisor, or use --driver to switch to it.": "",
"Automatically selected the {{.driver}} driver": "Choix automatique du driver {{.driver}}",
"Automatically selected the {{.driver}} driver. Other choices: {{.alternates}}": "Choix automatique du driver {{.driver}}. Autres choix: {{.alternatives}}",
"Available Commands": "",
"Basic Commands:": "",
"Because you are using docker driver on Mac, the terminal needs to be open to run it.": "",
[...]
}
为现有语言添加翻译
- 运行
make extract
以确保所有字符串都是最新的 - 以与上述描述相同的方式,编辑 “translations” 目录中的相应 json 文件。
测试翻译
-
您可以通过运行以下命令来验证翻译在语法上是否有效:
go test k8s.io/minikube/pkg/minikube/translate
-
一旦您拥有所有需要的翻译,请保存该文件并从头开始重新构建 minikube,以获取您的新翻译
~/minikube$ make clean
rm -rf ./out
rm -f pkg/minikube/assets/assets.go
rm -f pkg/minikube/translate/translations.go
rm -rf ./vendor
~/minikube$ make
注意:需要执行清理操作以重新生成嵌入的 translations.go
文件
-
现在,您在
out
目录中有一个全新的 minikube 二进制文件。如果您的系统语言环境与您添加翻译的语言相同,则简单的out/minikube start
将作为测试工作,前提是您翻译了minikube start
中的短语。 您可以以这种方式使用您想要的任何命令。 -
如果您有不同的系统语言环境,可以使用 LANGUAGE 环境变量覆盖打印的语言
~/minikube$ LANGUAGE=fr out/minikube start
😄 minikube v1.29.0 sur Ubuntu 18.04
✨ Choix automatique du pilote docker. Autres choix: kvm2, ssh
📌 Utilisation du pilote Docker avec le privilège root
👍 Démarrage du noeud de plan de contrôle minikube dans le cluster minikube
🚜 Extraction de l'image de base...
🔥 Création de docker container (CPUs=2, Memory=7900Mo) ...
🐳 Préparation de Kubernetes v1.26.1 sur Docker 20.10.23...
▪ Génération des certificats et des clés
▪ Démarrage du plan de contrôle ...
▪ Configuration des règles RBAC ...
🔗 Configuration de bridge CNI (Container Networking Interface)...
▪ Utilisation de l'image gcr.io/k8s-minikube/storage-provisioner:v5
🔎 Vérification des composants Kubernetes...
🌟 Modules activés: storage-provisioner, default-storageclass
🏄 Terminé ! kubectl est maintenant configuré pour utiliser "minikube" cluster et espace de noms "default" par défaut.