Sync POMO with GlotPress

See http://glotpress.trac.wordpress.org/browser/trunk/pomo/


git-svn-id: https://develop.svn.wordpress.org/trunk@22349 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Nikolay Bachiyski 2012-10-31 22:13:51 +00:00
parent 794c7f6b1c
commit 1a9ffb97a7
5 changed files with 76 additions and 58 deletions

View File

@ -2,7 +2,7 @@
/** /**
* Contains Translation_Entry class * Contains Translation_Entry class
* *
* @version $Id: entry.php 621 2011-06-13 12:21:50Z nbachiyski $ * @version $Id: entry.php 718 2012-10-31 00:32:02Z nbachiyski $
* @package pomo * @package pomo
* @subpackage entry * @subpackage entry
*/ */

View File

@ -2,7 +2,7 @@
/** /**
* Class for working with MO files * Class for working with MO files
* *
* @version $Id: mo.php 602 2011-01-30 12:43:29Z nbachiyski $ * @version $Id: mo.php 718 2012-10-31 00:32:02Z nbachiyski $
* @package pomo * @package pomo
* @subpackage mo * @subpackage mo
*/ */
@ -43,8 +43,20 @@ class MO extends Gettext_Translations {
return stream_get_contents( $tmp_fh ); return stream_get_contents( $tmp_fh );
} }
function is_entry_good_for_export( $entry ) {
if ( empty( $entry->translations ) ) {
return false;
}
if ( !array_filter( $entry->translations ) ) {
return false;
}
return true;
}
function export_to_file_handle($fh) { function export_to_file_handle($fh) {
$entries = array_filter($this->entries, create_function('$e', 'return !empty($e->translations);')); $entries = array_filter( $this->entries, array( $this, 'is_entry_good_for_export' ) );
ksort($entries); ksort($entries);
$magic = 0x950412de; $magic = 0x950412de;
$revision = 0; $revision = 0;
@ -195,8 +207,7 @@ class MO extends Gettext_Translations {
$translation = $reader->substr( $strings, $t['pos'], $t['length'] ); $translation = $reader->substr( $strings, $t['pos'], $t['length'] );
if ('' === $original) { if ('' === $original) {
$headers = $this->make_headers($translation); $this->set_headers($this->make_headers($translation));
$this->set_headers($headers);
} else { } else {
$entry = &$this->make_entry($original, $translation); $entry = &$this->make_entry($original, $translation);
$this->entries[$entry->key()] = &$entry; $this->entries[$entry->key()] = &$entry;

View File

@ -2,7 +2,7 @@
/** /**
* Class for working with PO files * Class for working with PO files
* *
* @version $Id: po.php 589 2010-12-18 01:40:57Z nbachiyski $ * @version $Id: po.php 718 2012-10-31 00:32:02Z nbachiyski $
* @package pomo * @package pomo
* @subpackage po * @subpackage po
*/ */
@ -229,7 +229,13 @@ class PO extends Gettext_Translations {
} }
} }
PO::read_line($f, 'clear'); PO::read_line($f, 'clear');
return $res !== false; if ( false === $res ) {
return false;
}
if ( ! $this->headers && ! $this->entries ) {
return false;
}
return true;
} }
function read_entry($f, $lineno = 0) { function read_entry($f, $lineno = 0) {
@ -349,6 +355,7 @@ class PO extends Gettext_Translations {
return true; return true;
} }
$line = $use_last_line? $last_line : fgets($f); $line = $use_last_line? $last_line : fgets($f);
$line = gp_endswith( $line, "\r\n" )? rtrim( $line, "\r\n" ) . "\n" : $line;
$last_line = $line; $last_line = $line;
$use_last_line = false; $use_last_line = false;
return $line; return $line;

View File

@ -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 597 2011-01-16 20:14:36Z nbachiyski $ * @version $Id: streams.php 718 2012-10-31 00:32:02Z nbachiyski $
* @package pomo * @package pomo
* @subpackage streams * @subpackage streams
*/ */

View File

@ -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 590 2010-12-20 19:58:37Z nbachiyski $ * @version $Id: translations.php 718 2012-10-31 00:32:02Z nbachiyski $
* @package pomo * @package pomo
* @subpackage translations * @subpackage translations
*/ */
@ -81,7 +81,7 @@ class Translations {
/** /**
* Given the number of items, returns the 0-based index of the plural form to use * Given the number of items, returns the 0-based index of the plural form to use
* *
* Here, in the base Translations class, the common logic for English is implemented: * Here, in the base Translations class, the common logic for English is implmented:
* 0 if there is one element, 1 otherwise * 0 if there is one element, 1 otherwise
* *
* This function should be overrided by the sub-classes. For example MO/PO can derive the logic * This function should be overrided by the sub-classes. For example MO/PO can derive the logic