#!/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 "Ошибка: директория '$TRANSLATIONS_DIR' не найдена"
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")
TOTAL_STRINGS=$(grep -c "^msgid " "$PO_FILE")
TRANSLATED_STRINGS=$(grep -c "^msgstr \"[^\"]\+\"" "$PO_FILE")
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