#!/usr/bin/env bash #SPDX-FileCopyrightText: 2023 HackerNCoder #SPDX-License-Identifier: MIT-0 declare -A langnames=( ["es_419"]="spanish" ["pt_BR"]="brazilian_portuguese" ["ru"]="russian" ["pl"]="polish" ) declare -a filesToDo for file in ./translations-*.po; do stats=$(msgfmt --statistics ${file} 2>&1) numdone=$(echo ${stats%* translated*}) if [[ $numdone -le 5400 ]]; then echo -e "\x1B[36mSKIPPING ${file#\.\/} since it has less than 5400 strings translated\x1B[0m" continue fi if (( $(date -d $(awk '/PO-Revision-Date/{ sub(/\+.*/,""); print $2"T"$3}' ${file}) +%s) < $CI_PREV_PIPELINE_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) done if (( ${#filesToDo[@]} > 0 )); then echo echo -e "\x1B[36m---------------------" echo "| INSTALLING |" echo -e "---------------------\x1B[0m" echo apt-get install --no-install-recommends -y git ca-certificates python3 libgl1 zip echo echo -e "\x1B[36m---------------------" echo "| CLONING |" echo -e "---------------------\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_CLONE_URL} ./game-source echo echo -e "\x1B[36m--------------------" echo "| BUILDING |" echo -e "--------------------\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 -e "\x1B[36m--------------------" echo "| DONE |" echo -e "--------------------\x1B[0m" echo else echo -e "\x1B[36mNothing to do\x1B[0m" fi