#!/bin/sh
##########################################################################
# OpenLP - Open Source Lyrics Projection                                 #
# ---------------------------------------------------------------------- #
# Copyright (c) 2008-2024 OpenLP Developers                              #
# ---------------------------------------------------------------------- #
# 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 <https://www.gnu.org/licenses/>. #
##########################################################################
#
# This script automates the update of the translations on OpenLP.
#
# It uses the tx client from Transifex for all the heavy lifting
# All download *.ts files are converted to *.qm files which are used by
# OpenLP.
#
###############################################################################
pwd=`pwd`
result=${PWD##*/}; echo $result

if [ $result != 'scripts' ] ; then
	echo 'This script must be run from the scripts directory'
	exit
fi

echo $pwd
echo
echo Generation translation control file
echo
rm ../resources/i18n/*.ts

echo
echo Creating base translation file
echo
./translation_raw_generate.sh

echo
echo Remove empty translation files
echo
find ../resources/i18n -type f -name *.xml -size 78c -delete

echo
echo Merge Trannslation file
echo
./translation_merge.py ../resources/i18n/*.xml > ../resources/i18n/en_ts.txt


echo
echo Add header and trailer
echo
cat ./translation_head.txt ../resources/i18n/en_ts.txt ./translation_tail.txt > ../resources/i18n/en.ts


echo
echo Remove all xml files
echo
rm ../resources/i18n/*.xml

echo Check of invalid characters in push file
grep -axv '.*' ../resources/i18n/en.ts

tx push -s

echo New translation file pushed.

