- case $WGET_COMMAND in
- '')
- echo "$0: wget not available; skipping translations";;
- ?*)
- echo "$0: getting translations into $subdir for $domain..." &&
-
- (cd $subdir && rm -f dummy `ls | sed -n '/\.gmo$/p; /\.po/p'`) &&
- $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 subdir="$subdir" '
- {
- lang = $1
- ver = $2
- urlfmt = ""
- printf "{ $WGET_COMMAND -O %s/%s.po '\'"$TP_PO_URL"'/%s/%s-%s.%s.po'\'' &&\n", subdir, lang, lang, domain, ver, lang
- printf " msgfmt -c -o /dev/null %s/%s.po || {\n", subdir, lang
- printf " echo >&2 '\'"$0"': omitting translation for %s'\''\n", lang
- printf " rm -f %s/%s.po; }; } &&\n", subdir, lang
- }
- END { print ":" }
- ' | WGET_COMMAND="$WGET_COMMAND" sh;;
- esac &&
- ls "$subdir"/*.po 2>/dev/null |
- sed 's|.*/||; s|\.po$||' >"$subdir/LINGUAS" &&
- rm -f "$subdir/$domain.html"
+# Download .po files to $po_dir/.reference and copy only the new
+# or modified ones into $po_dir. Also update $po_dir/LINGUAS.
+update_po_files() {
+ # Directory containing primary .po files.
+ # Overwrite them only when we're sure a .po file is new.
+ po_dir=$1
+ domain=$2
+
+ # Download *.po files into this dir.
+ # Usually contains *.s1 checksum files.
+ ref_po_dir="$po_dir/.reference"
+
+ test -d $ref_po_dir || mkdir $ref_po_dir || return
+ download_po_files $ref_po_dir $domain \
+ && ls "$ref_po_dir"/*.po 2>/dev/null |
+ sed 's|.*/||; s|\.po$||' > "$po_dir/LINGUAS"
+
+ for po in `cd $ref_po_dir && echo *.po|sed 's/\.po//g'`; do
+ new_po="$ref_po_dir/$po.po"
+ cksum_file="$ref_po_dir/$po.s1"
+ if ! "$SHA1SUM" -c --status "$cksum_file" < "$new_po" > /dev/null; then
+ echo "updated $po_dir/$po.po..."
+ cp "$new_po" "$po_dir/$po.po" && "$SHA1SUM" < "$new_po" > "$cksum_file"
+ fi
+ done