Update php-gettext to 1.0.10.

We're now using upstream version with no changes.
This commit is contained in:
Michal Čihař
2010-03-23 15:31:55 +01:00
parent 2b0cc1d9fc
commit 237c009be8
3 changed files with 246 additions and 93 deletions

45
libraries/php-gettext/gettext.php Executable file → Normal file
View File

@@ -134,7 +134,7 @@ class gettext_reader {
* Loads the translation tables from the MO file into the cache
* If caching is enabled, also loads all strings into a cache
* to speed up translation lookups
*
*
* @access private
*/
function load_tables() {
@@ -144,10 +144,14 @@ class gettext_reader {
return;
/* get original and translations tables */
$this->STREAM->seekto($this->originals);
$this->table_originals = $this->readintarray($this->total * 2);
$this->STREAM->seekto($this->translations);
$this->table_translations = $this->readintarray($this->total * 2);
if (!is_array($this->table_originals)) {
$this->STREAM->seekto($this->originals);
$this->table_originals = $this->readintarray($this->total * 2);
}
if (!is_array($this->table_translations)) {
$this->STREAM->seekto($this->translations);
$this->table_translations = $this->readintarray($this->total * 2);
}
if ($this->enable_cache) {
$this->cache_translations = array ();
@@ -300,6 +304,20 @@ class gettext_reader {
return $res;
}
/**
* Parse full PO header and extract only plural forms line.
*
* @access private
* @return string verbatim plural form header field
*/
function extract_plural_forms_header_from_po_header($header) {
if (preg_match("/(^|\n)plural-forms: ([^\n]*)\n/i", $header, $regs))
$expr = $regs[2];
else
$expr = "nplurals=2; plural=n == 1 ? 0 : 1;";
return $expr;
}
/**
* Get possible plural forms from MO header
*
@@ -318,11 +336,7 @@ class gettext_reader {
} else {
$header = $this->get_translation_string(0);
}
if (eregi("plural-forms: ([^\n]*)\n", $header, $regs))
$expr = $regs[1];
else
$expr = "nplurals=2; plural=n == 1 ? 0 : 1;";
$expr = $this->extract_plural_forms_header_from_po_header($header);
$this->pluralheader = $this->sanitize_plural_expression($expr);
}
return $this->pluralheader;
@@ -370,7 +384,7 @@ class gettext_reader {
$select = $this->select_string($number);
// this should contains all strings separated by NULLs
$key = $single.chr(0).$plural;
$key = $single . chr(0) . $plural;
if ($this->enable_cache) {
@@ -393,6 +407,15 @@ class gettext_reader {
}
}
function pgettext($context, $msgid) {
$key = $context . chr(4) . $msgid;
return $this->translate($key);
}
function npgettext($context, $singular, $plural, $number) {
$singular = $context . chr(4) . $singular;
return $this->ngettext($singular, $plural, $number);
}
}
?>