update-translations.sh: add fix translations option (-k)

This commit is contained in:
atiratree 2021-05-17 20:05:21 +02:00
parent 079d8aeb1e
commit 66dbfbce10

View File

@ -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 <file-path>: 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