<!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>[16073] trunk: Introduce and use translate_nooped_plural().</title>
</head>
<body>

<div id="msg">
<dl>
<dt>Revision</dt> <dd><a href="http://trac.wordpress.org/changeset/16073">16073</a></dd>
<dt>Author</dt> <dd>nbachiyski</dd>
<dt>Date</dt> <dd>2010-10-29 13:12:14 +0000 (Fri, 29 Oct 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre>Introduce and use translate_nooped_plural(). Fixes <a href="http://trac.wordpress.org/ticket/13996">#13996</a>

 * _n_noop() and _nx_noop() now return associative arrays for greater clarity
 * translate_nooped_plural() takes one such associative array and translates it
 * it works on both the result from _n_noop() and from _nx_noop()
 * this breaks backwards compatibility, but I doubt any plugin uses it (I will do a global grep to confirm)
 * translate_nooped_plural() is applied where applicable</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkwpadminincludeslisttablecommentsphp">trunk/wp-admin/includes/list-table-comments.php</a></li>
<li><a href="#trunkwpadminincludeslisttablemediaphp">trunk/wp-admin/includes/list-table-media.php</a></li>
<li><a href="#trunkwpadminincludeslisttablepostsphp">trunk/wp-admin/includes/list-table-posts.php</a></li>
<li><a href="#trunkwpadminincludesmediaphp">trunk/wp-admin/includes/media.php</a></li>
<li><a href="#trunkwpincludesl10nphp">trunk/wp-includes/l10n.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkwpadminincludeslisttablecommentsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/list-table-comments.php (16072 => 16073)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/list-table-comments.php        2010-10-29 07:46:35 UTC (rev 16072)
+++ trunk/wp-admin/includes/list-table-comments.php        2010-10-29 13:12:14 UTC (rev 16073)
</span><span class="lines">@@ -149,7 +149,7 @@
</span><span class="cx">                                 $link = add_query_arg( 's', esc_attr( stripslashes( $_REQUEST['s'] ) ), $link );
</span><span class="cx">                         */
</span><span class="cx">                         $status_links[$status] = &quot;&lt;li class='$status'&gt;&lt;a href='$link'$class&gt;&quot; . sprintf(
</span><del>-                                _n( $label[0], $label[1], $num_comments-&gt;$status ),
</del><ins>+                                translate_nooped_plural( $label, $num_comments-&gt;$status ),
</ins><span class="cx">                                 number_format_i18n( $num_comments-&gt;$status )
</span><span class="cx">                         ) . '&lt;/a&gt;';
</span><span class="cx">                 }
</span></span></pre></div>
<a id="trunkwpadminincludeslisttablemediaphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/list-table-media.php (16072 => 16073)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/list-table-media.php        2010-10-29 07:46:35 UTC (rev 16072)
+++ trunk/wp-admin/includes/list-table-media.php        2010-10-29 13:12:14 UTC (rev 16073)
</span><span class="lines">@@ -67,7 +67,7 @@
</span><span class="cx">                         if ( !empty($_GET['post_mime_type']) &amp;&amp; wp_match_mime_types($mime_type, $_GET['post_mime_type']) )
</span><span class="cx">                                 $class = ' class=&quot;current&quot;';
</span><span class="cx">                         if ( !empty( $num_posts[$mime_type] ) )
</span><del>-                                $type_links[$mime_type] = &quot;&lt;li&gt;&lt;a href='upload.php?post_mime_type=$mime_type'$class&gt;&quot; . sprintf( _n( $label[2][0], $label[2][1], $num_posts[$mime_type] ), number_format_i18n( $num_posts[$mime_type] )) . '&lt;/a&gt;';
</del><ins>+                                $type_links[$mime_type] = &quot;&lt;li&gt;&lt;a href='upload.php?post_mime_type=$mime_type'$class&gt;&quot; . sprintf( translate_nooped_plural( $label[2], $num_posts[$mime_type] ), number_format_i18n( $num_posts[$mime_type] )) . '&lt;/a&gt;';
</ins><span class="cx">                 }
</span><span class="cx">                 $type_links['detached'] = '&lt;li&gt;&lt;a href=&quot;upload.php?detached=1&quot;' . ( $detached ? ' class=&quot;current&quot;' : '' ) . '&gt;' . sprintf( _nx( 'Unattached &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;', 'Unattached &lt;span class=&quot;count&quot;&gt;(%s)&lt;/span&gt;', $total_orphans, 'detached files' ), number_format_i18n( $total_orphans ) ) . '&lt;/a&gt;';
</span><span class="cx"> 
</span></span></pre></div>
<a id="trunkwpadminincludeslisttablepostsphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/list-table-posts.php (16072 => 16073)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/list-table-posts.php        2010-10-29 07:46:35 UTC (rev 16072)
+++ trunk/wp-admin/includes/list-table-posts.php        2010-10-29 13:12:14 UTC (rev 16073)
</span><span class="lines">@@ -170,7 +170,7 @@
</span><span class="cx">                         if ( isset($_REQUEST['post_status']) &amp;&amp; $status_name == $_REQUEST['post_status'] )
</span><span class="cx">                                 $class = ' class=&quot;current&quot;';
</span><span class="cx"> 
</span><del>-                        $status_links[$status_name] = &quot;&lt;li&gt;&lt;a href='edit.php?post_status=$status_name&amp;amp;post_type=$post_type'$class&gt;&quot; . sprintf( _n( $status-&gt;label_count[0], $status-&gt;label_count[1], $num_posts-&gt;$status_name ), number_format_i18n( $num_posts-&gt;$status_name ) ) . '&lt;/a&gt;';
</del><ins>+                        $status_links[$status_name] = &quot;&lt;li&gt;&lt;a href='edit.php?post_status=$status_name&amp;amp;post_type=$post_type'$class&gt;&quot; . sprintf( translate_nooped_plural( $status-&gt;label_count, $num_posts-&gt;$status_name ), number_format_i18n( $num_posts-&gt;$status_name ) ) . '&lt;/a&gt;';
</ins><span class="cx">                 }
</span><span class="cx"> 
</span><span class="cx">                 if ( ! empty( $this-&gt;sticky_posts_count ) ) {
</span></span></pre></div>
<a id="trunkwpadminincludesmediaphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-admin/includes/media.php (16072 => 16073)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-admin/includes/media.php        2010-10-29 07:46:35 UTC (rev 16072)
+++ trunk/wp-admin/includes/media.php        2010-10-29 13:12:14 UTC (rev 16073)
</span><span class="lines">@@ -1863,7 +1863,7 @@
</span><span class="cx">         if ( isset($_GET['post_mime_type']) &amp;&amp; wp_match_mime_types($mime_type, $_GET['post_mime_type']) )
</span><span class="cx">                 $class = ' class=&quot;current&quot;';
</span><span class="cx"> 
</span><del>-        $type_links[] = &quot;&lt;li&gt;&lt;a href='&quot; . esc_url(add_query_arg(array('post_mime_type'=&gt;$mime_type, 'paged'=&gt;false))) . &quot;'$class&gt;&quot; . sprintf(_n($label[2][0], $label[2][1], $num_posts[$mime_type]), &quot;&lt;span id='$mime_type-counter'&gt;&quot; . number_format_i18n( $num_posts[$mime_type] ) . '&lt;/span&gt;') . '&lt;/a&gt;';
</del><ins>+        $type_links[] = &quot;&lt;li&gt;&lt;a href='&quot; . esc_url(add_query_arg(array('post_mime_type'=&gt;$mime_type, 'paged'=&gt;false))) . &quot;'$class&gt;&quot; . sprintf( translate_nooped_plural( $label[2], $num_posts[$mime_type] ), &quot;&lt;span id='$mime_type-counter'&gt;&quot; . number_format_i18n( $num_posts[$mime_type] ) . '&lt;/span&gt;') . '&lt;/a&gt;';
</ins><span class="cx"> }
</span><span class="cx"> echo implode(' | &lt;/li&gt;', apply_filters( 'media_upload_mime_type_links', $type_links ) ) . '&lt;/li&gt;';
</span><span class="cx"> unset($type_links);
</span></span></pre></div>
<a id="trunkwpincludesl10nphp"></a>
<div class="modfile"><h4>Modified: trunk/wp-includes/l10n.php (16072 => 16073)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/wp-includes/l10n.php        2010-10-29 07:46:35 UTC (rev 16072)
+++ trunk/wp-includes/l10n.php        2010-10-29 13:12:14 UTC (rev 16073)
</span><span class="lines">@@ -267,15 +267,15 @@
</span><span class="cx">  *  );
</span><span class="cx">  *  ...
</span><span class="cx">  *  $message = $messages[$type];
</span><del>- *  $usable_text = sprintf(_n($message[0], $message[1], $count), $count);
</del><ins>+ *  $usable_text = sprintf( translate_nooped_plural( $message, $count ), $count );
</ins><span class="cx">  *
</span><span class="cx">  * @since 2.5
</span><span class="cx">  * @param string $single Single form to be i18ned
</span><span class="cx">  * @param string $plural Plural form to be i18ned
</span><span class="cx">  * @return array array($single, $plural)
</span><span class="cx">  */
</span><del>-function _n_noop( $single, $plural ) {
-        return array( $single, $plural );
</del><ins>+function _n_noop( $singular, $plural ) {
+        return array( 'singular' =&gt; $singular, 'plural' =&gt; $plural, 'context' =&gt; null );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><span class="lines">@@ -283,11 +283,26 @@
</span><span class="cx">  *
</span><span class="cx">  * @see _n_noop()
</span><span class="cx">  */
</span><del>-function _nx_noop( $single, $plural, $context ) {
-        return array( $single, $plural, $context );
</del><ins>+function _nx_noop( $singular, $plural, $context ) {
+        return array( 'singular' =&gt; $singular, 'plural' =&gt; $plural, 'context' =&gt; $context );
</ins><span class="cx"> }
</span><span class="cx"> 
</span><span class="cx"> /**
</span><ins>+ * Translate the result of _n_noop() or _nx_noop()
+ * 
+ * @since 3.1
+ * @param array $nooped_plural array with singular, plural and context keys, usually the result of _n_noop() or _nx_noop()
+ * @param int $count number of objects
+ * @param string $domain Optional. The domain identifier the text should be retrieved in
+ */
+function translate_nooped_plural( $nooped_plural, $count, $domain = 'default' ) {
+        if ( $nooped_plural['context'] )
+                return _nx( $nooped_plural['singular'], $nooped_plural['plural'], $count, $nooped_plural['context'], $domain );
+        else
+                return _n( $nooped_plural['singular'], $nooped_plural['plural'], $count, $domain );
+}
+
+/**
</ins><span class="cx">  * Loads a MO file into the domain $domain.
</span><span class="cx">  *
</span><span class="cx">  * If the domain already exists, the translations will be merged. If both
</span></span></pre>
</div>
</div>

</body>
</html>