Skip to content

Instantly share code, notes, and snippets.

@ekohl
Last active January 23, 2023 13:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ekohl/124ec5ccf28709d3ee2789e37718650b to your computer and use it in GitHub Desktop.
Save ekohl/124ec5ccf28709d3ee2789e37718650b to your computer and use it in GitHub Desktop.
#!/bin/bash
PLUGIN="${1:-.}"
WEBPACK="${PLUGIN}/webpack"
LOCALE="${PLUGIN}/locale"
# These options have too many problems
#WHITESPACE=(-t endwhitespace -t endpunc -t puncspacing)
WHITESPACE=()
LANGUAGES="es fr ja zh_CN pt_BR"
EXIT=0
if [[ -d "$WEBPACK" ]] ; then
# This is supposed to catch __(``)
# It's never valid to perform string interpolation; instead sprintf should be used
if grep '_(`' -R "${WEBPACK}" ; then
echo "[ERROR] Found Javascript string interpolation in translated strings" > /dev/stderr
EXIT=$((EXIT + 1))
fi
fi
if [[ -d "$LOCALE" ]] ; then
DOMAIN=$(basename "${LOCALE}"/*.pot .pot)
for lang in $LANGUAGES ; do
file="${LOCALE}/${lang}/${DOMAIN}.po"
if [[ -e $file ]] ; then
msgfmt -c "$file"
pofilter --progress none --nofuzzy -t variables -t blank -t urls -t emails -t long -t newlines -t options -t printf -t validchars "${WHITESPACE[@]}" --gnome "$file" | tee "${file}x"
if grep -q msgid "${file}x" ; then
echo "[ERROR] Language ${lang} contains errors" > /dev/stderr
EXIT=$((EXIT + 1))
fi
# Doesn't print multi line strings in full
if msgattrib --untranslated --no-fuzzy "${file}" | grep -v 'msgid ""' | grep msgid ; then
echo "[ERROR] Language ${lang} is missing translations" > /dev/stderr
EXIT=$((EXIT + 1))
fi
else
echo "[ERROR] Missing translations for ${lang}" > /dev/stderr
EXIT=$((EXIT + 1))
fi
done
else
echo "[ERROR] Locale directory is missing" > /dev/stderr
EXIT=$((EXIT + 1))
fi
exit $EXIT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment