bin/update: Also update `.github/stats.json`

This commit is contained in:
Johannes Meyer 2020-04-30 14:06:59 +02:00
parent 8f9bd936c6
commit 9cdbfb18ed
1 changed files with 42 additions and 0 deletions

View File

@ -100,12 +100,54 @@ if [ $CHANGES -eq 0 ]; then
echo "No new messages found.";
git checkout icinga.pot;
else
STATS=""
# Update intermediate (in-progress) catalogs
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
msgmerge --update --backup=none --lang=$locale_name --sort-by-file $locale_name/LC_MESSAGES/icinga.po icinga.pot
STATS_OUT=$(LC_ALL=C msgfmt --statistics $locale_name/LC_MESSAGES/icinga.po 2>&1 >/dev/null)
if [ -f "messages.mo" ]; then
rm "messages.mo"
fi
# TODO: Make this a function? (is also used in bin/validate)
TRANSLATED=0
UNTRANSLATED=0
FUZZY=0
RE="[0-9]+"
LAST_LINE=$(echo "$STATS_OUT" | 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
PROGRESS=$(python -c "print (int(round(($TRANSLATED.0 / ($TRANSLATED + $UNTRANSLATED + $FUZZY)) * 100)))")
STATS+=" $locale_name:$PROGRESS%"
done
# Update locale statistics
python -c "import json; \
print ( \
json.dumps({k: v for k, v in (kv for kv in (s.split(':') for s in '$STATS'.strip().split()))}) \
) \
" > ../.github/stats.json
echo "New messages found!";
# Working tree is left dirty as the following step creates a new pull request
fi