function load($file = null)
{
if (!isset($file)) {
$file = $this->file;
}
// load file
if (!($contents = @file($file))) {
return false;
}
$contents = implode('', $contents);
// match all msgid/msgstr entries
$matched = preg_match_all('/(msgid\\s+("([^"]|\\\\")*?"\\s*)+)\\s+' . '(msgstr\\s+("([^"]|\\\\")*?"\\s*)+)/', $contents, $matches);
unset($contents);
if (!$matched) {
return false;
}
// get all msgids and msgtrs
for ($i = 0; $i < $matched; $i++) {
$msgid = preg_replace('/\\s*msgid\\s*"(.*)"\\s*/s', '\\1', $matches[1][$i]);
$msgstr = preg_replace('/\\s*msgstr\\s*"(.*)"\\s*/s', '\\1', $matches[4][$i]);
$this->strings[parent::prepare($msgid)] = parent::prepare($msgstr);
}
// check for meta info
if (isset($this->strings[''])) {
$this->meta = parent::meta2array($this->strings['']);
unset($this->strings['']);
}
return true;
}
/** * poFile2moFile * * That's a simple fake of the 'msgfmt' console command. It reads the * contents of a GNU PO file and saves them to a GNU MO file. * * @static * @access public * @return mixed Returns true on success or PEAR_Error on failure. * @param string $pofile path to GNU PO file * @param string $mofile path to GNU MO file */ static function poFile2moFile($pofile, $mofile) { if (!is_file($pofile)) { throw new Exception("File {$pofile} doesn't exist."); } include_once dirname(__FILE__) . '/PO.php'; $PO = new TGettext_PO($pofile); if (true !== ($e = $PO->load())) { return $e; } $MO = $PO->toMO(); if (true !== ($e = $MO->save($mofile))) { return $e; } unset($PO, $MO); return true; }