|
| 1 | +#!/bin/bash |
| 2 | +# Update the translation files with strings used in QGIS |
| 3 | +# 1. create a clean Qt .pro file for the project |
| 4 | +# 2. run lupdate using the .pro file from step 1 |
| 5 | +# 3. remove the .pro |
| 6 | +# Note the .pro file must NOT be named qgis.pro as this |
| 7 | +# name is reserved for the Windows qmake project file |
| 8 | +# $Id$ |
| 9 | + |
| 10 | +set -e |
| 11 | + |
| 12 | +cleanup() { |
| 13 | + if [ -f i18n/qgis_ts.tar ]; then |
| 14 | + echo Restoring excluded translations |
| 15 | + tar -xf i18n/qgis_ts.tar |
| 16 | + fi |
| 17 | + |
| 18 | + echo Removing temporary files |
| 19 | + perl -i.bak -ne 'print unless /^\s+<location.*python-i18n\.cpp.*$/;' i18n/qgis_*.ts |
| 20 | + for i in \ |
| 21 | + python/python-i18n.{ts,cpp} \ |
| 22 | + python/plugins/*/python-i18n.{ts,cpp} \ |
| 23 | + i18n/qgis_*.ts.bak \ |
| 24 | + src/plugins/grass/grasslabels-i18n.cpp \ |
| 25 | + i18n/qgis_ts.tar \ |
| 26 | + qgis_ts.pro |
| 27 | + do |
| 28 | + [ -f "$i" ] && rm "$i" |
| 29 | + done |
| 30 | + |
| 31 | + for i in \ |
| 32 | + src/plugins/plugin_template/plugingui.cpp \ |
| 33 | + src/plugins/plugin_template/plugin.cpp |
| 34 | + do |
| 35 | + [ -f "$i.save" ] && mv "$i.save" "$i" |
| 36 | + done |
| 37 | +} |
| 38 | + |
| 39 | +trap cleanup EXIT |
| 40 | + |
| 41 | +PATH=$QTDIR/bin:$PATH |
| 42 | + |
| 43 | +exclude= |
| 44 | +opts= |
| 45 | +while (( $# > 0 )); do |
| 46 | + arg=$1 |
| 47 | + shift |
| 48 | + |
| 49 | + if [ "$arg" = "-a" ]; then |
| 50 | + arg=$1 |
| 51 | + shift |
| 52 | + if [ -f "i18n/qgis_$arg.ts" ]; then |
| 53 | + echo "cannot add existing translation $arg" |
| 54 | + exit 1 |
| 55 | + else |
| 56 | + add="$add $arg" |
| 57 | + fi |
| 58 | + elif [ -f "i18n/qgis_$arg.ts" ]; then |
| 59 | + exclude="$exclude --exclude i18n/qgis_$arg.ts" |
| 60 | + else |
| 61 | + opts="$opts $arg" |
| 62 | + fi |
| 63 | +done |
| 64 | + |
| 65 | +if [ -n "$exclude" -o -n "$add" ]; then |
| 66 | + echo Saving excluded translations |
| 67 | + tar --remove-files -cf i18n/qgis_ts.tar i18n/qgis_*.ts$exclude |
| 68 | +fi |
| 69 | +echo Updating python translations |
| 70 | +cd python |
| 71 | +pylupdate4 console.py utils.py -ts python-i18n.ts |
| 72 | +perl ../scripts/ts2cpp.pl python-i18n.ts python-i18n.cpp |
| 73 | +rm python-i18n.ts |
| 74 | +cd .. |
| 75 | +for i in python/plugins/*/CMakeLists.txt; do |
| 76 | + cd ${i%/*} |
| 77 | + pylupdate4 $(find . -name "*.py" -o -name "*.ui") -ts python-i18n.ts |
| 78 | + perl ../../../scripts/ts2cpp.pl python-i18n.ts python-i18n.cpp |
| 79 | + rm python-i18n.ts |
| 80 | + cd ../../.. |
| 81 | +done |
| 82 | +echo Updating GRASS module translations |
| 83 | +perl scripts/qgm2cpp.pl >src/plugins/grass/grasslabels-i18n.cpp |
| 84 | +mv src/plugins/plugin_template/plugingui.cpp src/plugins/plugin_template/plugingui.cpp.save |
| 85 | +echo Creating qmake project file |
| 86 | +for i in \ |
| 87 | + src/plugins/plugin_template/plugingui.cpp \ |
| 88 | + src/plugins/plugin_template/plugin.cpp |
| 89 | +do |
| 90 | + [ -f "$i" ] && mv "$i" "$i.save" |
| 91 | +done |
| 92 | +qmake-qt4 -project -o qgis_ts.pro -nopwd src python i18n |
| 93 | +if [ -n "$add" ]; then |
| 94 | + for i in $add; do |
| 95 | + echo "Adding translation for $i" |
| 96 | + echo "TRANSLATIONS += i18n/qgis_$i.ts" >> qgis_ts.pro |
| 97 | + done |
| 98 | +fi |
| 99 | +echo Updating translations |
| 100 | +lupdate-qt4$opts -verbose qgis_ts.pro |
| 101 | + |
| 102 | +if [ -n "$add" ]; then |
| 103 | + for i in $add; do |
| 104 | + if [ -f i18n/qgis_$i.ts ]; then |
| 105 | + git add i18n/qgis_$i.ts |
| 106 | + else |
| 107 | + echo "Translaiton for $i was not added" |
| 108 | + exit 1 |
| 109 | + fi |
| 110 | + done |
| 111 | +fi |
0 commit comments