Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 11 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(2)
更新:截至 2018/05,最佳选项是:
请参阅http://www.phptherightway.com#i18n_l10n_title
有一些:
最后一个是 Drupal 的一部分,而且可能是维护得最多的一个。
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.
一些简单的正则表达式将允许您解析 .PO/.POT 文件。我最近做了类似的事情。从我最近编写的脚本中获取以下正则表达式:
这仅捕获最终的注释行,但到目前为止它适合我的目的。您可能需要适应它。
无论如何,您可以将上述正则表达式与
preg_match_all()
结合使用,将所有MsgId
和MsgStr
字符串捕获到匹配数组中。获得数组后,您可以将其设置为您想要的任何格式。可能有库可以执行此操作,但我还没有看到。
编辑:您可能还想查看“可能重复”注释中提到的用于转换 .po 文件 .mo 格式的 PHP 类。听起来它并不能解决您的问题(因为您想将 .po 文件转换为 XML),但无论如何它都值得检查。这对我帮助很大。
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:
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 allMsgId
andMsgStr
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.