#!/bin/bash
# ALR - Any Linux Repository
# Copyright (C) 2025 Евгений Храмов
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see .
TRANSLATIONS_DIR="internal/translations/po"
if [ ! -d "$TRANSLATIONS_DIR" ]; then
echo "Error: directory '$TRANSLATIONS_DIR' not found"
exit 1
fi
declare -A TOTAL_STRINGS_MAP
declare -A TRANSLATED_STRINGS_MAP
for PO_FILE in $(find "$TRANSLATIONS_DIR" -type f -name "*.po"); do
LANG_DIR=$(dirname "$PO_FILE")
LANG=$(basename "$LANG_DIR")
STATS=$(LC_ALL=C msgfmt --statistics -o /dev/null "$PO_FILE" 2>&1)
NUMBERS=($(echo "$STATS" | grep -o '[0-9]\+'))
case ${#NUMBERS[@]} in
1) TRANSLATED_STRINGS=${NUMBERS[0]}; UNTRANSLATED_STRINGS=0 ;; # all translated
2) TRANSLATED_STRINGS=${NUMBERS[0]}; UNTRANSLATED_STRINGS=${NUMBERS[1]} ;; # no fuzzy
3) TRANSLATED_STRINGS=${NUMBERS[0]}; UNTRANSLATED_STRINGS=${NUMBERS[2]} ;; # with fuzzy
*) TRANSLATED_STRINGS=0; UNTRANSLATED_STRINGS=0 ;;
esac
TOTAL_STRINGS=$((TRANSLATED_STRINGS + UNTRANSLATED_STRINGS))
TOTAL_STRINGS_MAP[$LANG]=$((TOTAL_STRINGS_MAP[$LANG] + TOTAL_STRINGS))
TRANSLATED_STRINGS_MAP[$LANG]=$((TRANSLATED_STRINGS_MAP[$LANG] + TRANSLATED_STRINGS))
done
for LANG in "${!TOTAL_STRINGS_MAP[@]}"; do
TOTAL=${TOTAL_STRINGS_MAP[$LANG]}
TRANSLATED=${TRANSLATED_STRINGS_MAP[$LANG]}
if [ "$TOTAL" -eq 0 ]; then
PERCENTAGE="0.00"
else
PERCENTAGE=$(echo "scale=2; ($TRANSLATED / $TOTAL) * 100" | bc)
fi
COLOR="#4c1"
if (( $(echo "$PERCENTAGE < 50" | bc -l) )); then
COLOR="#e05d44"
elif (( $(echo "$PERCENTAGE < 80" | bc -l) )); then
COLOR="#dfb317"
fi
cat < assets/i18n-$LANG-badge.svg
EOF
done