Add bin/validate

This commit is contained in:
Johannes Meyer 2020-04-29 15:37:36 +02:00
parent ec2dcc986b
commit 426fcaf7aa
1 changed files with 56 additions and 0 deletions

56
bin/validate Executable file
View File

@ -0,0 +1,56 @@
#!/bin/bash
FAIL=0
LOCALES=$(find . -mindepth 1 -maxdepth 1 -type d -regextype grep -regex '\./[a-z]\{2\}_[A-Z]\{2\}' -printf "%P ")
for locale_name in $LOCALES; do
echo "Checking locale $locale_name"
OUTPUT=$(LC_ALL=C msgfmt -cvf --statistics $locale_name/LC_MESSAGES/icinga.po 2>&1 >/dev/null)
ECODE=$?
if [ -f "messages.mo" ]; then
rm "messages.mo"
fi
echo "$OUTPUT"
if [ $ECODE -gt 0 ]; then
FAIL=1
fi
TRANSLATED=0
UNTRANSLATED=0
FUZZY=0
RE="[0-9]+"
LAST_LINE=$(echo "$OUTPUT" | tail -1)
for chars in $LAST_LINE; do
if [[ "$chars" =~ $RE ]] && [[ ${BASH_REMATCH[0]} ]]; then
LAST_CNT="${BASH_REMATCH[0]}"
else
case $chars in
"translated")
TRANSLATED=$LAST_CNT
;;
"fuzzy")
FUZZY=$LAST_CNT
;;
"untranslated")
UNTRANSLATED=$LAST_CNT
;;
esac
fi
done
if [ $FUZZY -gt 0 ]; then
echo "$locale_name still contains $FUZZY fuzzy messages"
FAIL=1
fi
PROGRESS=$(python -c "print (int(round(($TRANSLATED.0 / ($TRANSLATED + $UNTRANSLATED + $FUZZY)) * 100)))")
echo "$locale_name is at $PROGRESS%"
echo
done
exit $FAIL