Source for file phpgettext.catalog.php
Documentation is available at phpgettext.catalog.php
* @copyright Copyright (c) 2005 Carlos Souza <csouza@web-sense.net>
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
* @link http://phpgettext.web-sense.net
defined( '_VALID_MOS' ) or die( 'Direct Access to this location is not allowed.' );
require_once(dirname(__FILE__
).
'/phpgettext.message.php');
$this->lang =
'glossary';
trigger_error('Unrecognized mode in '.__CLASS__.
'->'.__FUNCTION__
, E_USER_ERROR);
$langdir =
$this->path.
DIRECTORY_SEPARATOR.
$this->lang;
$this->lang =
'glossary';
trigger_error('Unrecognized mode in '.__CLASS__.
'->'.__FUNCTION__
, E_USER_ERROR);
$return =
$this->path.
DIRECTORY_SEPARATOR;
$return .=
!empty($this->lang) ?
$this->lang.
DIRECTORY_SEPARATOR :
'';
// The directory doesn't exist. Recurse, passing in the parent
// directory so that it gets created.
$this->headers['PO-Revision-Date'] =
date('Y-m-d G:iO');
$comments =
trim($comments);
$comments =
explode("\n", $comments);
foreach ($comments as $comment) {
if (strpos($comment, '#') ==
1) {
foreach ($headers as $key =>
$value) {
$return =
$this->$property;
$this->$property =
$value;
function addentry($msgid, $msgid_plural=
null, $msgstr=
null, $comments=
array())
if (!is_null($msgstr)) $entry->setmsgstr($msgstr);
if (!empty($comments)) $entry->setcomments($comments);
if (!empty($translations[$this->strings[$i]->msgid])){
$this->strings[$i]->setmsgstr ($translations[$this->strings[$i]->msgid]);
function merge(&$glossary)
foreach ($this->strings as $msgid =>
$string){
if (!$glossary[$string->msgid]){
$glossary[$string->msgid] =
$string;
$glossary[$string->msgid]->comments =
array_merge($glossary[$string->msgid]->comments,$string->comments);
$glossary[$string->msgid]->comments =
array_unique($glossary[$string->msgid]->comments);
foreach ($glossary as $msgid =>
$string){
$this->addentry($msgid, $string->msgid_plural, $string->msgstr, $string->comments);
// lock PO file exclusively
if (!@flock($res, LOCK_EX)) {
$header =
'msgid ""' .
"\nmsgstr " .
'""' .
"\n";
foreach ($this->headers as $k =>
$v) {
$header .=
'"' .
$k .
': ' .
$v .
'\n"' .
"\n";
foreach ($this->strings as $string) {
fwrite($res, $string->toString());
if (!$data =
@file($file)) {
foreach ($data as $line) {
elseif (preg_match('/^msgid\s*"(.*)"\s*|^msgid_plural\s*"(.*)"\s*/s', $line, $matches)) {
if (preg_match('/^msgid_plural\s*/s', $line, $arr)) {
$strings[$count]['msgid_plural'] =
$matches[2];
$strings[$count]['comments'] = isset
($comments) ?
$comments :
'';
$strings[$count]['msgid'] =
'';
$strings[$count]['msgid_plural'] =
'';
$strings[$count]['msgstr'] =
'';
$strings[$count]['is_fuzzy'] =
$is_fuzzy;
if (!empty($matches[1])) {
$strings[$count]['msgid'] =
$matches[1];
elseif (preg_match('/^msgstr\s*"(.*)"\s*|^msgstr\[[0-9]\]\s*"(.*)"\s*/s', $line, $matches)) {
$strings[$count]['msgstr'][] = isset
($matches[2]) ?
$matches[2] :
'';
$strings[$count]['msgstr'] =
$matches[1];
} // multiline msgid or msgstr
elseif (preg_match('/^"(.*)"\s*$/s', $line, $matches)) {
if (isset
($msgstr) &&
$count ==
1) {
list
($key, $value) =
explode(':', $matches[1], 2);
elseif (isset
($msgstr) &&
$count >
1) {
$strings[$count]['msgstr'] .=
$matches[1];
$strings[$count]['msgid'] .=
$matches[1];
for ($a=
0; $a <
count($strings); $a++
) {
$this->strings[$a]->setmsgstr($strings[$a]['msgstr']);
$this->strings[$a]->setfuzzy($strings[$a]['is_fuzzy']);
$this->strings[$a]->setcomments($strings[$a]['comments']);
// lock MO file exclusively
if (!@flock($res, LOCK_EX)) {
foreach ($this->headers as $key =>
$val) {
$headers .=
$key .
': ' .
$val .
"\n";
$strings[] =
array('msgid' =>
"", 'msgstr' =>
$headers);
// don't write fuzzy entries
foreach ($this->strings as $message) {
if (!$message->is_fuzzy) {
$strings[] =
array('msgid' =>
$message->msgid,'msgid_plural' =>
$message->msgid_plural, 'msgstr' =>
$message->msgstr);
$count =
count($strings);
fwrite($res, pack('L', (int)
0x950412de)); // magic number
fwrite($res, pack('L', $count)); // N - number of strings
fwrite($res, pack('L', $offset)); // O - offset of table with original strings
fwrite($res, pack('L', $offset)); // T - offset of table with translation strings
fwrite($res, pack('L', 0)); // S - size of hashing table (set to 0 to omit the table)
fwrite($res, pack('L', $offset)); // H - offset of hashing table
// offsets for original strings
for ($a=
0; $a<
$count; $a++
) {
if (isset
($strings[$a]['msgid_plural'])) { // plurals
$strings[$a]['msgid'] =
$strings[$a]['msgid'] .
"\0".
$strings[$a]['msgid_plural'];
$len =
strlen($strings[$a]['msgid']);
// offsets for translated strings
for ($a=
0; $a<
$count; $a++
) {
if (is_array($strings[$a]['msgstr'])) { // plurals
$strings[$a]['msgstr'] =
implode("\0", $strings[$a]['msgstr']);
$len =
strlen($strings[$a]['msgstr']);
// write original strings
foreach ($strings as $str) {
fwrite($res, $str['msgid'] .
"\0");
// write translated strings
foreach ($strings as $str) {
fwrite($res, $str['msgstr'] .
"\0");
// read in data file completely
$data =
fread($f, 1<<
20);
// extract header fields and check file magic
$header =
substr($data, 0, 20);
$header =
unpack("L1magic/L1version/L1count/L1o_msg/L1o_trn", $header);
if ((dechex($magic) ==
"950412de") &&
($version ==
0)) {
for ($a=
0; $a<
$count; $a++
) {
$r =
unpack("L1len/L1offs", substr($data, $o_msg +
$a *
8, 8));
$msgid =
substr($data, $r["offs"], $r["len"]);
if (strpos($msgid, "\0")) { // plurals
list
($msgid, $msgid_plural) =
explode("\0", $msgid);
$r =
unpack("L1len/L1offs", substr($data, $o_trn +
$a *
8, 8));
$msgstr =
substr($data, $r["offs"], $r["len"]);
if (isset
($msgid_plural)) { // plurals
$strings[$a]['msgid'] =
$msgid;
$strings[$a]['msgstr'] =
$msgstr;
$strings[$a]['msgid_plural'] = isset
($msgid_plural) ?
$msgid_plural :
'';
if (!empty($strings[0]['msgstr'])){ // header
$str =
explode("\n", $strings[0]['msgstr']);
@list
($key, $value) =
explode(':', $s, 2);
for ($a=
0; $a <
count($strings); $a++
) {
$this->strings[$a]->setmsgstr($strings[$a]['msgstr']);
Documentation generated on Mon, 05 May 2008 16:22:20 +0400 by phpDocumentor 1.4.0