From 9cdbfb18edab982f9e340a2b811a77001cc71a29 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Thu, 30 Apr 2020 14:06:59 +0200 Subject: [PATCH] bin/update: Also update `.github/stats.json` --- bin/update | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/bin/update b/bin/update index 4ac72fce..578b33f1 100755 --- a/bin/update +++ b/bin/update @@ -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