Transifex autosync
[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 mode=$1
11 case "$mode" in
12         all)
13                 push_pot=true
14                 sync_po=true
15                 ;;
16         pot)
17                 push_pot=true
18                 sync_po=false
19                 ;;
20         po)
21                 push_pot=false
22                 sync_po=true
23                 ;;
24         *)
25                 echo "Usage: $0 [all|pot|po]"
26                 exit 1
27                 ;;
28 esac
29
30 if $push_pot; then
31         # Update the .pot.
32         sh check-translations.sh pot
33
34         # First upload our current .pot.
35         mkdir -p translations/xonotic.commonpot/
36         cp common.pot translations/xonotic.commonpot/en..po
37         tx push -s
38 fi
39
40 if $sync_po; then
41         # Then pull the rest.
42         tx pull -f -a
43
44         for f in common.*.po; do
45                 lang=${f%.po}
46                 lang=${lang#common.}
47                 case "$lang" in
48                         de_CH)
49                                 continue
50                                 ;;
51                 esac
52                 tcurfile=translations/xonotic.commonpot/$lang..po
53                 goldfile=translations/xonotic.commonpot/$lang..po.orig
54                 gnewfile=common.$lang.po
55                 if [ -f "$tcurfile" ]; then
56                         git show "$mergebase":"$gnewfile" > "$goldfile"
57                         msgmerge -N -F -U "$tcurfile" common.pot
58                         msgmerge -N -F -U "$goldfile" common.pot
59                         msgmerge -N -F -U "$gnewfile" common.pot
60                         if diff -u "$goldfile" "$gnewfile" >/dev/null; then
61                                 # no change on git, changed on tx only
62                                 msgmerge -N -F -U "$tcurfile" common.pot
63                                 cp "$tcurfile" "$gnewfile"
64                         else
65                                 if ! diff -u "$goldfile" "$gnewfile" | patch "$tcurfile"; then
66                                         if [ -z "$BATCH" ]; then
67                                                 while :; do
68                                                         vim -o "$tcurfile.rej" "$tcurfile"
69                                                         echo "OK?"
70                                                         read -r OK || exit 1
71                                                         [ x"$OK" != x"y" ] || break
72                                                 done
73                                                 rm -f "$tcurfile.rej"
74                                         fi
75                                 fi
76                                 msgmerge -N -F -U "$tcurfile" common.pot
77                                 cp "$tcurfile" "$gnewfile"
78                         fi
79                         rm "$goldfile"
80                 else
81                         msgmerge -N -F -U "$gnewfile" common.pot
82                         cp "$gnewfile" "$tcurfile"
83                 fi
84         done
85         for f in translations/xonotic.commonpot/*..po; do
86                 lang=${f%..po}
87                 lang=${lang#translations/xonotic.commonpot/}
88                 [ x"$lang" != x"en" ] || continue
89                 tcurfile=translations/xonotic.commonpot/$lang..po
90                 gnewfile=common.$lang.po
91                 if ! [ -f "$gnewfile" ]; then
92                         touch "$gnewfile"
93                         git add "$gnewfile"
94                         cp "$tcurfile" "$gnewfile"
95                 fi
96         done
97         tx push -t --skip
98         date > .tx/merge-base
99
100         # Generate Swiss Standard German from German.
101         msgfilter -i common.de.po -o common.de_CH.po perl -pe '
102                 # Character filters go here.
103                 s/ß/ss/g;
104                 # Word filters go here. By default we match even inside words, as there
105                 # are constructs like ^BGflag where "flag" is the actual word. Make
106                 # sure to not commit the clbuttical mistake.
107                 s/eventuell/allfällig/g;
108         '
109
110         # Build new languages list.
111         sh check-translations.sh txt > languages.txt.new
112         mv languages.txt.new languages.txt
113
114         # Report stats.
115         git diff --stat
116         git diff --color-words languages.txt
117 fi