weblate-butterflysoup2/.po2tl.sh

73 lines
2.4 KiB
Bash
Raw Normal View History

2023-01-31 13:23:39 +00:00
#!/usr/bin/env bash
2023-02-11 02:31:58 +00:00
#SPDX-FileCopyrightText: 2023 HackerNCoder
#SPDX-License-Identifier: MIT-0
2023-01-31 13:23:39 +00:00
2023-01-31 13:59:28 +00:00
declare -A langnames=( ["es_419"]="spanish" ["pt_BR"]="brazilian_portuguese" ["ru"]="russian" ["pl"]="polish" )
2023-01-31 13:23:39 +00:00
declare -a filesToDo
2023-01-31 13:23:39 +00:00
for file in ./translations-*.po; do
2023-01-31 13:50:44 +00:00
stats=$(msgfmt --statistics ${file} 2>&1)
2023-01-31 13:23:39 +00:00
numdone=$(echo ${stats%* translated*})
if [[ $numdone -le 5400 ]]; then
echo -e "\x1B[36mSKIPPING ${file#\.\/} since it has less than 5400 strings translated\x1B[0m"
2023-01-31 13:23:39 +00:00
continue
fi
if (( $(date -d $(awk '/PO-Revision-Date/{ sub(/\+.*/,""); print $2"T"$3}' ${file}) +%s) < $CI_PREV_BUILD_STARTED )); then
echo -e "\x1B[36mSKIPPING ${file#\.\/} since it hasn't been changed since last CI\x1B[0m"
continue
fi
echo -e "\x1B[36mAdding ${file#\.\/} to list of files to build\x1B[0m"
filesToDo+=(file)
2023-01-31 13:23:39 +00:00
done
2023-08-17 17:34:26 +00:00
if (( ${#filesToDo[@]} > 0 )); then
2023-09-12 15:03:26 +00:00
echo
echo "\x1B[36m---------------------"
echo "| INSTALLING |"
echo "---------------------\x1B[0m"
echo
apt-get install --no-install-recommends -y git ca-certificates python3 libgl1 zip
echo
echo "\x1B[36m---------------------"
echo "| CLONING |"
echo "---------------------\x1B[0m"
echo
git clone https://lab.encryptionin.space/Queerscriptors/rttk-queerscriptors.git
git clone https://lab.encryptionin.space/Queerscriptors/renpy.git
git clone -b game ${CI_REPO_REMOTE} ./game-source
echo
echo "\x1B[36m--------------------"
echo "| BUILDING |"
echo "--------------------\x1B[0m"
echo
for file in filesToDo; do
file2=${file%.po}
langcc=${file2#\.\/translations\-}
if [[ -n ${langnames[$langcc]} ]]; then
lang=${langnames[$langcc]}
if [[ -f "/var/www/queer/build/${CI_REPO_NAME}/${langcc}.zip" ]]; then
rm "/var/www/queer/build/${CI_REPO_NAME}/${langcc}.zip"
fi
else
lang=$langcc
fi
echo -e "\x1B[36mBUILDING ${file#\.\/} \x1B[0m"
msgfmt "$file" -o game.mo
PATH=$(pwd)/renpy:${PATH} RENPY_DIR=$(pwd)/renpy python3 rttk-queerscriptors/mo2tl.py $(pwd)/game-source game.mo ${lang}
(cd game-source/game/tl/${lang} && zip -r "${lang}.zip" . && mv "${lang}.zip" "/var/www/queer/build/${CI_REPO_NAME}/${lang}.zip" )
echo -e "\e[32mFINISHED $file\e[0m"
echo
done
echo
echo "\x1B[36m--------------------"
echo "| DONE |"
echo "--------------------\x1B[0m"
echo
else
echo -e "\x1B[36mNothing to do\x1B[0m"
fi