r72847 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r72846‎ | r72847 | r72848 >
Date:10:26, 12 September 2010
Author:nikerabbit
Status:ok
Tags:
Comment:
Implemented Gettext specific file headers
Modified paths:
  • /trunk/extensions/Translate/ffs/Gettext.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/ffs/Gettext.php
@@ -625,8 +625,11 @@
626626 // WRITE
627627 //
628628 protected function writeReal( MessageCollection $collection ) {
 629+ global $wgSitename;
629630 $output = $this->doHeader( $collection );
630631
 632+ $specs = array();
 633+
631634 $mangler = $this->group->getMangler();
632635 $messages = array();
633636 foreach ( $collection as $key => $m ) {
@@ -647,7 +650,7 @@
648651 }
649652
650653 protected function doHeader( MessageCollection $collection ) {
651 - global $wgSitename;
 654+ global $wgSitename, $wgServer;
652655 $code = $collection->code;
653656 $name = TranslateUtils::getLanguageName( $code );
654657 $native = TranslateUtils::getLanguageName( $code, true );
@@ -666,6 +669,33 @@
667670
668671 PHP;
669672
 673+ /// @todo twn specific
 674+ $portal = Title::makeTitle( NS_PORTAL, $code )->getFullUrl();
 675+
 676+ $specs = array();
 677+
 678+ $specs['Project-Id-Version'] = $this->group->getLabel();
 679+ $specs['Report-Msgid-Bugs'] = $wgSitename;
 680+ $specs['POT-Creation-Date'] = self::formatTime( $this->getPotTime() );
 681+ $specs['PO-Revision-Date'] = self::formatTime( wfTimestampNow() );
 682+ $specs['Language-Team'] = "$name <$portal>";
 683+ $specs['Content-Type'] = 'text/plain; charset=UTF-8';
 684+ $specs['Content-Transfer-Encoding'] = '8bit';
 685+ $specs['X-Generator'] = $this->getGenerator();
 686+ $specs['X-Translation-Project'] = "$wgSitename at $wgServer";
 687+ $specs['X-Language-Code'] = $code;
 688+ // Prepend # so that message import does not think this is a file it can import
 689+ $specs['X-Message-Group'] = '#' . $this->group->getId();
 690+
 691+ $output .= 'msgid ""' . "\n";
 692+ $output .= 'msgstr ""' . "\n";
 693+ $output .= '""' . "\n";
 694+
 695+ foreach ( $specs as $k => $v ) {
 696+ $output .= self::escape( "$k: $v\n" ) . "\n";
 697+ }
 698+
 699+
670700 return $output;
671701 }
672702
@@ -680,4 +710,30 @@
681711
682712 return $output;
683713 }
 714+
 715+ protected static function formatTime( $time ) {
 716+ $lang = Language::factory( 'en' );
 717+ return $lang->sprintfDate( 'xnY-xnm-xnd xnH:xni:xns+0000', $time );
 718+ }
 719+
 720+ protected function getPotTime() {
 721+ $defs = new MessageGroupCache( $this->group );
 722+ return $defs->exists() ? $defs->getTimestamp() : wfTimestampNow();
 723+ }
 724+
 725+ protected function getGenerator() {
 726+ return 'MediaWiki ' . SpecialVersion::getVersion() .
 727+ "; Translate extension (" . TRANSLATE_VERSION . ")";
 728+ }
 729+
 730+ protected static function escape( $line ) {
 731+ // There may be \ as a last character, for keeping trailing whitespace
 732+ $line = preg_replace( '/\\\\$/', '', $line );
 733+ $line = addcslashes( $line, '\\"' );
 734+ $line = str_replace( "\n", '\n', $line );
 735+ $line = '"' . $line . '"';
 736+
 737+ return $line;
 738+ }
 739+
684740 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r72848Remove unused code from r72847nikerabbit10:29, 12 September 2010

Status & tagging log