2014-09-06 12:10:02 -07:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
set -e
|
2021-01-09 07:40:12 -07:00
|
|
|
set -x
|
2014-09-06 12:10:02 -07:00
|
|
|
|
|
|
|
ROOT=$PWD
|
|
|
|
OUTPUT=$ROOT/build
|
|
|
|
|
2019-09-22 17:13:18 -07:00
|
|
|
LCONVERT_BIN=${LCONVERT_BIN:-lconvert}
|
|
|
|
LRELEASE_BIN=${LRELEASE_BIN:-lrelease}
|
|
|
|
LUPDATE_BIN=${LUPDATE_BIN:-lupdate}
|
|
|
|
|
2015-03-31 04:09:46 -07:00
|
|
|
|
2014-09-06 12:10:02 -07:00
|
|
|
if [ ! -d $OUTPUT ]
|
|
|
|
then
|
2018-12-16 18:10:37 -07:00
|
|
|
mkdir $OUTPUT
|
2014-09-06 12:10:02 -07:00
|
|
|
fi
|
|
|
|
|
2016-11-22 16:44:08 -07:00
|
|
|
echo "Cleaning old .qm files..."
|
|
|
|
rm -f $OUTPUT/*
|
|
|
|
|
2018-12-22 21:55:54 -07:00
|
|
|
grep_count()
|
|
|
|
{
|
|
|
|
local PIECE=`echo "$1" | grep -o "$2"`
|
|
|
|
if [ -n "$PIECE" ]; then
|
|
|
|
RETVAL=`echo $PIECE | sed 's/[a-z ]//g'`
|
|
|
|
echo $RETVAL
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
echo 0
|
|
|
|
}
|
|
|
|
|
|
|
|
echo "{" >> $OUTPUT/index_v2.json
|
2018-12-22 22:21:12 -07:00
|
|
|
echo " \"file_type\" : \"MMC-TRANSLATION-INDEX\"," >> $OUTPUT/index_v2.json
|
2018-12-22 21:55:54 -07:00
|
|
|
echo " \"version\" : 2," >> $OUTPUT/index_v2.json
|
|
|
|
echo " \"languages\" : {" >> $OUTPUT/index_v2.json
|
|
|
|
|
2014-09-06 12:10:02 -07:00
|
|
|
echo "Creating .qm files..."
|
2018-12-22 22:21:12 -07:00
|
|
|
|
|
|
|
FIRST=true
|
|
|
|
|
2014-09-06 12:10:02 -07:00
|
|
|
for po_file in $(ls *.po)
|
|
|
|
do
|
2018-12-16 18:10:37 -07:00
|
|
|
echo "Considering ${po_file}"
|
|
|
|
if cat "${po_file}" | grep '\"X-Qt-Contexts: true\\n\"' > /dev/null ; then
|
2018-12-08 19:52:24 -07:00
|
|
|
echo "Translation ${po_file} is OK"
|
2018-12-16 18:10:37 -07:00
|
|
|
else
|
2018-12-08 19:52:24 -07:00
|
|
|
echo "Translation ${po_file} is bad (missing X-Qt-Contexts)"
|
|
|
|
exit 1
|
2018-12-16 18:10:37 -07:00
|
|
|
fi
|
|
|
|
|
|
|
|
# gets everything up to the first dot
|
|
|
|
lang=$(echo $po_file | grep -oP "^[^\.]*")
|
2021-04-08 14:06:24 -07:00
|
|
|
if [ "$lang" = "en" ]; then
|
|
|
|
lang="en_GB"
|
|
|
|
fi
|
2018-12-16 18:10:37 -07:00
|
|
|
echo " Converting $po_file to $lang.ts"
|
|
|
|
$LCONVERT_BIN -locations relative $po_file -o $lang.ts
|
|
|
|
echo " Create $lang.qm"
|
|
|
|
$LRELEASE_BIN $lang.ts -qm $OUTPUT/$lang.qm
|
|
|
|
|
2018-12-27 19:36:21 -07:00
|
|
|
SHA1=`sha1sum $OUTPUT/$lang.qm | awk '{ print $1 }'`
|
|
|
|
FILENAME="${SHA1}.class"
|
|
|
|
cp "$OUTPUT/$lang.qm" "$OUTPUT/$FILENAME"
|
|
|
|
|
2018-12-16 18:10:37 -07:00
|
|
|
# Create an index file with info about the amount of strings translated and expected hashes of the files (for local caching purposes)
|
|
|
|
PO_STATS=`msgfmt --statistics --output=/dev/null ${po_file} 2>&1`
|
2018-12-22 21:55:54 -07:00
|
|
|
UNTRANSLATED=$(grep_count "$PO_STATS" '[0-9]\+ untranslated messages\?')
|
|
|
|
FUZZY=$(grep_count "$PO_STATS" '[0-9]\+ fuzzy translations\?')
|
|
|
|
TRANSLATED=$(grep_count "$PO_STATS" '[0-9]\+ translated messages\?')
|
2018-12-27 19:36:21 -07:00
|
|
|
|
2018-12-22 22:21:12 -07:00
|
|
|
FILESIZE=$(stat -c%s "$OUTPUT/$lang.qm")
|
2018-12-22 21:55:54 -07:00
|
|
|
|
2018-12-22 22:21:12 -07:00
|
|
|
if [ "$FIRST" = true ]; then
|
|
|
|
FIRST=false
|
|
|
|
else
|
|
|
|
# close previous scope
|
|
|
|
echo " }," >> $OUTPUT/index_v2.json
|
|
|
|
fi
|
2018-12-22 21:55:54 -07:00
|
|
|
echo " \"$lang\" : {" >> $OUTPUT/index_v2.json
|
2018-12-27 19:36:21 -07:00
|
|
|
echo " \"file\" : \"$FILENAME\"," >> $OUTPUT/index_v2.json
|
2018-12-22 21:55:54 -07:00
|
|
|
echo " \"sha1\" : \"$SHA1\"," >> $OUTPUT/index_v2.json
|
2018-12-22 22:21:12 -07:00
|
|
|
echo " \"size\" : $FILESIZE," >> $OUTPUT/index_v2.json
|
2018-12-22 21:55:54 -07:00
|
|
|
echo " \"translated\" : $TRANSLATED," >> $OUTPUT/index_v2.json
|
|
|
|
echo " \"fuzzy\" : $FUZZY," >> $OUTPUT/index_v2.json
|
2018-12-22 22:21:12 -07:00
|
|
|
echo " \"untranslated\" : $UNTRANSLATED" >> $OUTPUT/index_v2.json
|
2018-12-16 18:10:37 -07:00
|
|
|
# Create an index file with just the files (legacy)
|
|
|
|
echo "$lang.qm" >> $OUTPUT/index
|
2014-09-06 12:10:02 -07:00
|
|
|
done
|
2018-12-22 22:21:12 -07:00
|
|
|
echo " }" >> $OUTPUT/index_v2.json
|
2018-12-22 21:55:54 -07:00
|
|
|
echo " }" >> $OUTPUT/index_v2.json
|
|
|
|
echo "}" >> $OUTPUT/index_v2.json
|
2014-09-06 12:10:02 -07:00
|
|
|
|
|
|
|
echo "Removing intermediate files..."
|
|
|
|
rm *.ts
|
|
|
|
|
2014-09-06 15:39:32 -07:00
|
|
|
echo "All done!"
|