Sync pomo library with the current GlotPress version
git-svn-id: http://svn.automattic.com/wordpress/trunk@18528 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
cdb9e49b8c
commit
688eebdc26
|
@ -2,7 +2,7 @@
|
||||||
/**
|
/**
|
||||||
* Contains Translation_Entry class
|
* Contains Translation_Entry class
|
||||||
*
|
*
|
||||||
* @version $Id: entry.php 406 2010-02-07 11:10:24Z nbachiyski $
|
* @version $Id: entry.php 621 2011-06-13 12:21:50Z nbachiyski $
|
||||||
* @package pomo
|
* @package pomo
|
||||||
* @subpackage entry
|
* @subpackage entry
|
||||||
*/
|
*/
|
||||||
|
@ -65,5 +65,14 @@ class Translation_Entry {
|
||||||
// prepend context and EOT, like in MO files
|
// prepend context and EOT, like in MO files
|
||||||
return is_null($this->context)? $this->singular : $this->context.chr(4).$this->singular;
|
return is_null($this->context)? $this->singular : $this->context.chr(4).$this->singular;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function merge_with(&$other) {
|
||||||
|
$this->flags = array_unique( array_merge( $this->flags, $other->flags ) );
|
||||||
|
$this->references = array_unique( array_merge( $this->references, $other->references ) );
|
||||||
|
if ( $this->extracted_comments != $other->extracted_comments ) {
|
||||||
|
$this->extracted_comments .= $other->extracted_comments;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
endif;
|
endif;
|
|
@ -2,7 +2,7 @@
|
||||||
/**
|
/**
|
||||||
* Class for working with MO files
|
* Class for working with MO files
|
||||||
*
|
*
|
||||||
* @version $Id: mo.php 406 2010-02-07 11:10:24Z nbachiyski $
|
* @version $Id: mo.php 602 2011-01-30 12:43:29Z nbachiyski $
|
||||||
* @package pomo
|
* @package pomo
|
||||||
* @subpackage mo
|
* @subpackage mo
|
||||||
*/
|
*/
|
||||||
|
@ -30,6 +30,20 @@ class MO extends Gettext_Translations {
|
||||||
function export_to_file($filename) {
|
function export_to_file($filename) {
|
||||||
$fh = fopen($filename, 'wb');
|
$fh = fopen($filename, 'wb');
|
||||||
if ( !$fh ) return false;
|
if ( !$fh ) return false;
|
||||||
|
$res = $this->export_to_file_handle( $fh );
|
||||||
|
fclose($fh);
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
|
function export() {
|
||||||
|
$tmp_fh = fopen("php://temp", 'r+');
|
||||||
|
if ( !$tmp_fh ) return false;
|
||||||
|
$this->export_to_file_handle( $tmp_fh );
|
||||||
|
rewind( $tmp_fh );
|
||||||
|
return stream_get_contents( $tmp_fh );
|
||||||
|
}
|
||||||
|
|
||||||
|
function export_to_file_handle($fh) {
|
||||||
$entries = array_filter($this->entries, create_function('$e', 'return !empty($e->translations);'));
|
$entries = array_filter($this->entries, create_function('$e', 'return !empty($e->translations);'));
|
||||||
ksort($entries);
|
ksort($entries);
|
||||||
$magic = 0x950412de;
|
$magic = 0x950412de;
|
||||||
|
@ -70,7 +84,7 @@ class MO extends Gettext_Translations {
|
||||||
|
|
||||||
fwrite($fh, $originals_table);
|
fwrite($fh, $originals_table);
|
||||||
fwrite($fh, $translations_table);
|
fwrite($fh, $translations_table);
|
||||||
fclose($fh);
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function export_original($entry) {
|
function export_original($entry) {
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
/**
|
/**
|
||||||
* Class for working with PO files
|
* Class for working with PO files
|
||||||
*
|
*
|
||||||
* @version $Id: po.php 406 2010-02-07 11:10:24Z nbachiyski $
|
* @version $Id: po.php 589 2010-12-18 01:40:57Z nbachiyski $
|
||||||
* @package pomo
|
* @package pomo
|
||||||
* @subpackage po
|
* @subpackage po
|
||||||
*/
|
*/
|
||||||
|
@ -19,6 +19,7 @@ ini_set('auto_detect_line_endings', 1);
|
||||||
if ( !class_exists( 'PO' ) ):
|
if ( !class_exists( 'PO' ) ):
|
||||||
class PO extends Gettext_Translations {
|
class PO extends Gettext_Translations {
|
||||||
|
|
||||||
|
var $comments_before_headers = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exports headers to a PO entry
|
* Exports headers to a PO entry
|
||||||
|
@ -31,7 +32,11 @@ class PO extends Gettext_Translations {
|
||||||
$header_string.= "$header: $value\n";
|
$header_string.= "$header: $value\n";
|
||||||
}
|
}
|
||||||
$poified = PO::poify($header_string);
|
$poified = PO::poify($header_string);
|
||||||
return rtrim("msgid \"\"\nmsgstr $poified");
|
if ($this->comments_before_headers)
|
||||||
|
$before_headers = $this->prepend_each_line(rtrim($this->comments_before_headers)."\n", '# ');
|
||||||
|
else
|
||||||
|
$before_headers = '';
|
||||||
|
return rtrim("{$before_headers}msgid \"\"\nmsgstr $poified");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -76,6 +81,15 @@ class PO extends Gettext_Translations {
|
||||||
return fclose($fh);
|
return fclose($fh);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Text to include as a comment before the start of the PO contents
|
||||||
|
*
|
||||||
|
* Doesn't need to include # in the beginning of lines, these are added automatically
|
||||||
|
*/
|
||||||
|
function set_comment_before_headers( $text ) {
|
||||||
|
$this->comments_before_headers = $text;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Formats a string in PO-style
|
* Formats a string in PO-style
|
||||||
*
|
*
|
||||||
|
@ -254,7 +268,7 @@ class PO extends Gettext_Translations {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// add comment
|
// add comment
|
||||||
$this->add_comment_to_entry($entry, $line);
|
$this->add_comment_to_entry($entry, $line);;
|
||||||
} elseif (preg_match('/^msgctxt\s+(".*")/', $line, $m)) {
|
} elseif (preg_match('/^msgctxt\s+(".*")/', $line, $m)) {
|
||||||
if ($is_final($context)) {
|
if ($is_final($context)) {
|
||||||
PO::read_line($f, 'put-back');
|
PO::read_line($f, 'put-back');
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
* Classes, which help reading streams of data from files.
|
* Classes, which help reading streams of data from files.
|
||||||
* Based on the classes from Danilo Segan <danilo@kvota.net>
|
* Based on the classes from Danilo Segan <danilo@kvota.net>
|
||||||
*
|
*
|
||||||
* @version $Id: streams.php 406 2010-02-07 11:10:24Z nbachiyski $
|
* @version $Id: streams.php 597 2011-01-16 20:14:36Z nbachiyski $
|
||||||
* @package pomo
|
* @package pomo
|
||||||
* @subpackage streams
|
* @subpackage streams
|
||||||
*/
|
*/
|
||||||
|
@ -22,7 +22,7 @@ class POMO_Reader {
|
||||||
/**
|
/**
|
||||||
* Sets the endianness of the file.
|
* Sets the endianness of the file.
|
||||||
*
|
*
|
||||||
* @param string $endian 'big' or 'little'
|
* @param $endian string 'big' or 'little'
|
||||||
*/
|
*/
|
||||||
function setEndian($endian) {
|
function setEndian($endian) {
|
||||||
$this->endian = $endian;
|
$this->endian = $endian;
|
||||||
|
@ -106,7 +106,7 @@ if ( !class_exists( 'POMO_FileReader' ) ):
|
||||||
class POMO_FileReader extends POMO_Reader {
|
class POMO_FileReader extends POMO_Reader {
|
||||||
function POMO_FileReader($filename) {
|
function POMO_FileReader($filename) {
|
||||||
parent::POMO_Reader();
|
parent::POMO_Reader();
|
||||||
$this->_f = fopen($filename, 'r');
|
$this->_f = fopen($filename, 'rb');
|
||||||
}
|
}
|
||||||
|
|
||||||
function read($bytes) {
|
function read($bytes) {
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
/**
|
/**
|
||||||
* Class for a set of entries for translation and their associated headers
|
* Class for a set of entries for translation and their associated headers
|
||||||
*
|
*
|
||||||
* @version $Id: translations.php 406 2010-02-07 11:10:24Z nbachiyski $
|
* @version $Id: translations.php 590 2010-12-20 19:58:37Z nbachiyski $
|
||||||
* @package pomo
|
* @package pomo
|
||||||
* @subpackage translations
|
* @subpackage translations
|
||||||
*/
|
*/
|
||||||
|
@ -30,6 +30,19 @@ class Translations {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function add_entry_or_merge($entry) {
|
||||||
|
if (is_array($entry)) {
|
||||||
|
$entry = new Translation_Entry($entry);
|
||||||
|
}
|
||||||
|
$key = $entry->key();
|
||||||
|
if (false === $key) return false;
|
||||||
|
if (isset($this->entries[$key]))
|
||||||
|
$this->entries[$key]->merge_with($entry);
|
||||||
|
else
|
||||||
|
$this->entries[$key] = &$entry;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets $header PO header to $value
|
* Sets $header PO header to $value
|
||||||
*
|
*
|
||||||
|
@ -108,6 +121,15 @@ class Translations {
|
||||||
$this->entries[$entry->key()] = $entry;
|
$this->entries[$entry->key()] = $entry;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function merge_originals_with(&$other) {
|
||||||
|
foreach( $other->entries as $entry ) {
|
||||||
|
if ( !isset( $this->entries[$entry->key()] ) )
|
||||||
|
$this->entries[$entry->key()] = $entry;
|
||||||
|
else
|
||||||
|
$this->entries[$entry->key()]->merge_with($entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Gettext_Translations extends Translations {
|
class Gettext_Translations extends Translations {
|
||||||
|
|
Loading…
Reference in New Issue