diff options
author | Kissaki <kissaki@gmx.de> | 2015-04-11 21:31:48 +0300 |
---|---|---|
committer | Kissaki <kissaki@gmx.de> | 2015-04-12 01:02:37 +0300 |
commit | d0f6b965ddfc8d5a79192b8e517f6f16ace8ef02 (patch) | |
tree | 55fec10c497a5384011afdd1a48ec7d43eee2632 /scripts/updatetranslations.sh | |
parent | f6aa3cf95bb9916307dec18354527bce6daaf2ba (diff) |
Make script for updating translation strings more robust
Diffstat (limited to 'scripts/updatetranslations.sh')
-rwxr-xr-x | scripts/updatetranslations.sh | 103 |
1 files changed, 89 insertions, 14 deletions
diff --git a/scripts/updatetranslations.sh b/scripts/updatetranslations.sh index 2fa7c4864..5581ee358 100755 --- a/scripts/updatetranslations.sh +++ b/scripts/updatetranslations.sh @@ -1,23 +1,98 @@ #! /bin/bash # Updates mumble_en.ts from source and adds a commit. -# Expects to be executed in src/mumble/ +# +# The main actions this script performs: +# * lupdate to update translation strings +# * Duplicate single 'numerusform' entries in mumble_en.ts to work around #1195 +# * Commit the resulting translation file +# +# Requires qt5 ; sudo apt-get install libqt5-dev +# As the QT project files are parsed, additional qt dependencies apply; +# sudo apt-get install libqt5svg5-dev + +set -u +set -e + file="mumble_en.ts" +dir="`dirname $0`/../src/mumble" +# Make sure we are using +export QT_SELECT=5 +tmpfile="commitmessage.tmp" + +function requireCommand +{ + local c=$1 + command -v $c >/dev/null 2>&1 || { printError "The required command $c is not available." >&2; exit 1; } +} + +function checkRequirements +{ + requireCommand lupdate + requireCommand qmake + requireCommand perl + requireCommand git +} + +function printError +{ + echo -e "\e[1;31mERROR\e[0m: $1" +} + +function fatal +{ + local msg="${1:-"Exiting because a command returned the error code $code"}" + + printError "$msg" + exit 1 +} + +function main +{ + checkRequirements + + if ! [[ -f "$dir/$file" ]]; + then + printError "Could not find file '${file}'." + exit 1 + fi + + pushd "$dir" >/dev/null + trap 'code=$? ; popd >/dev/null; exit $code' INT TERM EXIT + + if [[ -n $(git status --porcelain $file) ]] ; then + printError "The file $file has local changes." + exit 1 + fi + + echo "Translation update" > $tmpfile + echo "" >> $tmpfile + + lupdate -no-ui-lines -disable-heuristic similartext -locations relative -no-obsolete mumble.pro -ts $file | tee -a $tmpfile || fatal "lupdate failed" + echo + + # Duplicate single numerusform entries in mumble_en.ts to work around #1195 + perl -pi -e 's!(^\s*)(<numerusform></numerusform>)$!\1\2\2!' $file || (rm $tmpfile ; fatal "Workardound for #1195 failed - in-place replacement via perl.") + + + if ! [[ -n $(git status --porcelain $file) ]] ; then + echo "No translation changes. Nothing to commit." + rm $tmpfile + exit 0 + fi -if ! [ -f $file ]; -then - echo "Could not find $file . Aborted." - exit 1 -fi; + echo "Committing changes ..." + git commit -F $tmpfile $file || (rm $tmpfile ; fatal "Failed to commit the changes") + rm $tmpfile || printError "Failed to remove temporary file '$tmpfile'" -echo "Translation update" > commitmessage.tmp -echo "" >> commitmessage.tmp -lupdate -no-ui-lines -disable-heuristic similartext -locations relative -no-obsolete mumble.pro -ts $file | tee -a commitmessage.tmp + echo "Probably done." + echo + echo "Before pushing, _manually_ check the output above as well as the commits changes." + echo "An lupdate warning about overriding TRANSLATIONS is expected, as well as \"removal of plural forms\". Any project errors (missing qt modules) however are not, and the resulting changes must not be pushed." -# Duplicate single numerusform entries in mumble_en.ts to work around #1195 -perl -pi.bak -e 's!(^\s*)(<numerusform></numerusform>)$!\1\2\2!' $file + popd >/dev/null + trap - INT TERM EXIT +} -git commit -F commitmessage.tmp $file -rm commitmessage.tmp +main -echo "Probably done. Please _manually_ check the commit before pushing" |