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…
You should use a localized XML format like
XLIFF
orTMX
, 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:
_()
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/
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:
Save this as, say, options.its, then run itstool like this:
After your translators have translated and given you a PO file (say, xx.po), compile it to an mo file, then merge using itstool:
Check the documentation for more: http://itstool.org/documentation/