Improve transifex sync script a bit.
[xonotic/xonotic-data.pk3dir.git] / tx.sh
1 #!/bin/sh
2
3 # We store:
4 #   .tx/merge-base - changed whenever translations get merged
5
6 mergebase=`git log --pretty=oneline -1 .tx/merge-base | cut -d ' ' -f 1`
7
8 set -e
9
10 # Update the .pot.
11 sh check-translations.sh pot
12
13 # First upload our current .pot.
14 mkdir -p translations/xonotic.commonpot/
15 cp common.pot translations/xonotic.commonpot/en..po
16 tx push -s
17
18 # Then pull the rest.
19 tx pull -f -a
20
21 for f in common.*.po; do
22         lang=${f%.po}
23         lang=${lang#common.}
24         tcurfile=translations/xonotic.commonpot/$lang..po
25         goldfile=translations/xonotic.commonpot/$lang..po.orig
26         gnewfile=common.$lang.po
27         if [ -f "$tcurfile" ]; then
28                 git show "$mergebase":"$gnewfile" > "$goldfile"
29                 msgmerge -F -U "$tcurfile" common.pot
30                 msgmerge -F -U "$goldfile" common.pot
31                 msgmerge -F -U "$gnewfile" common.pot
32                 if diff -u "$goldfile" "$gnewfile" >/dev/null; then
33                         # no change on git, changed on tx only
34                         msgmerge -F -U "$tcurfile" common.pot
35                         cp "$tcurfile" "$gnewfile"
36                 else
37                         if ! diff -u "$goldfile" "$gnewfile" | patch "$tcurfile"; then
38                                 while :; do
39                                         vim -o "$tcurfile.rej" "$tcurfile"
40                                         echo "OK?"
41                                         read -r OK || exit 1
42                                         [ x"$OK" != x"y" ] || break
43                                 done
44                                 rm -f "$tcurfile.rej"
45                         fi
46                         msgmerge -F -U "$tcurfile" common.pot
47                         cp "$tcurfile" "$gnewfile"
48                 fi
49                 rm "$goldfile"
50         else
51                 msgmerge -F -U "$gnewfile" common.pot
52                 cp "$gnewfile" "$tcurfile"
53         fi
54 done
55 for f in translations/xonotic.commonpot/*..po; do
56         lang=${f%..po}
57         lang=${lang#translations/xonotic.commonpot/}
58         [ x"$lang" != x"en" ] || continue
59         tcurfile=translations/xonotic.commonpot/$lang..po
60         gnewfile=common.$lang.po
61         if ! [ -f "$gnewfile" ]; then
62                 touch "$gnewfile"
63                 git add "$gnewfile"
64                 cp "$tcurfile" "$gnewfile"
65         fi
66 done
67 tx push -t --skip
68 date > .tx/merge-base
69
70 # Build new languages list.
71 sh check-translations.sh txt > languages.txt.new
72 mv languages.txt.new languages.txt
73
74 # Report stats.
75 git diff --stat
76 git diff --color-words languages.txt