翻译

如何添加翻译

所有翻译都存储在顶级的 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

注意:clean 是必需的,以重新生成嵌入的 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.

最后修改日期:2023 年 3 月 29 日:使用 $LANGUAGE 更改 minikube 输出语言 (ea35c614a)