[gimp-help-2] [xml2po] Enable md5 feature in gimphelp mode



commit bb417a3bd1e7b33e3d0149e05cb35dd780b29c02
Author: Ulf-D. Ehlert <ulfehlert svn gnome org>
Date:   Thu Dec 17 20:15:34 2009 +0100

    [xml2po] Enable md5 feature in gimphelp mode
    
    Customize gimphelp mode so that xml2po creates md5 checksums for
    image files.  (TODO: add images as prereqisites for po files.)

 Makefile.GNU                   |   20 ++++++++++++++++++++
 tools/xml2po/modes/gimphelp.py |   36 +++++++++++++++++++++++++++++++++++-
 2 files changed, 55 insertions(+), 1 deletions(-)
---
diff --git a/Makefile.GNU b/Makefile.GNU
index e151cee..2141819 100644
--- a/Makefile.GNU
+++ b/Makefile.GNU
@@ -152,6 +152,7 @@ endif
 #
 # Hint: Better don't use 'grep' for filtering-out the warning
 # messages, since grep's exit status is 1 if there is no match.
+ifeq ("$(findstring gimphelp,$(XML2POFLAGS))","")
 xml2pot = ($(XML2PO) $(XML2POFLAGS) --output='-' $(1) \
           | $(MSGUNIQ) $(MSGUNIQFLAGS) \
           | $(MSGCAT) $(MSGCATFLAGS) - > "$(2)") 2>&1 \
@@ -159,6 +160,14 @@ xml2pot = ($(XML2PO) $(XML2POFLAGS) --output='-' $(1) \
           test -s "$(2)" || rm -f "$(2)"; \
           touch -c -r $(call get_recent_file,$(1)) "$(2)" || true; \
           test -s "$(2)"
+else
+xml2pot = $(XML2PO) $(XML2POFLAGS) --output='-' $(1) \
+          | $(MSGUNIQ) $(MSGUNIQFLAGS) \
+          | $(MSGCAT) $(MSGCATFLAGS) - > "$(2)"; \
+          test -s "$(2)" || rm -f "$(2)"; \
+          touch -c -r $(call get_recent_file,$(1)) "$(2)" || true; \
+          test -s "$(2)"
+endif
 
 # Merge template (pot) and message catalog (po) or create a new catalog
 #
@@ -200,6 +209,7 @@ pot2po = with_compendium="$(shell $(call get_compendium,$3)) \
 #     $2 - PO file containing translations
 #     $3 - translation language
 #     $4 - resulting (translated) XML file
+ifeq ("$(findstring gimphelp,$(XML2POFLAGS))","")
 ifneq ("$(FORMAT_XML_WITH_XMLLINT)", "1")
 po2xml = $(XML2PO) $(XML2POFLAGS) --po-file=$(2) --language=$(3) --output=$(4) $(1) 2>&1 \
          | $(SED) -e '/Warning: image file .* not found./d'; \
@@ -210,6 +220,16 @@ po2xml = ($(XML2PO) $(XML2POFLAGS) --po-file=$(2) --language=$(3) --output='-' $
          | $(SED) -e '/Warning: image file .* not found./d'; \
          rm -f .xml2po.mo
 endif
+else
+ifneq ("$(FORMAT_XML_WITH_XMLLINT)", "1")
+po2xml = $(XML2PO) $(XML2POFLAGS) --po-file=$(2) --language=$(3) --output=$(4) $(1); \
+         rm -f .xml2po.mo
+else
+po2xml = ($(XML2PO) $(XML2POFLAGS) --po-file=$(2) --language=$(3) --output='-' $(1) \
+         | $(XMLLINT) $(XMLLINTFLAGS) --format --output $(4) -); \
+         rm -f .xml2po.mo
+endif
+endif
 
 
 #--------------------------------------------------------------#
diff --git a/tools/xml2po/modes/gimphelp.py b/tools/xml2po/modes/gimphelp.py
index 3759caf..4fa51ee 100644
--- a/tools/xml2po/modes/gimphelp.py
+++ b/tools/xml2po/modes/gimphelp.py
@@ -48,9 +48,43 @@ class gimphelpXmlMode(docbookXmlMode):
                              'screenshot' ]
 
     def getTreatedAttributes(self):
-        "Returns array of tag attributes which content is to be translated"
+        "Return array of tag attributes which content is to be translated"
         return ['xreflabel']
 
+    def _output_images(self, node, msg):
+        assert node
+        if node.type == 'element' and node.name == 'imagedata':
+            # Use .fileref to construct new message
+            attr = node.prop("fileref")
+            if attr:
+                assert attr.startswith("images/")
+                origimagepath = attr
+                for subdir in ("C", "commmon"):
+                    imagepath = origimagepath.replace("/", "/%s/" % subdir, 1)
+                    if os.path.exists(imagepath):
+                        hash = self._md5_for_file(imagepath)
+                        break
+                else:
+                    hash = "THIS FILE DOESN'T EXIST"
+                    sys.stderr.write("Warning: image file '%s' not found.\n" %
+                                     origimagepath)
+                msg.outputMessage(
+                    "@@image: '%s'; md5=%s" % (origimagepath, hash),
+                    node.lineNo(),
+                    "When image changes, this message will be marked fuzzy "
+                    "or untranslated for you.\nIt doesn't matter what you "
+                    "translate it to: it's not used at all.")
+        elif node and node.children:
+            child = node.children
+            while child:
+                self._output_images(child,msg)
+                child = child.next
+
+    def preProcessXml(self, doc, msg):
+        """Add additional messages of interest here."""
+        root = doc.getRootElement()
+        self._output_images(root,msg)
+
 # Perform some tests when ran standalone
 if __name__ == '__main__':
     test = gimphelpXmlMode()



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]