Fix up 'download-po' a bit, so that we find new translations for languages that aren...
[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 if ! diff --version 2>/dev/null >/dev/null; then
20   echo "==== You must have the 'diff' program installed for this script ===="
21   exit 1
22 fi
23
24 # check for 'wget' program
25 if ! wget --version 2>/dev/null >/dev/null; then
26   echo "==== You must have the 'wget' program installed for this script ===="
27   exit 1
28 fi
29
30 # make sure we're in the top-level directory
31 if [ ! -d ./po ]; then
32   echo "==== No ./po directory in the current working directory ===="
33   exit 1
34 fi
35
36 # make sure a package argument was passed to us
37 if [ -z "$1" ]; then
38   echo "Usage: $0 PACKAGE, e.g. $0 gst-plugins-good"
39   exit 1
40 fi
41
42 if test "$1" != "gstreamer" -a \
43         "$1" != "gst-plugins-base" -a \
44         "$1" != "gst-plugins-good" -a \
45         "$1" != "gst-plugins-ugly" -a \
46         "$1" != "gst-plugins-bad"; then
47   echo "Unexpected package '$1' ?!"
48   exit 1
49 fi
50
51 PACKAGE="$1"
52
53 DOMAINS_TO_ADD=""
54 DOMAINS_UPDATED=""
55
56 echo "Downloading latest translation files for package $PACKAGE ..."
57 echo
58
59 for d in $DOMAINS
60 do
61   PACKAGE_PO_URL_BASE="http://translationproject.org/latest/$PACKAGE"
62   PO_URL="$PACKAGE_PO_URL_BASE/$d.po"
63   PO_FILENAME="$PACKAGE.$d.po"
64   if ! wget -q -O $PO_FILENAME $PO_URL 2>/dev/null >/dev/null; then
65     rm -f $PO_FILENAME
66     echo "$d.po: failure (does probably not exist)"
67   else
68     if [ -f "po/$d.po" ]; then
69       # ./po/foo.po exists, so let's check if ours matches the latest from the
70       # translation project website 
71       if diff $PO_FILENAME "po/$d.po" >/dev/null; then
72         echo "$d.po: up-to-date"
73         rm -f $PO_FILENAME
74       else
75         mv $PO_FILENAME "po/$d.po"
76         echo "$d.po: updated"
77         DOMAINS_UPDATED="$DOMAINS_UPDATED $d"
78       fi
79     else
80       # ./po/foo.po does exists, but foo.po exists on the translation project
81       # website, so it's probably a new translation
82       echo "$d.po: new language"
83       mv $PO_FILENAME "po/$d.po"
84       DOMAINS_UPDATED="$DOMAINS_UPDATED $d"
85       DOMAINS_TO_ADD="$DOMAINS_TO_ADD $d"
86     fi
87   fi
88 done
89
90 if [ -n "$DOMAINS_UPDATED" ]; then
91   echo "===================================================================="
92   echo
93   echo "Language domains updated    :$DOMAINS_UPDATED"
94   echo "Language domains to cvs add :$DOMAINS_TO_ADD"
95   echo
96   echo "Source: http://translationproject.org/latest/$PACKAGE/"
97   echo
98   if [ -n "$DOMAINS_TO_ADD" ]; then
99     CMD_STRING="cvs add"
100     for d in $DOMAINS_TO_ADD; do
101       CMD_STRING="$CMD_STRING po/$d.po"
102     done
103     echo "Please run"
104     echo
105     echo "  $CMD_STRING"
106     echo
107     echo "now."
108     echo
109   fi
110   echo "===================================================================="
111 fi
112
113