Localizing text from XML files

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"?>
<options>
  <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>
      </option>

    </section>
  </page>
</options>

Strings within the “label” attribute should be detected by a gettext parser or something…

2 Answers
2

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/

Leave a Comment