有没有一种简便的方法可以以编程方式列出.MO文件中的所有邮件ID? [英] Is there an easy way to programmatically list all the message IDs in a .MO file?

查看:76
本文介绍了有没有一种简便的方法可以以编程方式列出.MO文件中的所有邮件ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很大的.po文件,其中包含我的PHP应用程序所需的所有面向用户的字符串.我想知道是否可以使用PHP函数获取存储在.po或.mo中的所有msgid字符串的列表.

I have a big ol' .po file containing all the user-facing strings I need for my PHP app. I'd like to know if there's a PHP function I can use to get a list of all the msgid strings stored in the .po or the .mo.

我没有看到执行此操作的已发布PHP函数.任何人都知道类似的东西,还是我自己必须手动解析.po文件?

I didn't see a published PHP function that does this. Anyone know of something similar, or will I have to manually parse my .po file myself?

这是我最想看到的:

$msgids = magic_gettext_keys_function('mydomain');
foreach ($msgids as $msgid) {
    do_something_awesome($msgid);
}

推荐答案

尚未收到任何答案,我假设没有API调用可为我完成此任务.但是,从.po文件中提取msgid字符串几乎是微不足道的:

Not having received any answers yet, I'm assuming there is no API call to do it for me. However, it's almost trivial to extract the msgid strings from the .po file instead:

$path = $GLOBALS['LOCALE_DIR'] . '/en/LC_MESSAGES/mydomain.po';
$poSrc = file_get_contents($path);
preg_match_all('/msgid\s+\"([^\"]*)\"/', $poSrc, $matches);
$msgids = $matches[1];

foreach ($msgids as $msgid) {
    do_something_awesome($msgid);
}

这篇关于有没有一种简便的方法可以以编程方式列出.MO文件中的所有邮件ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆