if is not in PHP, is possible use some command line tools which convert PO file into some structured format e.g. XML or some other which I can simple process in PHP?
Update: As of 2018/05, the best options are:
See http://www.phptherightway.com#i18n_l10n_title
There are some:
The last one is part of Drupal, and it's probably the most maintained.
Some simple regular expressions will allow you to parse .PO/.POT files. I did a similar thing recently. Take the following regex from a script I have recently written:
$poMsgIdAndMsgStrRegex = '/^#\s*(.+?)\nmsgid "(.+?)"\nmsgstr "(.+?)"/m';
This does only capture the final comment line but it has so far been suitable for my purposes. You may need to adapt it.
Anyway, you can use the above regex with preg_match_all()
to capture all MsgId
and MsgStr
strings into an array of matches. Once you have the array then you can put it into any format you wish.
There may be libraries for doing this but I have not seen any.
Edit: You may also want to check out the PHP class for converting.po files .mo format that is referred to in the 'possible duplicate' comment. It doesn't sound like it will solve your problem (since you want to convert .po files to XML), but it is worth examining anyway. It helped me a lot.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With