Index: xml2po/modes/docbook.py
===================================================================
--- xml2po/modes/docbook.py	(revision 862)
+++ xml2po/modes/docbook.py	(working copy)
@@ -96,6 +96,18 @@
             child = child.next
         return None
 
+    def _find_menupath(self, node):
+        """Locate menupath node."""
+        if node.name == 'menupath':
+            return node
+        child = node.children
+        while child:
+            ret = self._find_menupath(child)
+            if ret:
+                return ret
+            child = child.next
+        return None
+
     def _find_lastcopyright(self, node):
         if not node.children:
             return None
@@ -146,6 +158,55 @@
         root = doc.getRootElement()
         self._output_images(root,msg)
 
+    def processMenuPath(self, doc, desktop_file):
+        """Find menu location using desktop_file and replace <menupath> tag with
+        menu location."""
+
+        # Load in menuLocation mode/class
+        module = __import__("menulocation")
+        modeModule = 'menuLocation'
+        menuLocation = getattr(module, modeModule)()
+
+        menu_path = menuLocation.locateMenu(desktop_file)
+
+        if menu_path is not None:
+            # Locate menupath element, to be replaced with menu 
+            root = doc.getRootElement()
+            menupath = self._find_menupath(root)
+
+            # Replace <menupath/> with menu structure found
+            if menupath:
+                # Get <menupath/>'s parent
+                menuparent = menupath.parent
+
+                # Remove <menupath/> node
+                menupath.unlinkNode()
+                menupath.freeNode()
+
+                # Split returned path
+                items = menu_path.split('|')
+
+                # Create the main menu <term> node
+                mainmenu = libxml2.newNode("term")
+                mainmenu.newChild(None, "guimenu", items[0])
+
+                # Create the submenu's/menuitem <list> nodes
+                listitem = libxml2.newNode("listitem")
+                para = listitem.newChild(None, "para", "Choose ")
+                menuchoice = para.newChild(None, "menuchoice", None)
+
+                for i in range(len(items)):
+                    if i == (len(items)-1):
+                        # Menu Item
+                        menuchoice.newChild(None, "guimenuitem", items[i])
+                    elif i > 0:
+                        # Sub Menu
+                        menuchoice.newChild(None, "guisubmenu", items[i])
+
+                # Add mainmenu and list nodes to <menupath/>'s parent
+                menuparent.addChild(mainmenu)
+                menuparent.addChild(listitem)
+
     def postProcessXmlTranslation(self, doc, language, translators):
         """Sets a language and translators in "doc" tree.
         
Index: xml2po/modes/Makefile.am
===================================================================
--- xml2po/modes/Makefile.am	(revision 862)
+++ xml2po/modes/Makefile.am	(working copy)
@@ -1,4 +1,4 @@
 commondir = $(datadir)/xml2po
-common_DATA = docbook.py empty.py gs.py ubuntu.py xhtml.py
+common_DATA = docbook.py empty.py gs.py ubuntu.py xhtml.py menulocation.py
 
 EXTRA_DIST = $(common_DATA)
Index: xml2po/xml2po.py
===================================================================
--- xml2po/xml2po.py	(revision 862)
+++ xml2po/xml2po.py	(working copy)
@@ -643,6 +643,8 @@
             sys.exit(9)
         elif opt in ('-u', '--update-translation'):
             pass
+        elif opt in ('-d', '--desktop-file'):
+            command += " -d %s" % arg
         else:
             sys.stderr.write("Error: Option `%s' is not supported with option `-u'.\n" % (opt))
             sys.exit(9)
@@ -706,6 +708,7 @@
 expand_all_entities = 0
 
 output  = '-' # this means to stdout
+desktop_file = None
 
 NULL_STRING = '/dev/null'
 if not os.path.exists('/dev/null'): NULL_STRING = 'NUL'
@@ -733,6 +736,7 @@
           --mark-untranslated  Set 'xml:lang="C"' on untranslated tags
 
     -v    --version            Output version of the xml2po program
+    -d    --desktop-file       .desktop file to use for menu substitution
 
     -h    --help               Output this message
 
@@ -751,9 +755,9 @@
 if len(sys.argv) < 2: usage()
 
 args = sys.argv[1:]
-try: opts, args = getopt.getopt(args, 'avhkem:t:o:p:u:r:l:',
+try: opts, args = getopt.getopt(args, 'avhkem:t:o:p:u:r:l:d:',
                            ['automatic-tags','version', 'help', 'keep-entities', 'expand-all-entities', 'mode=', 'translation=',
-                            'output=', 'po-file=', 'update-translation=', 'reuse=', 'language=', 'mark-untranslated' ])
+                            'output=', 'po-file=', 'update-translation=', 'reuse=', 'language=', 'mark-untranslated', 'desktop-file=' ])
 except getopt.GetoptError: usage(True)
 
 for opt, arg in opts:
@@ -788,6 +792,8 @@
     elif opt in ('-v', '--version'):
         print VERSION
         sys.exit(0)
+    elif opt in ('-d', '--desktop-file'):
+        desktop_file = arg
     elif opt in ('-h', '--help'):
     	usage(True)
 
@@ -880,4 +886,6 @@
         else:
             outtxt = ''
         CurrentXmlMode.postProcessXmlTranslation(doc, translationlanguage, outtxt)
+        if desktop_file:
+            CurrentXmlMode.processMenuPath(doc, desktop_file)
     out.write(doc.serialize('utf-8', 1))
Index: template.make
===================================================================
--- template.make	(revision 862)
+++ template.make	(working copy)
@@ -6,3 +6,5 @@
 
 DOC_LINGUAS = 
 
+DOC_DESKTOP_LOCATION =
+
Index: tools/gnome-doc-utils.make
===================================================================
--- tools/gnome-doc-utils.make	(revision 862)
+++ tools/gnome-doc-utils.make	(working copy)
@@ -191,6 +191,10 @@
 ## The top-level documentation file in the C locale
 _DOC_C_MODULE = $(if $(DOC_MODULE),C/$(DOC_MODULE).xml)
 
+## @ _DOC_C_MODULE_IN
+## The top-level input documentation file in the C locale
+_DOC_C_MODULE_IN = $(if $(DOC_MODULE),C/$(DOC_MODULE).xml.in)
+
 ## @ _DOC_C_ENTITIES
 ## Files included with a SYSTEM entity in the C locale
 _DOC_C_ENTITIES = $(foreach ent,$(DOC_ENTITIES),C/$(ent))
@@ -199,12 +203,26 @@
 ## Files included with XInclude in the C locale
 _DOC_C_INCLUDES = $(foreach inc,$(DOC_INCLUDES),C/$(inc))
 
+## @ _DOC_C_INCLUDES_IN
+## Input Files included with a SYSTEM entity in the C locale
+_DOC_C_INCLUDES_IN = $(foreach ent,$(DOC_INCLUDES),C/$(ent).in)
+
 ## @ _DOC_C_DOCS
 ## All documentation files in the C locale
 _DOC_C_DOCS =								\
 	$(_DOC_C_ENTITIES)	$(_DOC_C_INCLUDES)			\
 	$(_DOC_C_MODULE)
 
+## @ _DOC_C_DOCS_IN
+## All documentation files in the C locale
+_DOC_C_DOCS_IN =								\
+	$(_DOC_C_INCLUDES_IN)	$(_DOC_C_MODULE_IN)
+
+## @ _DOC_C_DOCS_XML
+## All xml documentation files in the C locale
+_DOC_C_DOCS_XML =								\
+	$(_DOC_C_INCLUDES)	$(_DOC_C_MODULE)
+
 ## @ _DOC_C_DOCS_NOENT
 ## All documentation files in the C locale,
 ## except files included with a SYSTEM entity
@@ -270,7 +288,7 @@
 	$(foreach fig,$(_DOC_C_FIGURES), $(foreach lc,C $(_DOC_REAL_LINGUAS),	\
 		$(wildcard $(srcdir)/$(lc)/$(patsubst C/%,%,$(fig))) ))
 
-$(_DOC_POFILES):
+$(_DOC_POFILES): $(_DOCS_C_DOCS)
 	@if ! test -d $(dir $@); then \
 	  echo "mkdir $(dir $@)"; \
 	  mkdir "$(dir $@)"; \
@@ -301,6 +319,23 @@
 	    $(_xml2po) -e -u $(notdir $@) $$docs); \
 	fi
 
+# Conversion of C/*.xml.in to C/*.xml
+# If DOC_DESKTOP_LOCATION not defined just does a cp
+$(_DOC_C_DOCS_IN) :
+$(_DOC_C_DOCS) : $(_DOC_C_DOCS_IN)
+	@if ! test x$(DOC_DESKTOP_LOCATION) = x; then \
+		if [ -f C/$(notdir $@).in ]; then \
+			touch en.po; \
+	  		$(_xml2po) -k -p en.po -d $(DOC_DESKTOP_LOCATION) \
+				-o C/$(notdir $@) C/$(notdir $@).in; \
+			rm -f en.po; \
+		fi; \
+	else \
+		if [ -f C/$(notdir $@).in ]; then \
+			cp -f C/$(notdir $@).in C/$(notdir $@); \
+		fi; \
+	fi
+
 # FIXME: fix the dependancy
 # FIXME: hook xml2po up
 $(_DOC_LC_DOCS) : $(_DOC_POFILES)
@@ -346,12 +381,13 @@
 endif
 
 all:							\
+	$(_DOC_C_DOCS_IN)				\
 	$(_DOC_C_DOCS)		$(_DOC_LC_DOCS)		\
 	$(_DOC_OMF_ALL)		$(_DOC_DSK_ALL)		\
 	$(_DOC_HTML_ALL)	$(_DOC_POFILES)
 
 
-.PHONY: clean-doc-omf clean-doc-dsk clean-doc-lc clean-doc-dir
+.PHONY: clean-doc-omf clean-doc-dsk clean-doc-lc clean-doc-dir clean-doc-xml
 
 clean-doc-omf: ; rm -f $(_DOC_OMF_DB) $(_DOC_OMF_HTML)
 clean-doc-dsk: ; rm -f $(_DOC_DSK_DB) $(_DOC_DSK_HTML)
@@ -369,6 +405,13 @@
 	    rm -f "$$lc/.xml2po.mo"; \
 	  fi; \
 	done
+clean-doc-xml:
+	@for xml in $(_DOC_C_DOCS_XML); do \
+	  if test -f "$$xml.in"; then \
+	    echo "rm -f $$xml"; \
+	    rm -f "$$xml"; \
+	  fi; \
+	done
 clean-doc-dir:
 	@for lc in C $(_DOC_REAL_LINGUAS); do \
 	  for dir in `find $$lc -depth -type d`; do \
@@ -382,20 +425,25 @@
 _clean_omf = $(if $(_DOC_OMF_IN),clean-doc-omf)
 _clean_dsk = $(if $(_DOC_DSK_IN),clean-doc-dsk)
 _clean_lc  = $(if $(_DOC_REAL_LINGUAS),clean-doc-lc)
+_clean_xml = $(if $(DOC_MODULE),clean-doc-xml)
 _clean_dir = $(if $(DOC_MODULE),clean-doc-dir)
 
 clean-local:						\
 	$(_clean_omf)		$(_clean_dsk)		\
-	$(_clean_lc)		$(_clean_dir)
+	$(_clean_lc)		$(_clean_xml)		\
+	$(_clean_dir)
 distclean-local:					\
 	$(_clean_omf)		$(_clean_dsk)		\
-	$(_clean_lc)		$(_clean_dir)
+	$(_clean_lc)		$(_clean_xml)		\
+	$(_clean_dir)
 mostlyclean-local:					\
 	$(_clean_omf)		$(_clean_dsk)		\
-	$(_clean_lc)		$(_clean_dir)
+	$(_clean_lc)		$(_clean_xml)		\
+	$(_clean_dir)
 maintainer-clean-local:					\
 	$(_clean_omf)		$(_clean_dsk)		\
-	$(_clean_lc)		$(_clean_dir)
+	$(_clean_lc)		$(_clean_xml)		\
+	$(_clean_dir)
 
 
 .PHONY: dist-doc-docs dist-doc-figs dist-doc-omf dist-doc-dsk
@@ -533,7 +581,7 @@
 uninstall-local:					\
 	$(if $(DOC_MODULE),uninstall-doc-docs)		\
 	$(if $(_DOC_HTML_ALL),uninstall-doc-html)	\
-	$(if $(_DOC_C_FIGURES),uninstall-doc-figs)	\
+	$(if $(_DOC_FIGURES),uninstall-doc-figs)	\
 	$(if $(_DOC_OMF_IN),uninstall-doc-omf)
 #	$(if $(_DOC_DSK_IN),uninstall-doc-dsk)
 
