+# Get translations.
+
+get_translations() {
+ subdir=$1
+ domain=$2
+ po_file=$3
+
+ echo "$0: getting translations into $subdir for $domain..."
+
+ case $po_file in
+ '') (cd $subdir && rm -f dummy `ls | sed -n '/\.gmo$/p; /\.po/p'`);;
+ esac &&
+
+ $WGET_COMMAND -O "$subdir/$domain.html" "$TP_URL$domain" &&
+
+ sed -n 's|.*"http://[^"]*/translation/teams/PO/\([^/"]*\)/'"$domain"'-\([^/"]*\)\.[^."]*\.po".*|\1.\2|p' <"$subdir/$domain.html" |
+ sort -k 1,1 -k 2,2n -k2,2 -k3,3n -k3,3 -k4,4n -k4,4 -k5,5n -k5.5 |
+ awk -F. '
+ { if (lang && $1 != lang) print lang, ver }
+ { lang = $1; ver = substr($0, index($0, ".") + 1) }
+ END { if (lang) print lang, ver }
+ ' |
+ awk -v domain="$domain" -v po_file="$po_file" -v subdir="$subdir" '
+ {
+ lang = $1
+ if (po_file && po_file != (lang ".po")) next
+
+ # Work around bugs in translations uncovered by gettext 0.15.
+ # This workaround can be removed once the translations are fixed.
+ if (lang == "hu" || lang == "zh_TW") next
+
+ ver = $2
+ urlfmt = ""
+ printf "$WGET_COMMAND -O %s/%s.po 'http://www.iro.umontreal.ca/translation/teams/PO/%s/%s-%s.%s.po' &&\n", subdir, lang, lang, domain, ver, lang
+ }
+ END { print ":" }
+ ' |
+ sh &&
+ ls "$subdir"/*.po | sed 's|.*/||; s|\.po$||' >"$subdir/LINGUAS" &&
+ rm "$subdir/$domain.html"
+}
+
+update_po() {
+ if [ $# = 1 ]; then
+ case $1 in
+ *.po) POFILE=$1;;
+ *) POFILE=${1}.po;;
+ esac
+ get_translations po $package "$POFILE"
+ else
+ get_translations po $package
+ fi
+}
+
+case $DOWNLOAD_PO in
+no) ;;
+*)
+ case `wget --help` in
+ *'--no-cache'*)
+ no_cache='--no-cache';;
+ *'--cache=on/off'*)
+ no_cache='--cache=off';;
+ *)
+ no_cache='';;
+ esac
+
+ WGET_COMMAND="wget -nv $no_cache"
+ export WGET_COMMAND
+esac
+
+case $DOWNLOAD_PO in
+only) update_po
+ exit
+ ;;
+no|yes) ;;
+*) update_po $DOWNLOAD_PO
+ exit
+esac
+