-
Notifications
You must be signed in to change notification settings - Fork 136
/
update-strings.sh
executable file
·96 lines (87 loc) · 2.75 KB
/
update-strings.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
#!/bin/bash
LOCALES=$*
# get newest .py file
TR='tr' # Gettext alias marking translatable strings
NEWESTPY=0
PYTHONFILES=$(find . -name '*.py')
for PYTHONFILE in $PYTHONFILES
do
PYTHONFILEMOD=$(stat -c %Y $PYTHONFILE)
if [ $PYTHONFILEMOD -gt $NEWESTPY ]
then
NEWESTPY=$PYTHONFILEMOD
fi
done
# Gettext translation stuff
# for .po files by applying xgettext command
for LOCALE in $LOCALES
do
PODIR=safe/i18n/${LOCALE}/LC_MESSAGES
POPATH=${PODIR}/inasafe.po
# get modified date of .po file
LASTMODPOTIME=$(stat -c %Y $POPATH)
echo "Newst python file: $NEWESTPY Translation last update: $LASTMODPOTIME"
# only proceed if the po file is older than the newst py file
if [ $NEWESTPY -gt $LASTMODPOTIME ]
then
echo "Newest python file is newer than po file so updating strings"
# Keep the current field separator
oIFS=$IFS
PYFILES=$(egrep -r "ugettext" . | cut -f 1 -d ':' | grep 'py$' | sort | uniq | tr '\n' ' ')
echo 'Scanning $PYFILE for new strings'
#echo
echo $PODIR
echo $POPATH
# double brackets deal gracefully if path has spaces
if [[ ! -f $POPATH ]]
then
mkdir -p $PODIR
xgettext -j -d ${LOCALE} -o ${POPATH} ${PYFILES} -k${TR} --no-location
xgettext -j -d ${LOCALE} -o ${POPATH} ${PYFILES} -k${TR}
else
# Update translation file. Options:
# -a all strings
# -j update mode
# -k specify alias marking strings for translation
xgettext -j -d ${LOCALE} -o ${POPATH} ${PYFILES} -k${TR} --no-location
xgettext -j -d ${LOCALE} -o ${POPATH} ${PYFILES} -k${TR}
fi
# Spit out files that need to be edited
echo "$POPATH"
else
echo "No need to update $POPATH because no python files has been updated since the last update translation."
fi
done
# Qt translation stuff
# for .ts file
UPDATE=false
for LOCALE in $LOCALES
do
TSFILE="safe_qgis/i18n/inasafe_"$LOCALE".ts"
TSMODTIME=$(stat -c %Y $TSFILE)
if [ $NEWESTPY -gt $TSMODTIME ]
then
UPDATE=true
break
fi
done
if [ $UPDATE == true ]
# retrieve all python files in safe_qgis and realtime
then
python_safe_qgis=`find safe_qgis/ -regex ".*\(ui\|py\)$"`
python_realtime=`find realtime/ -regex ".*\(ui\|py\)$"`
# concat list of files
python_all="$python_safe_qgis $python_realtime"
# update .ts
echo "Please provide translations by editing the translation files below:"
for LOCALE in $LOCALES
do
echo "safe_qgis/i18n/inasafe_"$LOCALE".ts"
# Note we don't use pylupdate with qt .pro file approach as it is flakey
# about what is made available.
pylupdate4 -noobsolete $python_all -ts safe_qgis/i18n/inasafe_id.ts
done
else
echo "No need to edit any translation files (.ts) because no python files "
echo "has been updated since the last update translation. "
fi