[Tests] Test slug functionality, fix Slug ordering
[mygpo.git] / tools / i18n / merge-from-transifex.sh
blobf27e92a1db8ee331efd29d5c065b2e6b917a552a
1 #!/bin/sh
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 set -e
14 MERGE_DIR=../_tmp_merge_dir
15 MESSAGES_POT=en/LC_MESSAGES/django.po
17 if [ "`which tx`" = "" ]; then
18 echo "The Transifex client 'tx' was not found."
19 echo "If you are on Debian: apt-get install transifex-client"
20 exit 1
23 if [ "`which git`" = "" ]; then
24 echo "Please install 'git'. We need it to revert changes by 'tx' ;)"
25 exit 1
28 cd `dirname $0`/../../mygpo/locale
30 if git status --porcelain | grep -q '^ M po'; then
31 echo "Uncommitted changes in po/ - cannot continue."
32 echo "Please revert or commit current changes before continuing."
33 exit 1
36 rm */LC_MESSAGES/django.po
38 # restore english source language
39 git checkout en
41 if [ -d "$MERGE_DIR" ]; then
42 echo "The directory $MERGE_DIR still exists. Please remove it."
43 exit 1
46 # First, pull translations from Transifex, overwriting existing .po files
47 echo "Downloading UPDATED translations from Transifex..."
48 tx pull --force --all
50 echo "Moving files to merge directory..."
51 mkdir "$MERGE_DIR"
53 find -mindepth 1 -maxdepth 1 -not -name "en" -exec mv -v '{}' "$MERGE_DIR" \;
55 echo "Restoring original .po files from Git..."
56 git checkout .
58 echo "Merging translations..."
60 for POFILE in `find . -path ./en -prune -o -name django.po -print`; do
61 echo -n "Merging $POFILE"
62 msgmerge --compendium="$MERGE_DIR/$POFILE" \
63 "$POFILE" "$MESSAGES_POT" --output-file="$POFILE"
64 done
66 echo "Removing merge directory..."
67 rm -rf "$MERGE_DIR"
69 echo "Running validation script to check for errors..."
70 sh ../../tools/i18n/validate.sh
72 echo "All done. Please review changes and stage them for commmit."