Don't try to dist shave files that have been removed
[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     # we want all .po files in UTF-8 format really, so convert if needed..
68     CHARSET=`grep Content-Type $PO_FILENAME | sed -e 's/.*charset=\(.*\)\\\\n.*/\1/'`
69     if test "x$CHARSET" != "xUTF-8" -a "x$CHARSET" != "xutf-8"; then
70       # note: things like the bugs address will be added back by make update-po
71       if msguniq $PO_FILENAME --no-location \
72                               --output-file=$PO_FILENAME.utf8 \
73                               --to-code=UTF-8; then
74         mv $PO_FILENAME.utf8 $PO_FILENAME
75       else
76         echo "**** $d: conversion from $CHARSET to UTF-8 failed ****"
77       fi
78     fi
79     if [ -f "po/$d.po" ]; then
80       # ./po/foo.po exists, so let's check if ours matches the latest from the
81       # translation project website
82       REVDATE_NEW=`grep PO-Revision-Date $PO_FILENAME`;
83       REVDATE_OLD=`grep PO-Revision-Date po/$d.po`;
84       CHARSET_OLD=`grep Content-Type po/$d.po | sed -e 's/.*charset=\(.*\)\\\\n.*/\1/'`
85       if test "x$REVDATE_NEW" = "x$REVDATE_OLD" -a "x$CHARSET_OLD" = "xUTF-8"; then
86         # note: source code line markers will be removed later by make upload-po
87         echo "$d.po: up-to-date"
88         rm -f $PO_FILENAME
89       else
90         mv $PO_FILENAME "po/$d.po"
91         if test "x$CHARSET_OLD" != "xUTF-8" -a "x$CHARSET_OLD" != "xutf-8"; then
92           echo "$d.po: update (and charset converted from $CHARSET_OLD to UTF-8)"
93         else
94           echo "$d.po: updated"
95         fi
96         DOMAINS_UPDATED="$DOMAINS_UPDATED $d"
97       fi
98     else
99       # ./po/foo.po doesn't exist, but foo.po exists on the translation project
100       # website, so it's probably a new translation
101       echo "$d.po: new language"
102       mv $PO_FILENAME "po/$d.po"
103       DOMAINS_UPDATED="$DOMAINS_UPDATED $d"
104       DOMAINS_TO_ADD="$DOMAINS_TO_ADD $d"
105     fi
106   else
107     rm -f $PO_FILENAME
108     echo "$d.po: failure (does probably not exist)"
109   fi
110 done
111
112 if [ -n "$DOMAINS_UPDATED" ]; then
113   echo "===================================================================="
114   echo
115   echo "Language domains updated    :$DOMAINS_UPDATED"
116   echo "Language domains to git add :$DOMAINS_TO_ADD"
117   echo
118   echo "Source: http://translationproject.org/latest/$PACKAGE/"
119   echo
120   if [ -n "$DOMAINS_TO_ADD" ]; then
121     CMD_STRING="git add"
122     for d in $DOMAINS_TO_ADD; do
123       CMD_STRING="$CMD_STRING po/$d.po"
124     done
125     echo "Please run"
126     echo
127     echo "  $CMD_STRING"
128     echo
129     echo "now and add the following domains to the po/LINGUAS file:"
130     echo
131     echo "  $DOMAINS_TO_ADD"
132     echo
133     echo
134   fi
135   echo "===================================================================="
136 fi
137
138