-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
release.sh
executable file
·98 lines (77 loc) · 2.71 KB
/
release.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/bin/sh
set -e
set -x
ROOT=$PWD
OUTPUT=$ROOT/build
LCONVERT_BIN=${LCONVERT_BIN:-lconvert}
LRELEASE_BIN=${LRELEASE_BIN:-lrelease}
LUPDATE_BIN=${LUPDATE_BIN:-lupdate}
if [ ! -d $OUTPUT ]
then
mkdir $OUTPUT
fi
echo "Cleaning old .qm files..."
rm -f $OUTPUT/*
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
echo " \"file_type\" : \"MMC-TRANSLATION-INDEX\"," >> $OUTPUT/index_v2.json
echo " \"version\" : 2," >> $OUTPUT/index_v2.json
echo " \"languages\" : {" >> $OUTPUT/index_v2.json
echo "Creating .qm files..."
FIRST=true
for ts_file in $(ls *.ts)
do
echo "Considering ${ts_file}"
lang="${ts_file%.ts}"
po_file="${lang}.po"
$LCONVERT_BIN -locations absolute "$ts_file" -o "$po_file"
if cat "${po_file}" | grep '\"X-Qt-Contexts: true\\n\"' > /dev/null ; then
echo "Translation ${po_file} is OK"
else
echo "Translation ${po_file} is bad (missing X-Qt-Contexts)"
exit 1
fi
if [ "$lang" = "pt" ]; then
lang="pt_PT"
fi
echo " Create $lang.qm"
$LRELEASE_BIN $ts_file -qm $OUTPUT/$lang.qm
SHA1=`sha1sum $OUTPUT/$lang.qm | awk '{ print $1 }'`
FILENAME="${SHA1}.class"
cp "$OUTPUT/$lang.qm" "$OUTPUT/$FILENAME"
# 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`
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\?')
FILESIZE=$(stat -c%s "$OUTPUT/$lang.qm")
if [ "$FIRST" = true ]; then
FIRST=false
else
# close previous scope
echo " }," >> $OUTPUT/index_v2.json
fi
echo " \"$lang\" : {" >> $OUTPUT/index_v2.json
echo " \"file\" : \"$FILENAME\"," >> $OUTPUT/index_v2.json
echo " \"sha1\" : \"$SHA1\"," >> $OUTPUT/index_v2.json
echo " \"size\" : $FILESIZE," >> $OUTPUT/index_v2.json
echo " \"translated\" : $TRANSLATED," >> $OUTPUT/index_v2.json
echo " \"fuzzy\" : $FUZZY," >> $OUTPUT/index_v2.json
echo " \"untranslated\" : $UNTRANSLATED" >> $OUTPUT/index_v2.json
# Create an index file with just the files (legacy)
echo "$lang.qm" >> $OUTPUT/index
rm "$po_file"
done
echo " }" >> $OUTPUT/index_v2.json
echo " }" >> $OUTPUT/index_v2.json
echo "}" >> $OUTPUT/index_v2.json
echo "All done!"