1#!/usr/bin/env bash
2
3PWD=`pwd`
4LOG=$PWD/update_ts_file.log
5
6PROCESSONLY=""
7if [ -n "$1" ]; then
8	PROCESSONLY="$1"
9	echo "Only processing \"$PROCESSONLY\"";
10fi
11
12XSLT_PROCESSOR=$(which saxon-xslt) || XSLT_PROCESSOR=$(which saxon8) || XSLT_PROCESSOR=$(which xt) || XSLT_PROCESSOR=saxon-xslt
13
14LUPDATE=$(which lupdate-qt5) || LUPDATE=$(which lupdate) || LUPDATE=$QTDIR/bin/lupdate
15
16if [ -z "$PROCESSONLY" ] || [ "$PROCESSONLY" = "kadu" ] || [ "$PROCESSONLY" = "kadu-core" ]; then
17	echo "Updating kadu-core translations"
18	echo > $LOG
19
20	# empty fake file
21	echo > ../kadu-core/.configuration-ui-translations.cpp
22	for i in `ls ../varia/configuration/*.ui`; do
23		$XSLT_PROCESSOR $i configuration-ui.xsl >> ../kadu-core/.configuration-ui-translations.cpp 2>> $LOG
24	done
25
26	# all .cpp files in kadu_core subdirectories
27	SRC_FILES=`find ../kadu-core/ -type f -name *.cpp`
28
29	for ts in *.ts; do
30		$LUPDATE  -qt=5 -locations none -noobsolete -verbose $SRC_FILES -ts $ts  >> $LOG 2>&1 || \
31		( rm $ts && $LUPDATE -locations none -noobsolete -verbose $SRC_FILES -ts $ts  >> $LOG 2>&1 )
32	done
33
34fi
35
36pushd ../plugins/ >> $LOG
37for PLUGIN in *; do
38	if [ ! -d $PLUGIN ]; then
39		continue
40	fi
41
42	if [ ! -f $PLUGIN/$PLUGIN.desc ]; then
43		continue;
44	fi
45
46	if [ -n "$PROCESSONLY" ] && [ "$PROCESSONLY" != "$PLUGIN" ]; then
47		continue;
48	fi
49
50	echo "Updating plugin $PLUGIN translations"
51
52	UI_TRANS=
53
54	pushd $PLUGIN >> $LOG 2>&1
55
56	if [ -d configuration ]; then
57		UI_TRANS=.configuration-ui-translations.cpp
58
59		pushd configuration >> $LOG 2>&1
60		echo > ../.configuration-ui-translations.cpp
61		for i in *.ui; do
62			$XSLT_PROCESSOR $i ../../../translations/configuration-ui.xsl >> ../.configuration-ui-translations.cpp 2>> $LOG
63		done
64		popd >> $LOG 2>&1
65	fi
66
67	if [ -x ./translations/extract-custom-strings.js ]; then
68		./translations/extract-custom-strings.js
69	fi
70
71	if [ -d data/configuration ]; then
72		UI_TRANS=.configuration-ui-translations.cpp
73
74		pushd data/configuration >> $LOG 2>&1
75		echo > ../.configuration-ui-translations.cpp
76		for i in *.ui; do
77			$XSLT_PROCESSOR $i ../../../../translations/configuration-ui.xsl >> ../../.configuration-ui-translations.cpp 2>> $LOG
78		done
79		popd >> $LOG 2>&1
80	fi
81
82	if [ ! -d translations ]; then
83		mkdir translations;
84	fi
85
86	SRC_FILES=`find . -type f -name "*.cpp"`
87
88	for TS in `ls translations/*.ts`; do
89		$LUPDATE  -qt=5 -locations none -noobsolete -verbose $SRC_FILES ${UI_TRANS} -ts $TS 2>> $LOG || \
90		( rm $TS && $LUPDATE -locations none -noobsolete -verbose $SRC_FILES ${UI_TRANS} -ts $TS 2>> $LOG )
91	done
92	if [ ! -f translations/${PLUGIN}_en.ts ]; then
93		$LUPDATE  -qt=5 -locations none -noobsolete -verbose $SRC_FILES ${UI_TRANS} -ts translations/${PLUGIN}_en.ts 2>> $LOG || \
94		( rm translations/${PLUGIN}_en.ts && $LUPDATE -locations none -noobsolete -verbose $SRC_FILES ${UI_TRANS} -ts translations/${PLUGIN}_en.ts 2>> $LOG )
95	fi
96
97	popd >> $LOG 2>&1
98done
99popd >> $LOG 2>&1
100