r56815 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r56814‎ | r56815 | r56816 >
Date:13:00, 23 September 2009
Author:nikerabbit
Status:ok
Tags:
Comment:
Update comments
Modified paths:
  • /trunk/extensions/Translate/FFS.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/FFS.php
@@ -580,8 +580,7 @@
581581 );
582582
583583 /**
584 - * Flattens multidimensional array by using the path to the value as key
585 - * with each individual key separated by a dot.
 584+ * Flattens ruby plural arrays into special plural syntax.
586585 */
587586 protected function flattenPlural( $messages ) {
588587
@@ -601,16 +600,22 @@
602601 if ( $key === 'other' ) continue;
603602 $pls .= "|$key=$value";
604603 }
 604+
 605+ // Put the "other" alternative last, without other= prefix
605606 $other = isset($messages['other']) ? '|' . $messages['other'] : '';
606607 $pls .= "$other|}}";
607608 return $pls;
608609 }
609610
 611+ /**
 612+ * Converts the special plural syntax to array or ruby style plurals
 613+ */
610614 protected function unflattenPlural( $key, $message ) {
611615 $regex = '~\{\{PLURAL\|(.*?)\|}}~s';
612616 $i = 0;
613617 $matches = array();
614618 $match = array();
 619+ // First replace (possibly multiple ) plural instances into placeholders
615620 while ( preg_match( $regex, $message, $match ) ) {
616621 $matches[$i] = $match;
617622 $message = preg_replace( $regex, "d__{$i}__b", $message );
@@ -624,6 +629,9 @@
625630 // The final array of alternative plurals forms
626631 $alts = array();
627632
 633+ // Then loop trough each plural block and replacing the placeholders
 634+ // to construct the alternatives. Produces invalid output if there is
 635+ // multiple plural bocks which don't have the same set of keys.
628636 $pluralChoice = implode( '|', array_keys(self::$pluralWords) );
629637 $regex = "~($pluralChoice)\s*=\s*(.+)~s";
630638 foreach ( $matches as $i => $plu ) {

Status & tagging log