download-translations: make sure all .po files are UTF-8
authorTim-Philipp Müller <tim.muller@collabora.co.uk>
Fri, 21 Aug 2009 01:17:42 +0000 (02:17 +0100)
committerTim-Philipp Müller <tim.muller@collabora.co.uk>
Fri, 21 Aug 2009 01:19:12 +0000 (02:19 +0100)
download-translations

index 21f2ac0..f210c94 100755 (executable)
@@ -64,15 +64,35 @@ do
   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
-      if diff $PO_FILENAME "po/$d.po" >/dev/null; then
+      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"
-        echo "$d.po: updated"
+        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
     else