Whitespace cleanups
[platform/upstream/gst-common.git] / download-translations
1 #!/bin/sh
2 # Shell script to download the latest translations for a given GStreamer
3 # package from translationproject.org
4
5
6 # DOMAINS based on http://translationproject.org/extra/matrix.html
7 # We need to check all domains, not only po/LINGUAS, since there might be
8 # new translations
9 DOMAINS=\
10 "af am ar az be bg pt_BR bs ca zh_CN cs cy da de el eo es et eu fa fi fr "\
11 "ga en_GB gl gu he hi zh_HK hr hu id is it ja ko ku ky lg lt lv mk mn ms "\
12 "mt nb ne nl nn or pa pl pt rm ro ru rw sk sl sq sr sv ta tq th tk "\
13 "tr zh_TW uk ven vi wa xh zu"
14
15 # for testing/debugging:
16 #DOMAINS="es fr hu sv pl xx"
17
18 # check for 'diff' program
19 diff --version 2>/dev/null >/dev/null
20 if [ ! $? ]; then
21   echo "==== You must have the 'diff' program installed for this script ===="
22   exit 1
23 fi
24
25 # check for 'wget' program
26 wget --version 2>/dev/null >/dev/null
27 if [ ! $? ]; then
28   echo "==== You must have the 'wget' program installed for this script ===="
29   exit 1
30 fi
31
32 # make sure we're in the top-level directory
33 if [ ! -d ./po ]; then
34   echo "==== No ./po directory in the current working directory ===="
35   exit 1
36 fi
37
38 # make sure a package argument was passed to us
39 if [ -z "$1" ]; then
40   echo "Usage: $0 PACKAGE, e.g. $0 gst-plugins-good"
41   exit 1
42 fi
43
44 if test "$1" != "gstreamer" -a \
45         "$1" != "gst-plugins-base" -a \
46         "$1" != "gst-plugins-good" -a \
47         "$1" != "gst-plugins-ugly" -a \
48         "$1" != "gst-plugins-bad"; then
49   echo "Unexpected package '$1' ?!"
50   exit 1
51 fi
52
53 PACKAGE="$1"
54
55 DOMAINS_TO_ADD=""
56 DOMAINS_UPDATED=""
57
58 echo "Downloading latest translation files for package $PACKAGE ..."
59 echo
60
61 for d in $DOMAINS
62 do
63   PACKAGE_PO_URL_BASE="http://translationproject.org/latest/$PACKAGE"
64   PO_URL="$PACKAGE_PO_URL_BASE/$d.po"
65   PO_FILENAME="$PACKAGE.$d.po"
66   if wget -q -nc -O $PO_FILENAME $PO_URL; then
67     if [ -f "po/$d.po" ]; then
68       # ./po/foo.po exists, so let's check if ours matches the latest from the
69       # translation project website
70       if diff $PO_FILENAME "po/$d.po" >/dev/null; then
71         echo "$d.po: up-to-date"
72         rm -f $PO_FILENAME
73       else
74         mv $PO_FILENAME "po/$d.po"
75         echo "$d.po: updated"
76         DOMAINS_UPDATED="$DOMAINS_UPDATED $d"
77       fi
78     else
79       # ./po/foo.po doesn't exist, but foo.po exists on the translation project
80       # website, so it's probably a new translation
81       echo "$d.po: new language"
82       mv $PO_FILENAME "po/$d.po"
83       DOMAINS_UPDATED="$DOMAINS_UPDATED $d"
84       DOMAINS_TO_ADD="$DOMAINS_TO_ADD $d"
85     fi
86   else
87     rm -f $PO_FILENAME
88     echo "$d.po: failure (does probably not exist)"
89   fi
90 done
91
92 if [ -n "$DOMAINS_UPDATED" ]; then
93   echo "===================================================================="
94   echo
95   echo "Language domains updated    :$DOMAINS_UPDATED"
96   echo "Language domains to cvs add :$DOMAINS_TO_ADD"
97   echo
98   echo "Source: http://translationproject.org/latest/$PACKAGE/"
99   echo
100   if [ -n "$DOMAINS_TO_ADD" ]; then
101     CMD_STRING="cvs add"
102     for d in $DOMAINS_TO_ADD; do
103       CMD_STRING="$CMD_STRING po/$d.po"
104     done
105     echo "Please run"
106     echo
107     echo "  $CMD_STRING"
108     echo
109     echo "now and add the following domains to the po/LINGUAS file:"
110     echo
111     echo "  $DOMAINS_TO_ADD"
112     echo
113     echo
114   fi
115   echo "===================================================================="
116 fi
117
118