r107242 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107241‎ | r107242 | r107243 >
Date:23:30, 24 December 2011
Author:jarry1250
Status:deferred (Comments)
Tags:
Comment:
Sort languages before displaying; make languages collapsible; if nothing to translate don't try; and fallback if textbox left blank (presumably this is the least astonishing outcome).
Modified paths:
  • /trunk/extensions/TranslateSvg/SpecialTranslateSvg.php (modified) (history)
  • /trunk/extensions/TranslateSvg/TranslateSvg.i18n.php (modified) (history)
  • /trunk/extensions/TranslateSvg/ext.translateSvg.core.js (modified) (history)

Diff [purge]

Index: trunk/extensions/TranslateSvg/TranslateSvg.i18n.php
@@ -25,7 +25,10 @@
2626 'translatesvg-fallbackdesc' => 'Default (no language specified)',
2727 'translatesvg-qqqdesc' => 'Advice to translators',
2828 'translatesvg-nodesc' => '(no description)',
29 - 'translatesvg-remove' => 'Remove all translations in this language'
 29+ 'translatesvg-remove' => 'Remove all translations in this language',
 30+ 'translatesvg-unsuccessful' => "This file '''could not be translated''', sorry.",
 31+ 'translatesvg-toggle-view' => 'View translations in this language',
 32+ 'translatesvg-toggle-hide' => 'Hide translations in this language'
3033 );
3134
3235 /** Message documentation (Message documentation)
@@ -45,6 +48,9 @@
4649 'translatesvg-qqqdesc' => 'The heading of the section that contains descriptions of the context of each translation (i.e. translations into the language with code "qqq"). Comparable to other language headings such as "English", "Deutsch", etc.',
4750 'translatesvg-nodesc' => 'The text that appears next to a translation when no description (translation into language qqq) exists.',
4851 'translatesvg-remove' => 'Tooltip for a link attached to each translation language group which remove all form elements relating to the language group it is attached to',
 52+ 'translatesvg-unsuccessful' => 'A very general error message (bold and italics may be used to draw attention to it)',
 53+ 'translatesvg-toggle-view' => 'A toggle label; clicking on it causes extra form elements to appear',
 54+ 'translatesvg-toggle-hide' => 'A toggle label; clicking on it causes form elements to disappear'
4955 );
5056
5157 /** Breton (Brezhoneg)
Index: trunk/extensions/TranslateSvg/SpecialTranslateSvg.php
@@ -56,7 +56,7 @@
5757 $this->printTranslations( $file->getName() );
5858 }
5959 } else {
60 - $this->getOutput()->addHTML( '<p>This file could not be translated, sorry.</p>' ); //TODO: internationalise
 60+ $this->getOutput()->addHTML( Html::element( 'p', null, wfMessage( 'translatesvg-unsuccessful' )->parse() ) );
6161 }
6262 } else {
6363 $this->getOutput()->setStatusCode( 404 );
@@ -89,6 +89,9 @@
9090 function makeTranslationReady() {
9191 $texts = $this->svg->getElementsByTagName( "text" );
9292 $length = $texts->length;
 93+ if( $length === 0 ){
 94+ return false; //Nothing to translate!
 95+ }
9396 for( $i = 0; $i < $length; $i++){
9497 $text = $texts->item( $i );
9598 $ancestorswitches = $this->xpath->query( "ancestor::svg:switch", $text );
@@ -195,6 +198,7 @@
196199 $languages = Language::getLanguageNames();
197200 $languages['fallback'] = wfMsg( 'translatesvg-fallbackdesc');
198201 $languages['qqq'] = wfMsg( 'translatesvg-qqqdesc' );
 202+ uksort($this->translations, "self::customsort");
199203
200204 $this->getOutput()->addModules( 'ext.translateSvg' );
201205 $html = $this->thumb .
@@ -207,7 +211,9 @@
208212 foreach( $this->translations as $language=>$translations ){
209213 $html .= Html::openElement( 'fieldset', array( 'id' => "mw-translatesvg-fieldset-$language" ) ) .
210214 Html::element( 'legend', null, $languages[$language] ) .
211 - Html::openElement( 'div', array( 'class' => "mw-translatesvg-collapsible" ) );
 215+ Html::openElement( 'div', array( 'class' => 'mw-collapsible mw-collapsed',
 216+ 'data-collapsetext' => wfMsg( 'translatesvg-toggle-hide' ),
 217+ 'data-expandtext' => wfMsg( 'translatesvg-toggle-view' ) ) );
212218 $groups = array();
213219 for( $i = 0; $i < $this->number; $i++ ){
214220 $fallback = $this->getFallback( $i );
@@ -287,7 +293,7 @@
288294 */
289295 function updateTranslations( $params ){
290296 foreach( $params as $name=>$value ){
291 - list( $lang, $num, $param ) = explode( '-', $name );
 297+ list( $lang, $num, $param ) = explode( '-', substr( $name, 16 ) );
292298 if( !isset( $this->translations[ $lang ][ $num ] ) ){
293299 if( $lang !== 'qqq' ){
294300 $this->translations[ $lang ][ $num ] = $this->getFallback( $num );
@@ -295,7 +301,9 @@
296302 $this->translations[ $lang ][ $num ] = array();
297303 }
298304 }
299 - $this->translations[ $lang ][ $num ][ $param ] = $value;
 305+ if( $value !== '' ){
 306+ $this->translations[ $lang ][ $num ][ $param ] = $value;
 307+ }
300308 }
301309
302310 $reverse = array();
@@ -395,11 +403,18 @@
396404
397405 $this->mLocalFile = $mUpload->getLocalFile();
398406 $watch = true; //TODO
399 - unset( $this->added['fallback'] );
400407 $comment = "Updating translations:";
401408 if( count( $this->added ) > 0 ) $comment .= " added " . implode( ", ", array_keys( $this->added ) ) . ";";
402409 if( count( $this->modified ) > 0 ) $comment .= " modified " . implode( ", ", array_keys( $this->modified ) ) . ";";
403410 $comment = trim( $comment, ";" ) . ".";
 411+
 412+ if( ( ( count( $this->added ) == 1 && isset( $this->added['qqq'] ) ) || count( $this->added ) == 0 )
 413+ && count( $this->modified ) == 0 ){
 414+ //No real change, jump to save
 415+ $this->getOutput()->redirect( $this->mLocalFile->getTitle()->getFullURL() );
 416+ return;
 417+ }
 418+
404419 $status = $mUpload->performUpload( $comment, false, $watch, $this->getUser() );
405420 if ( !$status->isGood() ) {
406421 //TODO
@@ -410,6 +425,13 @@
411426 // Success, redirect to description page
412427 $this->getOutput()->redirect( $this->mLocalFile->getTitle()->getFullURL() );
413428 }
 429+ static function customsort( $a, $b ) {
 430+ if( $a == 'qqq' ) return 1;
 431+ if( $b == 'qqq' ) return -1;
 432+ if( $a == 'fallback' ) return 1;
 433+ if( $b == 'fallback' ) return -1;
 434+ return strcasecmp($a, $b);
 435+ }
414436 }
415437
416438 class TranslateSvgUpload extends UploadBase {
Index: trunk/extensions/TranslateSvg/ext.translateSvg.core.js
@@ -79,6 +79,10 @@
8080 $( this ).text( langname );
8181 $( this ).append( '&#160;' ).append( getRemoveLink() );
8282 } );
 83+ newfieldset.find( 'div.mw-collapsible.mw-made-collapsible' ).first().each( function(){
 84+ $(this).find( '.mw-collapsible-toggle' ).first().remove();
 85+ $(this).removeClass().addClass( 'mw-collapsible mw-collapsed' ).makeCollapsible();
 86+ } );
8387 return newfieldset;
8488 }
8589

Follow-up revisions

RevisionCommit summaryAuthorDate
r107290Followup r107242, 107233: rework to reduce indentation in various places; imp...jarry125020:33, 25 December 2011

Comments

#Comment by Nikerabbit (talk | contribs)   11:26, 25 December 2011
-$this->getOutput()->addHTML( Html::element( 'p', null, wfMessage( 'translatesvg-unsuccessful' )->parse() ) );
+$this->getOutput->addWikiMsg( 'translatesvg-unsuccessful' ); // Better

The indendation is off here:

+					Html::openElement( 'div', array( 'class' => 'mw-collapsible mw-collapsed',
+													'data-collapsetext' => wfMsg( 'translatesvg-toggle-hide' ),
+													'data-expandtext' => wfMsg( 'translatesvg-toggle-view' ) ) );

Status & tagging log