Index: trunk/extensions/TranslateSvg/TranslateSvg.i18n.php |
— | — | @@ -25,7 +25,10 @@ |
26 | 26 | 'translatesvg-fallbackdesc' => 'Default (no language specified)', |
27 | 27 | 'translatesvg-qqqdesc' => 'Advice to translators', |
28 | 28 | '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' |
30 | 33 | ); |
31 | 34 | |
32 | 35 | /** Message documentation (Message documentation) |
— | — | @@ -45,6 +48,9 @@ |
46 | 49 | '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.', |
47 | 50 | 'translatesvg-nodesc' => 'The text that appears next to a translation when no description (translation into language qqq) exists.', |
48 | 51 | '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' |
49 | 55 | ); |
50 | 56 | |
51 | 57 | /** Breton (Brezhoneg) |
Index: trunk/extensions/TranslateSvg/SpecialTranslateSvg.php |
— | — | @@ -56,7 +56,7 @@ |
57 | 57 | $this->printTranslations( $file->getName() ); |
58 | 58 | } |
59 | 59 | } 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() ) ); |
61 | 61 | } |
62 | 62 | } else { |
63 | 63 | $this->getOutput()->setStatusCode( 404 ); |
— | — | @@ -89,6 +89,9 @@ |
90 | 90 | function makeTranslationReady() { |
91 | 91 | $texts = $this->svg->getElementsByTagName( "text" ); |
92 | 92 | $length = $texts->length; |
| 93 | + if( $length === 0 ){ |
| 94 | + return false; //Nothing to translate! |
| 95 | + } |
93 | 96 | for( $i = 0; $i < $length; $i++){ |
94 | 97 | $text = $texts->item( $i ); |
95 | 98 | $ancestorswitches = $this->xpath->query( "ancestor::svg:switch", $text ); |
— | — | @@ -195,6 +198,7 @@ |
196 | 199 | $languages = Language::getLanguageNames(); |
197 | 200 | $languages['fallback'] = wfMsg( 'translatesvg-fallbackdesc'); |
198 | 201 | $languages['qqq'] = wfMsg( 'translatesvg-qqqdesc' ); |
| 202 | + uksort($this->translations, "self::customsort"); |
199 | 203 | |
200 | 204 | $this->getOutput()->addModules( 'ext.translateSvg' ); |
201 | 205 | $html = $this->thumb . |
— | — | @@ -207,7 +211,9 @@ |
208 | 212 | foreach( $this->translations as $language=>$translations ){ |
209 | 213 | $html .= Html::openElement( 'fieldset', array( 'id' => "mw-translatesvg-fieldset-$language" ) ) . |
210 | 214 | 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' ) ) ); |
212 | 218 | $groups = array(); |
213 | 219 | for( $i = 0; $i < $this->number; $i++ ){ |
214 | 220 | $fallback = $this->getFallback( $i ); |
— | — | @@ -287,7 +293,7 @@ |
288 | 294 | */ |
289 | 295 | function updateTranslations( $params ){ |
290 | 296 | foreach( $params as $name=>$value ){ |
291 | | - list( $lang, $num, $param ) = explode( '-', $name ); |
| 297 | + list( $lang, $num, $param ) = explode( '-', substr( $name, 16 ) ); |
292 | 298 | if( !isset( $this->translations[ $lang ][ $num ] ) ){ |
293 | 299 | if( $lang !== 'qqq' ){ |
294 | 300 | $this->translations[ $lang ][ $num ] = $this->getFallback( $num ); |
— | — | @@ -295,7 +301,9 @@ |
296 | 302 | $this->translations[ $lang ][ $num ] = array(); |
297 | 303 | } |
298 | 304 | } |
299 | | - $this->translations[ $lang ][ $num ][ $param ] = $value; |
| 305 | + if( $value !== '' ){ |
| 306 | + $this->translations[ $lang ][ $num ][ $param ] = $value; |
| 307 | + } |
300 | 308 | } |
301 | 309 | |
302 | 310 | $reverse = array(); |
— | — | @@ -395,11 +403,18 @@ |
396 | 404 | |
397 | 405 | $this->mLocalFile = $mUpload->getLocalFile(); |
398 | 406 | $watch = true; //TODO |
399 | | - unset( $this->added['fallback'] ); |
400 | 407 | $comment = "Updating translations:"; |
401 | 408 | if( count( $this->added ) > 0 ) $comment .= " added " . implode( ", ", array_keys( $this->added ) ) . ";"; |
402 | 409 | if( count( $this->modified ) > 0 ) $comment .= " modified " . implode( ", ", array_keys( $this->modified ) ) . ";"; |
403 | 410 | $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 | + |
404 | 419 | $status = $mUpload->performUpload( $comment, false, $watch, $this->getUser() ); |
405 | 420 | if ( !$status->isGood() ) { |
406 | 421 | //TODO |
— | — | @@ -410,6 +425,13 @@ |
411 | 426 | // Success, redirect to description page |
412 | 427 | $this->getOutput()->redirect( $this->mLocalFile->getTitle()->getFullURL() ); |
413 | 428 | } |
| 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 | + } |
414 | 436 | } |
415 | 437 | |
416 | 438 | class TranslateSvgUpload extends UploadBase { |
Index: trunk/extensions/TranslateSvg/ext.translateSvg.core.js |
— | — | @@ -79,6 +79,10 @@ |
80 | 80 | $( this ).text( langname ); |
81 | 81 | $( this ).append( ' ' ).append( getRemoveLink() ); |
82 | 82 | } ); |
| 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 | + } ); |
83 | 87 | return newfieldset; |
84 | 88 | } |
85 | 89 | |