<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" /><style type="text/css"><!--
#msg dl { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fc0 solid; padding: 6px; }
#msg ul, pre { overflow: auto; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<title>[12079] trunk/wp-includes/pomo: Merge updated pomo code.</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/12079">12079</a></dd>
<dt>Author</dt> <dd>westi</dd>
<dt>Date</dt> <dd>2009-10-21 07:06:55 +0000 (Wed, 21 Oct 2009)</dd>
</dl>

<h3>Log Message</h3>
<pre>Merge updated pomo code. Includes new NOOP_Translations class see <a href="http://trac.wordpress.org/ticket/10971">#10971</a> props nbachiyski.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpincludespomoentryphp">trunk/wp-includes/pomo/entry.php</a></li>
<li><a href="#trunkwpincludespomomophp">trunk/wp-includes/pomo/mo.php</a></li>
<li><a href="#trunkwpincludespomopophp">trunk/wp-includes/pomo/po.php</a></li>
<li><a href="#trunkwpincludespomostreamsphp">trunk/wp-includes/pomo/streams.php</a></li>
<li><a href="#trunkwpincludespomotranslationsphp">trunk/wp-includes/pomo/translations.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpincludespomoentryphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/pomo/entry.php (12078 => 12079)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/pomo/entry.php        2009-10-20 22:58:47 UTC (rev 12078)
+++ trunk/wp-includes/pomo/entry.php        2009-10-21 07:06:55 UTC (rev 12079)
</span><span class="lines">@@ -2,12 +2,12 @@
</span><span class="cx"> /**
</span><span class="cx">  * Contains Translation_Entry class
</span><span class="cx">  *
</span><del>- * @version $Id: entry.php 115 2009-05-11 18:56:15Z nbachiyski $
</del><ins>+ * @version $Id: entry.php 222 2009-09-07 21:14:23Z nbachiyski $
</ins><span class="cx">  * @package pomo
</span><span class="cx">  * @subpackage entry
</span><span class="cx">  */
</span><span class="cx"> 
</span><del>-
</del><ins>+if ( !class_exists( 'Translation_Entry' ) ):
</ins><span class="cx"> /**
</span><span class="cx">  * Translation_Entry class encapsulates a translatable string
</span><span class="cx">  */
</span><span class="lines">@@ -67,4 +67,4 @@
</span><span class="cx">                 return is_null($this-&gt;context)? $this-&gt;singular : $this-&gt;context.chr(4).$this-&gt;singular;
</span><span class="cx">         }
</span><span class="cx"> }
</span><del>-?&gt;
</del><ins>+endif;
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkwpincludespomomophp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/pomo/mo.php (12078 => 12079)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/pomo/mo.php        2009-10-20 22:58:47 UTC (rev 12078)
+++ trunk/wp-includes/pomo/mo.php        2009-10-21 07:06:55 UTC (rev 12079)
</span><span class="lines">@@ -2,7 +2,7 @@
</span><span class="cx"> /**
</span><span class="cx">  * Class for working with MO files
</span><span class="cx">  *
</span><del>- * @version $Id: mo.php 106 2009-04-23 19:48:22Z nbachiyski $
</del><ins>+ * @version $Id: mo.php 221 2009-09-07 21:08:21Z nbachiyski $
</ins><span class="cx">  * @package pomo
</span><span class="cx">  * @subpackage mo
</span><span class="cx">  */
</span><span class="lines">@@ -10,6 +10,7 @@
</span><span class="cx"> require_once dirname(__FILE__) . '/translations.php';
</span><span class="cx"> require_once dirname(__FILE__) . '/streams.php';
</span><span class="cx"> 
</span><ins>+if ( !class_exists( 'MO' ) ):
</ins><span class="cx"> class MO extends Gettext_Translations {
</span><span class="cx"> 
</span><span class="cx">         var $_nplurals = 2;
</span><span class="lines">@@ -95,15 +96,13 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         function get_byteorder($magic) {
</span><del>-
</del><span class="cx">                 // The magic is 0x950412de
</span><span class="cx"> 
</span><span class="cx">                 // bug in PHP 5.0.2, see https://savannah.nongnu.org/bugs/?func=detailitem&amp;item_id=10565
</span><span class="cx">                 $magic_little = (int) - 1794895138;
</span><span class="cx">                 $magic_little_64 = (int) 2500072158;
</span><span class="cx">                 // 0xde120495
</span><del>-                $magic_big = ((int) - 569244523) &amp;&amp; 0xFFFFFFFF;
-                
</del><ins>+                $magic_big = ((int) - 569244523) &amp; 0xFFFFFFFF;
</ins><span class="cx">                 if ($magic_little == $magic || $magic_little_64 == $magic) {
</span><span class="cx">                         return 'little';
</span><span class="cx">                 } else if ($magic_big == $magic) {
</span><span class="lines">@@ -182,4 +181,4 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> }
</span><del>-?&gt;
</del><ins>+endif;
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkwpincludespomopophp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/pomo/po.php (12078 => 12079)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/pomo/po.php        2009-10-20 22:58:47 UTC (rev 12078)
+++ trunk/wp-includes/pomo/po.php        2009-10-21 07:06:55 UTC (rev 12079)
</span><span class="lines">@@ -2,7 +2,7 @@
</span><span class="cx"> /**
</span><span class="cx">  * Class for working with PO files
</span><span class="cx">  *
</span><del>- * @version $Id: po.php 123 2009-05-13 19:35:43Z nbachiyski $
</del><ins>+ * @version $Id: po.php 283 2009-09-23 16:21:51Z nbachiyski $
</ins><span class="cx">  * @package pomo
</span><span class="cx">  * @subpackage po
</span><span class="cx">  */
</span><span class="lines">@@ -16,6 +16,7 @@
</span><span class="cx"> /**
</span><span class="cx">  * Routines for working with PO files
</span><span class="cx">  */
</span><ins>+if ( !class_exists( 'PO' ) ):
</ins><span class="cx"> class PO extends Gettext_Translations {
</span><span class="cx">         
</span><span class="cx"> 
</span><span class="lines">@@ -316,7 +317,9 @@
</span><span class="cx">                                 return false;
</span><span class="cx">                         }
</span><span class="cx">                 }
</span><del>-                if (array() == array_filter($entry-&gt;translations)) $entry-&gt;translations = array();
</del><ins>+                if (array() == array_filter($entry-&gt;translations, create_function('$t', 'return $t || &quot;0&quot; === $t;'))) {
+                        $entry-&gt;translations = array();
+                }
</ins><span class="cx">                 return array('entry' =&gt; $entry, 'lineno' =&gt; $lineno);
</span><span class="cx">         }
</span><span class="cx">         
</span><span class="lines">@@ -357,4 +360,4 @@
</span><span class="cx">                 return $s;
</span><span class="cx">         }
</span><span class="cx"> }
</span><del>-?&gt;
</del><ins>+endif;
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkwpincludespomostreamsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/pomo/streams.php (12078 => 12079)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/pomo/streams.php        2009-10-20 22:58:47 UTC (rev 12078)
+++ trunk/wp-includes/pomo/streams.php        2009-10-21 07:06:55 UTC (rev 12079)
</span><span class="lines">@@ -3,12 +3,13 @@
</span><span class="cx">  * Classes, which help reading streams of data from files.
</span><span class="cx">  * Based on the classes from Danilo Segan &lt;danilo@kvota.net&gt;
</span><span class="cx">  *
</span><del>- * @version $Id: streams.php 138 2009-06-23 13:22:09Z nbachiyski $
</del><ins>+ * @version $Id: streams.php 223 2009-09-07 21:20:13Z nbachiyski $
</ins><span class="cx">  * @package pomo
</span><span class="cx">  * @subpackage streams
</span><span class="cx">  */
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+if ( !class_exists( 'POMO_StringReader' ) ):
</ins><span class="cx"> /**
</span><span class="cx">  * Provides file-like methods for manipulating a string instead
</span><span class="cx">  * of a physical file.
</span><span class="lines">@@ -61,7 +62,9 @@
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx"> }
</span><ins>+endif;
</ins><span class="cx"> 
</span><ins>+if ( !class_exists( 'POMO_CachedFileReader' ) ):
</ins><span class="cx"> /**
</span><span class="cx">  * Reads the contents of the file in the beginning.
</span><span class="cx">  */
</span><span class="lines">@@ -74,7 +77,9 @@
</span><span class="cx">                 $this-&gt;_pos = 0;
</span><span class="cx">         }
</span><span class="cx"> }
</span><ins>+endif;
</ins><span class="cx"> 
</span><ins>+if ( !class_exists( 'POMO_CachedIntFileReader' ) ):
</ins><span class="cx"> /**
</span><span class="cx">  * Allows reading integers from a file.
</span><span class="cx">  */
</span><span class="lines">@@ -133,5 +138,4 @@
</span><span class="cx">                 return unpack($endian_letter.$count, $bytes);
</span><span class="cx">         }
</span><span class="cx"> }
</span><del>-
-?&gt;
</del><ins>+endif;
</ins><span class="cx">\ No newline at end of file
</span></span></pre></div>
<a id="trunkwpincludespomotranslationsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/pomo/translations.php (12078 => 12079)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/pomo/translations.php        2009-10-20 22:58:47 UTC (rev 12078)
+++ trunk/wp-includes/pomo/translations.php        2009-10-21 07:06:55 UTC (rev 12079)
</span><span class="lines">@@ -2,13 +2,14 @@
</span><span class="cx"> /**
</span><span class="cx">  * Class for a set of entries for translation and their associated headers
</span><span class="cx">  *
</span><del>- * @version $Id: translations.php 114 2009-05-11 17:30:38Z nbachiyski $
</del><ins>+ * @version $Id: translations.php 291 2009-10-21 05:46:08Z nbachiyski $
</ins><span class="cx">  * @package pomo
</span><span class="cx">  * @subpackage translations
</span><span class="cx">  */
</span><span class="cx"> 
</span><span class="cx"> require_once dirname(__FILE__) . '/entry.php';
</span><span class="cx"> 
</span><ins>+if ( !class_exists( 'Translations' ) ):
</ins><span class="cx"> class Translations {
</span><span class="cx">         var $entries = array();
</span><span class="cx">         var $headers = array();
</span><span class="lines">@@ -25,7 +26,7 @@
</span><span class="cx">                 }
</span><span class="cx">                 $key = $entry-&gt;key();
</span><span class="cx">                 if (false === $key) return false;
</span><del>-                $this-&gt;entries[$key] = $entry;
</del><ins>+                $this-&gt;entries[$key] = &amp;$entry;
</ins><span class="cx">                 return true;
</span><span class="cx">         }
</span><span class="cx"> 
</span><span class="lines">@@ -117,29 +118,33 @@
</span><span class="cx">          */
</span><span class="cx">         function gettext_select_plural_form($count) {
</span><span class="cx">                 if (!isset($this-&gt;_gettext_select_plural_form) || is_null($this-&gt;_gettext_select_plural_form)) {
</span><del>-                        $plural_header = $this-&gt;get_header('Plural-Forms');
-                        $this-&gt;_gettext_select_plural_form = $this-&gt;_make_gettext_select_plural_form($plural_header);
</del><ins>+                        list( $nplurals, $expression ) = $this-&gt;nplurals_and_expression_from_header($this-&gt;get_header('Plural-Forms'));
+                        $this-&gt;_nplurals = $nplurals;
+                        $this-&gt;_gettext_select_plural_form = $this-&gt;make_plural_form_function($nplurals, $expression);
</ins><span class="cx">                 }
</span><span class="cx">                 return call_user_func($this-&gt;_gettext_select_plural_form, $count);
</span><span class="cx">         }
</span><ins>+        
+        function nplurals_and_expression_from_header($header) {
+                if (preg_match('/^\s*nplurals\s*=\s*(\d+)\s*;\s+plural\s*=\s*(.+)$/', $header, $matches)) {
+                        $nplurals = (int)$matches[1];
+                        $expression = trim($this-&gt;parenthesize_plural_exression($matches[2]));
+                        return array($nplurals, $expression);
+                } else {
+                        return array(2, 'n != 1');
+                }
+        }
</ins><span class="cx"> 
</span><span class="cx">         /**
</span><span class="cx">          * Makes a function, which will return the right translation index, according to the
</span><span class="cx">          * plural forms header
</span><span class="cx">          */
</span><del>-        function _make_gettext_select_plural_form($plural_header) {
-                $res = create_function('$count', 'return 1 == $count? 0 : 1;');
-                if ($plural_header &amp;&amp; (preg_match('/^\s*nplurals\s*=\s*(\d+)\s*;\s+plural\s*=\s*(.+)$/', $plural_header, $matches))) {
-                        $nplurals = (int)$matches[1];
-                        $this-&gt;_nplurals = $nplurals;
-                        $plural_expr = trim($this-&gt;_parenthesize_plural_exression($matches[2]));
-                        $plural_expr = str_replace('n', '$n', $plural_expr);
-                        $func_body = &quot;
-                                \$index = (int)($plural_expr);
-                                return (\$index &lt; $nplurals)? \$index : $nplurals - 1;&quot;;
-                        $res = create_function('$n', $func_body);
-                }
-                return $res;
</del><ins>+        function make_plural_form_function($nplurals, $expression) {
+                $expression = str_replace('n', '$n', $expression);
+                $func_body = &quot;
+                        \$index = (int)($expression);
+                        return (\$index &lt; $nplurals)? \$index : $nplurals - 1;&quot;;
+                return create_function('$n', $func_body);
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         /**
</span><span class="lines">@@ -149,7 +154,7 @@
</span><span class="cx">          * @param string $expression the expression without parentheses
</span><span class="cx">          * @return string the expression with parentheses added
</span><span class="cx">          */
</span><del>-        function _parenthesize_plural_exression($expression) {
</del><ins>+        function parenthesize_plural_exression($expression) {
</ins><span class="cx">                 $expression .= ';';
</span><span class="cx">                 $res = '';
</span><span class="cx">                 $depth = 0;
</span><span class="lines">@@ -186,14 +191,61 @@
</span><span class="cx">                 }
</span><span class="cx">                 return $headers;
</span><span class="cx">         }
</span><del>-
</del><ins>+        
</ins><span class="cx">         function set_header($header, $value) {
</span><span class="cx">                 parent::set_header($header, $value);
</span><del>-                if ('Plural-Forms' == $header)
-                        $this-&gt;_gettext_select_plural_form = $this-&gt;_make_gettext_select_plural_form($value);
</del><ins>+                if ('Plural-Forms' == $header) {
+                        list( $nplurals, $expression ) = $this-&gt;nplurals_and_expression_from_header($this-&gt;get_header('Plural-Forms'));
+                        $this-&gt;_nplurals = $nplurals;
+                        $this-&gt;_gettext_select_plural_form = $this-&gt;make_plural_form_function($nplurals, $expression);
+                }
</ins><span class="cx">         }
</span><ins>+}
+endif;
</ins><span class="cx"> 
</span><ins>+if ( !class_exists( 'NOOP_Translations' ) ):
+/**
+ * Provides the same interface as Translations, but doesn't do anything
+ */
+class NOOP_Translations {
+        var $entries = array();
+        var $headers = array();
</ins><span class="cx">         
</span><ins>+        function add_entry($entry) {
+                return true;
+        }
+
+        function set_header($header, $value) {
+        }
+
+        function set_headers(&amp;$headers) {
+        }
+
+        function get_header($header) {
+                return false;
+        }
+
+        function translate_entry(&amp;$entry) {
+                return false;
+        }
+
+        function translate($singular, $context=null) {
+                return $singular;
+        }
+
+        function select_plural_form($count) {
+                return 1 == $count? 0 : 1;
+        }
+
+        function get_plural_forms_count() {
+                return 2;
+        }
+
+        function translate_plural($singular, $plural, $count, $context = null) {
+                        return 1 == $count? $singular : $plural;
+        }
+
+        function merge_with(&amp;$other) {
+        }
</ins><span class="cx"> }
</span><del>-
-?&gt;
</del><ins>+endif;
</ins></span></pre>
</div>
</div>

</body>
</html>