Minor fixes to merge-from-transifex.sh
[gpodder.git] / po / merge-from-transifex.sh
blob946fc9bc2402ce97872e1abcd9e89e73e3f288c6
1 #!/usr/bin/env bash
3 # merge-from-transifex.sh
4 # Fix problems with the "tx" command line client by forcing a download of
5 # all translations and then using the downloaded translations as a compendium
6 # in msgmerge to update the .po file without destroying existing content.
7 # ..which I think is what the "tx" client should do all along?! :/
9 # Thomas Perl <thp.io/about>; 2012-01-21
12 MERGE_DIR=_tmp_merge_dir
13 MESSAGES_POT=messages.pot
15 if [ "`which tx`" == "" ]; then
16 echo "The Transifex client 'tx' was not found."
17 echo "If you are on Debian: apt-get install transifex-client"
18 exit 1
21 if [ "`which git`" == "" ]; then
22 echo "Please install 'git'. We need it to revert changes by 'tx' ;)"
23 exit 1
26 cd `dirname $0`
28 if git status --porcelain | grep -q '^ M po'; then
29 echo "Uncommitted changes in po/ - cannot continue."
30 echo "Please revert or commit current changes before continuing."
31 exit 1
34 if [ -d "$MERGE_DIR" ]; then
35 echo "The directory $MERGE_DIR still exists. Please remove it."
36 exit 1
39 # First, pull translations from Transifex, overwriting existing .po files
40 echo "Downloading UPDATED translations from Transifex..."
41 tx pull --force
43 FILES=`git status --porcelain |
44 grep '^ M po/.*.po$' |
45 awk '{ print $2 }' |
46 cut -d/ -f3`
48 echo "`echo $FILES | wc -w` files changed by 'tx'."
50 if [ "$FILES" != "" ]; then
51 echo "Moving files to merge directory..."
52 mkdir "$MERGE_DIR"
53 mv -v $FILES "$MERGE_DIR"
56 echo "Restoring original .po files from Git..."
57 git checkout .
59 echo "Merging translations..."
61 for POFILE in $FILES; do
62 echo -n "Merging $POFILE"
63 msgmerge --compendium="$MERGE_DIR/$POFILE" \
64 "$POFILE" "$MESSAGES_POT" --output-file="$POFILE"
65 done
67 echo "Removing merge directory..."
68 rm -rf "$MERGE_DIR"
70 # To finish things off, fetch new translations from the server
71 echo "Downloading NEW translations from Transifex..."
72 tx pull --all --disable-overwrite
74 echo "Running validation script to check for errors..."
75 sh validate.sh
77 echo "All done. Please review changes and stage them for commmit."