Index: trunk/extensions/Translate/ffs/Gettext.php |
— | — | @@ -631,6 +631,23 @@ |
632 | 632 | $potTemplate = isset( $pot['TEMPLATE'][$key] ) ? |
633 | 633 | $pot['TEMPLATE'][$key] : array(); |
634 | 634 | |
| 635 | + $comments = array(); |
| 636 | + if ( isset( $potTemplate['comments'] ) ) { |
| 637 | + $comments = $potTemplate['comments']; |
| 638 | + } elseif ( isset( $transTemplate['comments'] ) ) { |
| 639 | + $comments = $transTemplate['comments']; |
| 640 | + } |
| 641 | + |
| 642 | + $header = ''; |
| 643 | + |
| 644 | + $header .= self::formatDocumentation( $key ); |
| 645 | + foreach ( $comments as $type => $typecomments ) { |
| 646 | + foreach ( $typecomments as $comment ) { |
| 647 | + if ( strpos( $comment, '[Wiki]' ) === 0 ) continue; |
| 648 | + $header .= "#$type $comment\n"; |
| 649 | + } |
| 650 | + } |
| 651 | + |
635 | 652 | $tags = $m->getTags(); |
636 | 653 | $flags = isset( $transTemplate['flags'] ) ? $transTemplate['flags'] : array(); |
637 | 654 | |
— | — | @@ -638,9 +655,16 @@ |
639 | 656 | |
640 | 657 | if ( $outFlags ) { |
641 | 658 | sort( $outFlags ); |
642 | | - $output .= "#, " . implode( ', ', $outFlags ) . "\n"; |
| 659 | + $header .= "#, " . implode( ', ', $outFlags ) . "\n"; |
643 | 660 | } |
644 | 661 | |
| 662 | + if ( $header ) { |
| 663 | + $output .= $header; |
| 664 | + } else { |
| 665 | + // Must be at least empty comment |
| 666 | + $output .= "#\n"; |
| 667 | + } |
| 668 | + |
645 | 669 | if ( isset( $potTemplate['msgctxt'] ) ) { |
646 | 670 | $output .= 'msgctxt ' . self::escape( $potTemplate['msgctxt'] ) . "\n"; |
647 | 671 | } |
— | — | @@ -681,8 +705,8 @@ |
682 | 706 | |
683 | 707 | $specs['Project-Id-Version'] = $this->group->getLabel(); |
684 | 708 | $specs['Report-Msgid-Bugs-To'] = $wgSitename; |
685 | | - $specs['POT-Creation-Date'] = self::formatTime( $this->getPotTime() ); |
686 | 709 | $specs['PO-Revision-Date'] = self::formatTime( wfTimestampNow() ); |
| 710 | + $specs['X-POT-Import-Date'] = self::formatTime( $this->getPotTime() ); |
687 | 711 | $specs['Language-Team'] = "$name <$portal>"; |
688 | 712 | $specs['Content-Type'] = 'text/plain; charset=UTF-8'; |
689 | 713 | $specs['Content-Transfer-Encoding'] = '8bit'; |
— | — | @@ -691,6 +715,12 @@ |
692 | 716 | $specs['X-Language-Code'] = $code; |
693 | 717 | // Prepend # so that message import does not think this is a file it can import |
694 | 718 | $specs['X-Message-Group'] = '#' . $this->group->getId(); |
| 719 | + $plural = self::getPluralRule( $code ); |
| 720 | + if ( $plural ) { |
| 721 | + $specs['Plural-Forms'] = $plural; |
| 722 | + } elseif( !isset( $specs['Plural-Forms'] ) ) { |
| 723 | + $specs['Plural-Forms'] = 'nplurals=2; plural=(n != 1);'; |
| 724 | + } |
695 | 725 | |
696 | 726 | $output .= 'msgid ""' . "\n"; |
697 | 727 | $output .= 'msgstr ""' . "\n"; |
— | — | @@ -732,6 +762,23 @@ |
733 | 763 | "; Translate extension (" . TRANSLATE_VERSION . ")"; |
734 | 764 | } |
735 | 765 | |
| 766 | + protected static function formatDocumentation( $key ) { |
| 767 | + global $wgTranslateDocumentationLanguageCode; |
| 768 | + |
| 769 | + $code = $wgTranslateDocumentationLanguageCode; |
| 770 | + if ( !$code ) return ''; |
| 771 | + |
| 772 | + $documentation = TranslateUtils::getMessageContent( $key, $code ); |
| 773 | + if ( !is_string( $documentation ) ) return ''; |
| 774 | + |
| 775 | + $lines = explode( "\n", $documentation ); |
| 776 | + $out = ''; |
| 777 | + foreach ( $lines as $line ) { |
| 778 | + $out .= "#. [Wiki] $line\n"; |
| 779 | + } |
| 780 | + return $out; |
| 781 | + } |
| 782 | + |
736 | 783 | protected static function escape( $line ) { |
737 | 784 | // There may be \ as a last character, for keeping trailing whitespace |
738 | 785 | $line = preg_replace( '/\\\\$/', '', $line ); |
— | — | @@ -742,4 +789,20 @@ |
743 | 790 | return $line; |
744 | 791 | } |
745 | 792 | |
| 793 | + /** |
| 794 | + * Returns plural rule for Gettext. |
| 795 | + * @param $code \string Language code. |
| 796 | + * @return \string |
| 797 | + */ |
| 798 | + public static function getPluralRule( $code ) { |
| 799 | + $rulefile = dirname( __FILE__ ) . '/../data/plural-gettext.txt'; |
| 800 | + $rules = file_get_contents( $rulefile ); |
| 801 | + foreach ( explode( "\n", $rules ) as $line ) { |
| 802 | + if ( trim( $line ) === '' ) continue; |
| 803 | + list( $rulecode, $rule ) = explode( "\t", $line ); |
| 804 | + if ( $rulecode === $code ) return $rule; |
| 805 | + } |
| 806 | + return ''; |
| 807 | + } |
| 808 | + |
746 | 809 | } |