summaryrefslogtreecommitdiff
path: root/common/download-translations
blob: aef1d31550eef981514e6c782255be6a16f65c7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/bin/sh
# Shell script to download the latest translations for a given GStreamer
# package from translationproject.org


# DOMAINS based on http://translationproject.org/extra/matrix.html
# We need to check all domains, not only po/LINGUAS, since there might be
# new translations
DOMAINS=\
"af am ar az be bg pt_BR bs ca zh_CN cs cy da de el eo es et eu fa fi fr "\
"ga en_GB gl gu he hi zh_HK hr hu id is it ja ko ku ky lg lt lv mk mn ms "\
"mt nb ne nl nn or pa pl pt rm ro ru rw sk sl sq sr sv ta tq th tk "\
"tr zh_TW uk ven vi wa xh zu"

# for testing/debugging:
#DOMAINS="es fr hu sv pl xx"

# check for 'diff' program
diff --version 2>/dev/null >/dev/null
if [ ! $? ]; then
  echo "==== You must have the 'diff' program installed for this script ===="
  exit 1
fi

# check for 'wget' program
wget --version 2>/dev/null >/dev/null
if [ ! $? ]; then
  echo "==== You must have the 'wget' program installed for this script ===="
  exit 1
fi

# make sure we're in the top-level directory
if [ ! -d ./po ]; then
  echo "==== No ./po directory in the current working directory ===="
  exit 1
fi

# make sure a package argument was passed to us
if [ -z "$1" ]; then
  echo "Usage: $0 PACKAGE, e.g. $0 gst-plugins-good"
  exit 1
fi

if test "$1" != "gstreamer" -a \
        "$1" != "gst-plugins-base" -a \
        "$1" != "gst-plugins-good" -a \
        "$1" != "gst-plugins-ugly" -a \
        "$1" != "gst-plugins-bad"; then
  echo "Unexpected package '$1' ?!"
  exit 1
fi

PACKAGE="$1"

DOMAINS_TO_ADD=""
DOMAINS_UPDATED=""
DOMAINS_NOT_IN_LINGUAS=""

echo "Downloading latest translation files for package $PACKAGE ..."
echo

for d in $DOMAINS
do
  PACKAGE_PO_URL_BASE="http://translationproject.org/latest/$PACKAGE"
  PO_URL="$PACKAGE_PO_URL_BASE/$d.po"
  PO_FILENAME="$PACKAGE.$d.po"
  if wget -q -nc -O $PO_FILENAME $PO_URL; then
    # we want all .po files in UTF-8 format really, so convert if needed..
    CHARSET=`grep Content-Type $PO_FILENAME | sed -e 's/.*charset=\(.*\)\\\\n.*/\1/'`
    if test "x$CHARSET" != "xUTF-8" -a "x$CHARSET" != "xutf-8"; then
      # note: things like the bugs address will be added back by make update-po
      if msguniq $PO_FILENAME --no-location \
                              --output-file=$PO_FILENAME.utf8 \
                              --to-code=UTF-8; then
        mv $PO_FILENAME.utf8 $PO_FILENAME
      else
        echo "**** $d: conversion from $CHARSET to UTF-8 failed ****"
      fi
    fi
    if [ -f "po/$d.po" ]; then
      # ./po/foo.po exists, so let's check if ours matches the latest from the
      # translation project website
      REVDATE_NEW=`grep PO-Revision-Date $PO_FILENAME`;
      REVDATE_OLD=`grep PO-Revision-Date po/$d.po`;
      CHARSET_OLD=`grep Content-Type po/$d.po | sed -e 's/.*charset=\(.*\)\\\\n.*/\1/'`
      if test "x$REVDATE_NEW" = "x$REVDATE_OLD" -a "x$CHARSET_OLD" = "xUTF-8"; then
        # note: source code line markers will be removed later by make upload-po
        echo "$d.po: up-to-date"
        rm -f $PO_FILENAME
      else
        mv $PO_FILENAME "po/$d.po"
        if test "x$CHARSET_OLD" != "xUTF-8" -a "x$CHARSET_OLD" != "xutf-8"; then
          echo "$d.po: update (and charset converted from $CHARSET_OLD to UTF-8)"
        else
          echo "$d.po: updated"
        fi
        DOMAINS_UPDATED="$DOMAINS_UPDATED $d"
      fi
      # make sure domain is listed in LINGUAS
      if ! grep $d "po/LINGUAS" >/dev/null 2>/dev/null; then
        DOMAINS_NOT_IN_LINGUAS="$DOMAINS_NOT_IN_LINGUAS $d"
      fi
    else
      # ./po/foo.po doesn't exist, but foo.po exists on the translation project
      # website, so it's probably a new translation
      echo "$d.po: new language"
      mv $PO_FILENAME "po/$d.po"
      DOMAINS_UPDATED="$DOMAINS_UPDATED $d"
      DOMAINS_TO_ADD="$DOMAINS_TO_ADD $d"
    fi
  else
    rm -f $PO_FILENAME
    echo "$d.po: failure (does probably not exist)"
  fi
done

if [ -n "$DOMAINS_UPDATED" ]; then
  echo "===================================================================="
  echo
  echo "Language domains updated    :$DOMAINS_UPDATED"
  echo "Language domains to git add :$DOMAINS_TO_ADD"
  echo
  echo "Source: http://translationproject.org/latest/$PACKAGE/"
  echo
  if [ -n "$DOMAINS_TO_ADD" ]; then
    CMD_STRING="git add"
    for d in $DOMAINS_TO_ADD; do
      CMD_STRING="$CMD_STRING po/$d.po"
    done
    echo "Please run"
    echo
    echo "  $CMD_STRING"
    echo
    echo "now and add the following domains to the po/LINGUAS file:"
    echo
    echo "  $DOMAINS_TO_ADD"
    echo
    echo
  fi
  echo "===================================================================="
fi

if [ -n "$DOMAINS_NOT_IN_LINGUAS" ]; then
  echo
  echo "Existing domains missing from the po/LINGUAS file:"
  echo
  echo "  $DOMAINS_NOT_IN_LINGUAS"
  echo
  echo
fi