http://www.mediawiki.org/wiki/Special:Code/MediaWiki/73241

Revision: 73241
Author:   siebrand
Date:     2010-09-17 19:05:58 +0000 (Fri, 17 Sep 2010)

Log Message:
-----------
Remove all traces of old style gettext support implementation.

Modified Paths:
--------------
    trunk/extensions/Translate/MessageGroups.php
    trunk/extensions/Translate/_autoload.php
    trunk/extensions/Translate/ffs/Gettext.php
    trunk/extensions/Translate/groups/StatusNet/README
    trunk/extensions/Translate/utils/TranslationHelpers.php

Modified: trunk/extensions/Translate/MessageGroups.php
===================================================================
--- trunk/extensions/Translate/MessageGroups.php        2010-09-17 18:54:40 UTC 
(rev 73240)
+++ trunk/extensions/Translate/MessageGroups.php        2010-09-17 19:05:58 UTC 
(rev 73241)
@@ -637,85 +637,6 @@
 }
 
 /**
- * This implements the old style message group for Gettext format.
- * @todo Move to the new interface.
- */
-class GettextMessageGroup extends MessageGroupOld {
-       protected $type = 'gettext';
-
-       /**
-        * Name of the array where all messages are stored, if applicable.
-        */
-       protected $potFile      = 'messages';
-       public function getPotFile() { return $this->potFile; }
-       public function setPotFile( $value ) { $this->potFile = $value; }
-
-       protected $codeMap = array();
-       public function setCodeMap( $map ) {
-               $this->codeMap = $map;
-       }
-
-       protected $path = '';
-       public function getPath() { return $this->path; }
-       public function setPath( $value ) { $this->path = $value; }
-
-       protected $prefix = '';
-       public function getPrefix() { return $this->prefix; }
-       public function setPrefix( $value ) { $this->prefix = $value; }
-
-       public $filePattern = '%CODE%.po';
-
-       public function getMessageFile( $code ) {
-               if ( $code == 'en' ) {
-                       return $this->getPotFile();
-               } else {
-                       $origCode = $code;
-
-                       if ( isset( $this->codeMap[$code] ) ) {
-                               $code = $this->codeMap[$code];
-                       }
-
-                       /** If this (valid) code is a mapped target, do not 
provide a file.
-                        * Example: 'no' => 'nb'.
-                        */
-                       $mappedCodes = array_values( $this->codeMap );
-                       if ( $code == $origCode && in_array( $code, 
$mappedCodes ) ) {
-                               return '';
-                       }
-
-                       return $this->replaceVariables( $this->filePattern, 
$code );
-               }
-       }
-
-       public function replaceVariables( $string, $code ) {
-               return str_replace( '%CODE%', $code, $string );
-       }
-
-       public static function factory( $label, $id ) {
-               $group = new GettextMessageGroup;
-               $group->setLabel( $label );
-               $group->setId( $id );
-
-               return $group;
-       }
-
-       public function getReader( $code ) {
-               $reader = new GettextFormatReader( 
$this->getMessageFileWithPath( $code ) );
-               $reader->setPrefix( $this->prefix );
-
-               if ( $code === 'en' ) {
-                       $reader->setPotMode( true );
-               }
-
-               return $reader;
-       }
-
-       public function getWriter() {
-               return new GettextFormatWriter( $this );
-       }
-}
-
-/**
  * Group for messages that can be controlled via a page in %MediaWiki 
namespace.
  *
  * In the page comments start with # and continue till the end of the line.

Modified: trunk/extensions/Translate/_autoload.php
===================================================================
--- trunk/extensions/Translate/_autoload.php    2010-09-17 18:54:40 UTC (rev 
73240)
+++ trunk/extensions/Translate/_autoload.php    2010-09-17 19:05:58 UTC (rev 
73241)
@@ -80,8 +80,6 @@
 $wgAutoloadClasses['WikiFormatWriter'] = $dir . 'ffs/Wiki.php';
 $wgAutoloadClasses['WikiExtensionFormatReader'] = $dir . 
'ffs/WikiExtension.php';
 $wgAutoloadClasses['WikiExtensionFormatWriter'] = $dir . 
'ffs/WikiExtension.php';
-$wgAutoloadClasses['GettextFormatReader'] = $dir . 'ffs/Gettext.php';
-$wgAutoloadClasses['GettextFormatWriter'] = $dir . 'ffs/Gettext.php';
 $wgAutoloadClasses['XliffFormatWriter'] = $dir . 'ffs/Xliff.php';
 /*...@}*/
 

Modified: trunk/extensions/Translate/ffs/Gettext.php
===================================================================
--- trunk/extensions/Translate/ffs/Gettext.php  2010-09-17 18:54:40 UTC (rev 
73240)
+++ trunk/extensions/Translate/ffs/Gettext.php  2010-09-17 19:05:58 UTC (rev 
73241)
@@ -15,348 +15,6 @@
 class GettextPluralException extends MwException {}
 
 /**
- * Old-style parser for gettext file format.
- */
-class GettextFormatReader extends SimpleFormatReader {
-       protected $pot = false;
-
-       public function setPotMode( $value ) {
-               $this->pot = $value;
-       }
-
-       protected $prefix = '';
-
-       public function setPrefix( $value ) {
-               $this->prefix = $value;
-       }
-
-       /**
-        * Get authors from gettext file.
-        *
-        * @todo Implement this.
-        * return \array List of authors
-        */
-       public function parseAuthors() {
-               return array();
-       }
-
-       /**
-        * Returns static header of gettext file.
-        * Static part recognition is based on finding "# --" as beginning and
-        * "msgid" as end.
-        * return /string Static header of gettext file.
-        */
-       public function parseStaticHeader() {
-               if ( $this->filename === false ) {
-                       return '';
-               }
-
-               $data = file_get_contents( $this->filename );
-               $start = (int) strpos( $data, '# --' );
-
-               if ( $start ) {
-                       $start += 5;
-               }
-
-               $end = (int) strpos( $data, "msgid" );
-
-               return substr( $data, $start, $end - $start );
-       }
-
-       public function parseFile() {
-               if ( $this->filename === false ) {
-                       return array();
-               }
-
-               $data = file_get_contents( $this->filename );
-               $parse = GettextFFS::parseGettextData( $data );
-
-               return $parse['TEMPLATE'];
-       }
-
-       public function parseFileExt() {
-               if ( $this->filename === false ) {
-                       return array();
-               }
-
-               $data = file_get_contents( $this->filename );
-
-               return GettextFFS::parseGettextData( $data );
-       }
-
-       public function parseMessages( StringMangler $mangler ) {
-               $defs = $this->parseFile();
-               $messages = array();
-
-               foreach ( $defs as $key => $def ) {
-                       if ( $this->pot ) {
-                               $messages[$key] = $def['id'];
-                       } else {
-                               if ( $def['str'] !== '' ) {
-                                       $messages[$key] = $def['str'];
-                               }
-                       }
-               }
-
-               return $mangler->mangle( $messages );
-       }
-}
-
-/**
- * Old-style writer for gettext file format.
- */
-class GettextFormatWriter extends SimpleFormatWriter {
-       protected $data = array();
-       protected $plural = array( false, 0 );
-
-       public function load( $code ) {
-               $reader = $this->group->getReader( $code );
-               $readerEn = $this->group->getReader( 'en' );
-
-               if ( $reader instanceof GettextFormatReader ) {
-                       $this->addAuthors( $reader->parseAuthors(), $code );
-                       $this->staticHeader = $reader->parseStaticHeader();
-                       $this->owndata = $reader->parseFileExt();
-               }
-
-               if ( $readerEn instanceof GettextFormatReader ) {
-                       $this->data = $readerEn->parseFile();
-               }
-       }
-
-       public function exportLanguage( $handle, MessageCollection $messages ) {
-               global $wgSitename, $wgServer, 
$wgTranslateDocumentationLanguageCode;
-
-               $code = $messages->code;
-               $this->load( $code );
-               $lang = Language::factory( 'en' );
-
-               $out = '';
-               $now = wfTimestampNow();
-               $label = $this->group->getLabel();
-               $languageName = TranslateUtils::getLanguageName( $code );
-
-               $headers = isset( $this->owndata['HEADERS'] ) ? 
$this->owndata['HEADERS'] : array();
-               $headers['Project-Id-Version'] = $label;
-
-               /**
-                * @todo Make this customisable or something
-                * $headers['Report-Msgid-Bugs-To'] = $wgServer;
-                */
-
-               /** @todo sprintfDate doesn't support any time zone flags
-                * $headers['POT-Creation-Date']
-                */
-
-               $headers['PO-Revision-Date'] = $lang->sprintfDate( 'xnY-xnm-xnd 
xnH:xni:xns+0000', $now );
-
-               /**
-                * @todo Link to portal pages?
-                * $headers['Language-Team'] = $languageName;
-                */
-
-               $headers['Content-Type'] = 'text/plain; charset=UTF-8';
-               $headers['Content-Transfer-Encoding'] = '8bit';
-
-               $headers['X-Generator'] = 'MediaWiki ' . 
SpecialVersion::getVersion() .
-                       "; Translate extension (" . TRANSLATE_VERSION . ")";
-
-               $headers['X-Translation-Project'] = "$wgSitename at $wgServer";
-               $headers['X-Language-Code'] = $code;
-               $headers['X-Message-Group'] = $this->group->getId();
-
-               $headerlines = array( '' );
-               foreach ( $headers as $key => $value ) {
-                       $headerlines[] = "$key: $value\n";
-               }
-
-               fwrite( $handle, "# Translation of $label to 
$languageName\n#\n" );
-               fwrite( $handle, $this->formatAuthors( "# aut...@$wgsitename: 
", $code ) );
-               fwrite( $handle, "# --\n" );
-
-               $header = preg_replace( '/^# translation of (.*) to 
(.*)$\n/im', '', $this->staticHeader );
-
-               fwrite( $handle, $header );
-               fwrite( $handle, $this->formatmsg( '', $headerlines  ) );
-
-               $mangler = $this->group->getMangler();
-
-               foreach ( $messages as $key => $m ) {
-                       $flags = array();
-
-                       $key = $mangler->unmangle( $key );
-
-                       $translation = $m->translation();
-                       # CASE2: no translation
-                       if ( $translation === null ) {
-                               $translation = '';
-                       }
-
-                       # CASE3: optional messages; accept only if different
-                       if ( $m->hasTag( 'optional' ) ) {
-                               $flags[] = 'x-optional';
-                       }
-
-                       # Remove explicit fuzzy markings from the translation 
before export
-                       $flags = array();
-                       $comments = array();
-                       if ( isset( $this->data[$key]['flags'] ) ) {
-                               $flags = $this->data[$key]['flags'];
-                       }
-
-                       if ( strpos( $translation, TRANSLATE_FUZZY ) !== false 
) {
-                               $translation = str_replace( TRANSLATE_FUZZY, 
'', $translation );
-                               $flags[] = 'fuzzy';
-                       }
-
-                       $documentation = '';
-                       if ( $wgTranslateDocumentationLanguageCode ) {
-                               $documentation = 
TranslateUtils::getMessageContent( $key, $wgTranslateDocumentationLanguageCode 
);
-                       }
-
-                       $comments = array();
-                       if ( isset( $this->data[$key]['comments'] ) ) {
-                               $comments = $this->data[$key]['comments'];
-                       }
-
-                       fwrite( $handle, self::formatComments( $comments, 
$documentation, $flags ) );
-
-                       $ckey = '';
-                       if ( isset( $this->data[$key]['ctxt'] ) ) {
-                               $ckey = $this->data[$key]['ctxt'];
-                       }
-
-                       $pluralForms = false;
-                       if ( isset( $this->owndata['METADATA']['plural'] ) ) {
-                               $pluralForms = 
$this->owndata['METADATA']['plural'];
-                       }
-
-                       fwrite( $handle, $this->formatmsg( $m->definition(), 
$translation, $ckey, $pluralForms ) );
-               }
-
-               return $out;
-       }
-
-       protected function escape( $line ) {
-               // There may be \ as a last character, for keeping trailing 
whitespace
-               $line = preg_replace( '/\\\\$/', '', $line );
-               $line = addcslashes( $line, '\\"' );
-               $line = str_replace( "\n", '\n', $line );
-               $line = '"' . $line . '"';
-
-               return $line;
-       }
-
-       public static function formatComments( $comments, $documentation = 
false, $flags = false ) {
-               if ( $documentation ) {
-                       foreach ( explode( "\n", $documentation ) as $line ) {
-                               $comments['.'][] = $line;
-                       }
-               }
-
-               if ( $flags ) {
-                       $comments[','][] = implode( ', ', $flags );
-               }
-
-               // Ensure there is always something
-               if ( !count( $comments ) ) {
-                       $comments[':'][] = '';
-               }
-
-               $order = array( '', '.', ':', ',', '|' );
-               $output = array();
-               foreach ( $order as $type ) {
-                       if ( !isset( $comments[$type] ) ) {
-                               continue;
-                       }
-
-                       foreach ( $comments[$type] as $value ) {
-                               $output[] = "#$type $value";
-                       }
-               }
-
-               return implode( "\n", $output ) . "\n";
-       }
-
-       protected function formatmsg( $msgid, $msgstr, $msgctxt = false, 
$pluralForms = false ) {
-               $output = array();
-
-               // @todo Very ugly hack to allow gettext plurals to be exported.
-               if ( $msgstr == '{{PLURAL:GETTEXT|}}' ) {
-                       return '';
-               }
-
-               if ( $msgctxt ) {
-                       $output[] = 'msgctxt ' . $this->escape( $msgctxt );
-               }
-
-               if ( preg_match( '/{{PLURAL:GETTEXT/i', $msgid ) ) {
-                       $forms = $this->splitPlural( $msgid, 2 );
-                       $output[] = 'msgid ' . $this->escape( $forms[0] );
-                       $output[] = 'msgid_plural ' . $this->escape( $forms[1] 
);
-
-                       try {
-                               $forms = $this->splitPlural( $msgstr, 
$pluralForms );
-                               foreach ( $forms as $index => $form ) {
-                                       $output[] = "msgstr[$index] " . 
$this->escape( $form );
-                               }
-                       } catch ( GettextPluralException $e ) {
-                               $output[] = "# Plural problem";
-                       }
-               } else {
-                       $output[] = 'msgid ' . $this->escape( $msgid );
-
-                       // Special case for the header
-                       if ( is_array( $msgstr ) ) {
-                               $output[] = 'msgstr ""';
-                               foreach ( $msgstr as $line )
-                                       $output[] = $this->escape( $line );
-                       } else {
-                               $output[] = 'msgstr ' . $this->escape( $msgstr 
);
-                       }
-               }
-
-               $out = implode( "\n", $output ) . "\n\n";
-
-               return $out;
-
-       }
-
-       protected function splitPlural( $text, $forms ) {
-               if ( $forms === 1 ) {
-                       return $text;
-               } elseif ( !$forms ) {
-                       $forms = (int) $forms;
-                       throw new GettextPluralException( "Don't know how to 
split $text into $forms forms" );
-               }
-
-               $splitPlurals = array();
-               for ( $i = 0; $i < $forms; $i++ ) {
-                       $plurals = array();
-                       $match = preg_match_all( 
'/{{PLURAL:GETTEXT\|(.*)}}/iU', $text, $plurals );
-
-                       if ( !$match ) {
-                               throw new GettextPluralException( "Failed to 
parse plural for: $text" );
-                       }
-
-                       $pluralForm = $text;
-                       foreach ( $plurals[0] as $index => $definition ) {
-                               $parsedFormsArray = explode( '|', 
$plurals[1][$index] );
-                               if ( !isset( $parsedFormsArray[$i] ) ) {
-                                       error_log( "Too few plural forms in: 
$text" );
-                                       $pluralForm = '';
-                               } else {
-                                       $pluralForm = str_replace( $pluralForm, 
$definition, $parsedFormsArray[$i] );
-                               }
-                       }
-                       $splitPlurals[$i] = $pluralForm;
-               }
-
-               return $splitPlurals;
-       }
-}
-
-/**
  * New-style FFS class that implements support for gettext file format.
  * @ingroup FFS
  */

Modified: trunk/extensions/Translate/groups/StatusNet/README
===================================================================
--- trunk/extensions/Translate/groups/StatusNet/README  2010-09-17 18:54:40 UTC 
(rev 73240)
+++ trunk/extensions/Translate/groups/StatusNet/README  2010-09-17 19:05:58 UTC 
(rev 73241)
@@ -7,34 +7,5 @@
 
 Settings:
 wfAddNamespace( 1208, 'StatusNet' );
-
-As long as new message groups have not yet been implemented for gettext, the
-following settings are needed:
-
-$wgHooks['TranslatePostInitGroups'][] = array( 'setupStatusnet' );
-
-function setupStatusnet( &$cc ) {
-        global $wgTranslateGroupRoot;
-        global $IP;
-        $id = 'out-statusnet';
-        $mg = GettextMessageGroup::factory( 'StatusNet', $id );
-        $mg->setPotFile( 'locale/statusnet.pot' );
-        $mg->setPath( "$wgTranslateGroupRoot/statusnet/" );
-        $mg->filePattern = "locale/%CODE%/LC_MESSAGES/statusnet.po";
-        $mg->setDescription( "{{int:bw-desc-statusnet}}" );
-        $mg->namespaces = array( NS_STATUSNET, NS_STATUSNET_TALK );
-        $mg->setCodeMap( array(
-                'en-gb' => 'en_GB',
-                'no' => 'nb',
-                'pt-br' => 'pt_BR',
-                'zh-hans' => 'zh_CN',
-                'zh-hant' => 'zh_TW'
-        ) );
-        $cc[$id] = $mg;
-        return true;
-}
-
-When GettextMessageGroupFFS has been implemented, the following will suffice:
 $wgTranslateGroupFiles[] = 
"$IP/extensions/Translate/groups/StatusNet/StatusNet.yml";
-
-Add more to $wgTranslateGroupFiles for supported plugins.
+$wgTranslateGroupFiles[] = 
"$IP/extensions/Translate/groups/StatusNet/StatusNet-plugins.yml";

Modified: trunk/extensions/Translate/utils/TranslationHelpers.php
===================================================================
--- trunk/extensions/Translate/utils/TranslationHelpers.php     2010-09-17 
18:54:40 UTC (rev 73240)
+++ trunk/extensions/Translate/utils/TranslationHelpers.php     2010-09-17 
19:05:58 UTC (rev 73241)
@@ -682,21 +682,6 @@
        }
 
        protected function formatGettextComments() {
-               if ( $this->group instanceof GettextMessageGroup ) {
-                       $reader = $this->group->getReader( 'en' );
-                       if ( $reader ) {
-                               global $wgContLang;
-
-                               $mykey = $wgContLang->lcfirst( $this->page );
-                               $data = $reader->parseFile();
-                               $help = trim( 
GettextFormatWriter::formatComments( @$data[$mykey]['comments'], false, 
@$data[$mykey]['flags'] ) );
-                               // Do not display an empty comment. That's no 
help and takes up unnecessary space.
-                               if ( $help !== '#:' ) {
-                                       return "<hr /><pre>$help</pre>";
-                               }
-                       }
-               }
-
                if ( $this->group instanceof FileBasedMessageGroup ) {
                        $ffs = $this->group->getFFS();
                        if ( $ffs instanceof GettextFFS ) {



_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to