How to configure poedit to extract strings from xml file?
I have Zend Framework navigation items in .xml like this:
<entry-i>
<label>Text to translate</label>
<params>
...
<params>
<entry-i>
And I want poedit to read just messages from <label>
s.
I have been searching for a solution as well, and I have just gotten it to work!
In Poedit (I have 1.4.2), add a new parser (
Edit > Preferences
) with the following properties:XML
*.xml
xgettext --force-po -o %o %C %K %F -L glade
-k%k
%f
--from-code=%c
In your translation project, add
label
andtitle
to your keyword list and update the catalog.It worked great!! I found the problem about "glade not supported" using Poedit 1.4.6 in Windows 7 but I fixed by downloading last gnuwin32 binaries and dependencies as user496209 said. Don't download the complet package because PoEdit comes with its own gettext library, so just donwload binaries and dependencies and replace the requested files into the poedit folder.
Looks like PoEdit does not support XML yet.
I have created a little php script, to extract the labels to .php file, which PoEdit does understand.
For anyone running into problems with the configuration for Poedit on windows, specifically if you get an error message saying that glade and expat are not available, replace the supplied xgettext.exe with current one from the gnuwin32 project:
http://gnuwin32.sourceforge.net/packages/gettext.htm
You need to download the binaries and the dependencies. However, only the binary xgettext.exe must be extracted and related files (just run it and it will tell you what is missing)
The above advice to abuse the Glade extractor to parse non-Glade XML files is misguided. It’s never going to work well (case in point: some comments around here). Of course, it was better than nothing back in 2010.
Starting with gettext 0.19.7 (bundled with Poedit since 1.8.7), there’s a better way: there’s now builtin support in gettext for custom XML files via ITS rules.
The best way to extract strings from a custom XML file is to
-L glade
bit..its
and.loc
files in Poedit’s installation.