i18n: Fix bug where package-level variables are not translated.

The call to `i18n.LoadTranslations` needs to occur on init so
that package-level variables that call `i18n.T()` to initialize
their values will be able to receive the translated string.

Added new integration tests to test help output translation.
This commit is contained in:
Brian Pursley 2022-11-21 22:48:42 -05:00
parent 3f823c0daa
commit 34d980e770
2 changed files with 384 additions and 308 deletions

View File

@ -83,8 +83,7 @@ if [[ "${generate_pot}" == "true" ]]; then
# shellcheck disable=SC2046 # shellcheck disable=SC2046
go-xgettext -k=i18n.T $(grep -lr "i18n.T" "${KUBECTL_FILES[@]}" | grep -vE "${KUBECTL_IGNORE_FILES_REGEX}") > tmp.pot go-xgettext -k=i18n.T $(grep -lr "i18n.T" "${KUBECTL_FILES[@]}" | grep -vE "${KUBECTL_IGNORE_FILES_REGEX}") > tmp.pot
perl -pi -e 's/CHARSET/UTF-8/' tmp.pot perl -pi -e 's/CHARSET/UTF-8/' tmp.pot
perl -pi -e 's/\\\(/\\\\\(/g' tmp.pot perl -pi -e 's/\\(?!n"\n|")/\\\\/g' tmp.pot
perl -pi -e 's/\\\)/\\\\\)/g' tmp.pot
kube::util::ensure-temp-dir kube::util::ensure-temp-dir
if msgcat -s tmp.pot > "${KUBE_TEMP}/template.pot"; then if msgcat -s tmp.pot > "${KUBE_TEMP}/template.pot"; then
mv "${KUBE_TEMP}/template.pot" "${TRANSLATIONS}/kubectl/template.pot" mv "${KUBE_TEMP}/template.pot" "${TRANSLATIONS}/kubectl/template.pot"