WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Do you guys know any way I could automatically pick up strings from .xml files and store them in a .po / .pot file, just like PoEdit does with the ones from .php files?

The XML structure looks like this:

<?xml version="1.0" encoding="iso-8859-1"?>
  <page id="content" label="Content Options" icon="4">
    <section id="post" label="Content Options">
      <option id="title" type="checkbox" default="yes" label="Show post title"></option>
      <option id="comments" type="checkbox" default="yes" label="Show comments link"></option>
      <option id="thumb_size" type="select" default="default" label="Thumbnail Size">
        <value id="default" label="Default Size, (%s)" vars="default_size"></value>
        <value id="100x100" label="Small (100x100)"></value>
        <value id="150x150" label="Medium (150x150)"></value>
        <value id="200x200" label="Large (200x200)"></value>


Strings within the "label" attribute should be detected by a gettext parser or something...

share|improve this question
up vote 3 down vote accepted

You should use a localized XML format like XLIFF or TMX , there is a tool to convert XLIFF to .po.

If you cannot change the source XML you have a few options but it really depends how your outputting this XML info:

  1. Parse the XML ( for label) and create a .po with gettext output for these strings (then possibly merge the .po files).
  2. Duplicate the XML and insert the _() gettext right into the XML, then parse it on output.

Also have a look at this tool, and there are some command line python tools that can convert xml-->po I think, http://itstool.org/

share|improve this answer
thanks. I found a work-around for PoEdit: stackoverflow.com/questions/3307612/poedit-and-xml-files and zendschool.com/tag/poedit (the text needs to inside a new element though) – onetrickpony Aug 29 '11 at 13:18

If you'd like to try itstool, you just need to give it a custom ITS rules file for your format. The following rules works for the snippet you posted:

  <its:translateRule translate="yes" selector="//@label"/>

Save this as, say, options.its, then run itstool like this:

itstool -i options.its -o somefile.pot somefile.xml

After your translators have translated and given you a PO file (say, xx.po), compile it to an mo file, then merge using itstool:

msgfmt -o xx.mo xx.po
itstool -m xx.mo -i options.its -o somefile.xx.xml somefile.xml

Check the documentation for more: http://itstool.org/documentation/

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.