Is there an easy way to programmatically list all

2019-08-17 17:06发布

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.

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?

This is what I'd optimally like to see:

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

标签: php gettext
1条回答
做个烂人
2楼-- · 2019-08-17 17:13

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);
}
查看更多
登录 后发表回答