tags:

views:

30

answers:

1

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);
}
A: 

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);
}
jodonnell