Poedit and xml files

How to configure poedit to extract strings from xml file?

I have Zend Framework navigation elements in .xml, for example:

<entry-i> <label>Text to translate</label> <params> ... <params> <entry-i> 

And I want poedit to read only messages from <label> s.

+4
source share
5 answers

I was also looking for a solution, and I just got it to work!

In Poedit (I have 1.4.2) add a new parser ( Edit > Preferences ) with the following properties:

  • Language: XML
  • List of extensions separated by semicolons (e.g. .cpp; .h): *.xml
  • Parser command: xgettext --force-po -o %o %C %K %F -L glade
  • Keyword List Element: -k%k
  • Input file list item: %f
  • Source Code Encoding: --from-code=%c

In the translation project, add label and title to the list of keywords and update the catalog.

+12
source

For those who encounter configuration problems for Poedit in windows, especially if you receive an error message indicating that the fields and expat are not available, replace the supplied xgettext.exe with the current one from the gnuwin32 project:

http://gnuwin32.sourceforge.net/packages/gettext.htm

You need to download binaries and dependencies. However, you only need to extract the binary file xgettext.exe and link the files (just run it and it will tell you what is missing)

+2
source

The above advice on abuse of the Glade extractor for parsing XML files other than Glade is wrong. It will never work well (example: some comments here). Of course, in 2010, it was better than nothing.

Starting with gettext 0.19.7 (bundled with Poedit from version 1.8.7), the best way: now there is built-in gettext support for custom XML files through ITS Rules .

The best way to extract strings from a custom XML file is

  • Add your own extractor with the extension, specifying a standard gettext call, without the -L glade bit.
  • Write ITS rules for your file format.
  • Put them in the location of the other .its and .loc in the Poedits installation.
+2
source

It appears that PoEdit does not yet support XML.

I created a little PHP script to extract tags in a .php file that PoEdit really understands.

 $xml = simplexml_load_file("../application/configs/navigation.xml") or die("Error: Cannot open XML file"); echo '<?'; foreach($xml->xpath('//label') as $label){ echo 'echo _("'.$label.'");'. PHP_EOL; } 
0
source

It works great! I found that the problem is that "Glade is not supported" using Poedit 1.4.6 on Windows 7, but I fixed the download of the latest gnuwin32 binaries and dependencies, as user496209 said. Do not download the complete package because PoEdit comes with its own gettext library, so just download the binaries and dependencies and replace the requested files in the poedit folder.

0
source

Source: https://habr.com/ru/post/1316523/


All Articles