poedit and xml files

女生的网名这么多〃 提交于 2019-11-27 02:27:30

问题


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.


回答1:


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:

  • 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
  • An item in keywords list: -k%k
  • An item in input files list: %f
  • Source code charset: --from-code=%c

In your translation project, add label and title to your keyword list and update the catalog.




回答2:


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

  1. Add a custom extractor with your extension, specifying standard gettext invocation, without the -L glade bit.
  2. Write ITS rules for your file format.
  3. Put them in the location of other .its and .loc files in Poedit’s installation.



回答3:


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)




回答4:


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.

$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;
}



回答5:


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.



来源:https://stackoverflow.com/questions/3307612/poedit-and-xml-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!