diff --git a/hack/update-translations.sh b/hack/update-translations.sh index 52f14a9f6ca..bc5b4d6dbd1 100755 --- a/hack/update-translations.sh +++ b/hack/update-translations.sh @@ -31,13 +31,15 @@ KUBECTL_IGNORE_FILES_REGEX="cmd/kustomize/kustomize.go" generate_pot="false" generate_mo="false" +fix_translations="false" -while getopts "hf:xg" opt; do +while getopts "hf:xkg" opt; do case ${opt} in h) - echo "$0 [-f files] [-x] [-g]" + echo "$0 [-f files] [-x] [-k] [-g]" echo " -f : Files to process" echo " -x extract strings to a POT file" + echo " -k fix .po files; deprecate translations by marking them obsolete and supply default messages" echo " -g sort .po files and generate .mo files" exit 0 ;; @@ -47,6 +49,9 @@ while getopts "hf:xg" opt; do x) generate_pot="true" ;; + k) + fix_translations="true" + ;; g) generate_mo="true" ;; @@ -90,6 +95,23 @@ if [[ "${generate_pot}" == "true" ]]; then fi fi +if [[ "${fix_translations}" == "true" ]]; then + echo "Fixing .po files" + kube::util::ensure-temp-dir + for PO_FILE in translations/kubectl/*/LC_MESSAGES/k8s.po; do + TMP="${KUBE_TEMP}/fix.po" + if [[ "${PO_FILE}" =~ .*/default/.* || "${PO_FILE}" =~ .*/en_US/.* ]]; then + # mark obsolete, and set default values for english translations + msgen translations/kubectl/template.pot | \ + msgmerge -s --no-fuzzy-matching "${PO_FILE}" - > "${TMP}" + else + # mark obsolete, but do not add untranslated messages + msgmerge -s --no-fuzzy-matching "${PO_FILE}" translations/kubectl/template.pot | msgattrib --translated - > "${TMP}" + fi + mv "${TMP}" "${PO_FILE}" + done +fi + if [[ "${generate_mo}" == "true" ]]; then echo "Generating .po and .mo files" for x in "${TRANSLATIONS}"/*/*/*/*.po; do