Index: trunk/extensions/Translate/FFS.php |
— | — | @@ -580,8 +580,7 @@ |
581 | 581 | ); |
582 | 582 | |
583 | 583 | /** |
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. |
586 | 585 | */ |
587 | 586 | protected function flattenPlural( $messages ) { |
588 | 587 | |
— | — | @@ -601,16 +600,22 @@ |
602 | 601 | if ( $key === 'other' ) continue; |
603 | 602 | $pls .= "|$key=$value"; |
604 | 603 | } |
| 604 | + |
| 605 | + // Put the "other" alternative last, without other= prefix |
605 | 606 | $other = isset($messages['other']) ? '|' . $messages['other'] : ''; |
606 | 607 | $pls .= "$other|}}"; |
607 | 608 | return $pls; |
608 | 609 | } |
609 | 610 | |
| 611 | + /** |
| 612 | + * Converts the special plural syntax to array or ruby style plurals |
| 613 | + */ |
610 | 614 | protected function unflattenPlural( $key, $message ) { |
611 | 615 | $regex = '~\{\{PLURAL\|(.*?)\|}}~s'; |
612 | 616 | $i = 0; |
613 | 617 | $matches = array(); |
614 | 618 | $match = array(); |
| 619 | + // First replace (possibly multiple ) plural instances into placeholders |
615 | 620 | while ( preg_match( $regex, $message, $match ) ) { |
616 | 621 | $matches[$i] = $match; |
617 | 622 | $message = preg_replace( $regex, "d__{$i}__b", $message ); |
— | — | @@ -624,6 +629,9 @@ |
625 | 630 | // The final array of alternative plurals forms |
626 | 631 | $alts = array(); |
627 | 632 | |
| 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. |
628 | 636 | $pluralChoice = implode( '|', array_keys(self::$pluralWords) ); |
629 | 637 | $regex = "~($pluralChoice)\s*=\s*(.+)~s"; |
630 | 638 | foreach ( $matches as $i => $plu ) { |