r106445 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r106444‎ | r106445 | r106446 >
Date:16:36, 16 December 2011
Author:jarry1250
Status:ok
Tags:
Comment:
Split special page alias into separate file; further internationalisation preparation including new messages.
Modified paths:
  • /trunk/extensions/TranslateSvg/SpecialTranslateSvg.php (modified) (history)
  • /trunk/extensions/TranslateSvg/TranslateSvg.alias.php (added) (history)
  • /trunk/extensions/TranslateSvg/TranslateSvg.i18n.php (modified) (history)
  • /trunk/extensions/TranslateSvg/TranslateSvg.php (modified) (history)
  • /trunk/extensions/TranslateSvg/ext.translateSvg.core.js (modified) (history)

Diff [purge]

Index: trunk/extensions/TranslateSvg/TranslateSvg.i18n.php
@@ -14,8 +14,8 @@
1515 //'translatesvg-xcoordinate-post' => '',
1616 'translatesvg-ycoordinate-pre' => 'Y-coordinate (vertical): ',
1717 //'translatesvg-ycoordinate-post' => ''
18 - );
19 - $specialPageAliases['en'] = array(
20 - 'TranslateSvg' => array( 'TranslateSVG', 'TranslateSvg' ),
21 - );
22 - $aliases =& $specialPageAliases; // for backwards compatibility with MediaWiki 1.15 and earlier.
\ No newline at end of file
 18+ 'translatesvg-specify' => 'Specify new language code (e.g. en, fr, de, es...)',
 19+ 'translatesvg-fallbackdesc' => 'Default (no language specified)',
 20+ 'translatesvg-qqqdesc' => 'Advice to translators',
 21+ 'translatesvg-nodesc' => '(no description)',
 22+ );
\ No newline at end of file
Index: trunk/extensions/TranslateSvg/TranslateSvg.php
@@ -18,15 +18,17 @@
1919 'version' => '1.0.0',
2020 );
2121
22 -$wgAutoloadClasses['SpecialTranslateSvg'] = dirname(__FILE__) . '/' . 'SpecialTranslateSvg.php';
23 -$wgExtensionMessagesFiles['TranslateSvg'] = dirname( __FILE__ ) . '/TranslateSvg.i18n.php';
 22+$dir = dirname( __FILE__ ) . '/';
 23+$wgAutoloadClasses['SpecialTranslateSvg'] = $dir . 'SpecialTranslateSvg.php';
 24+$wgExtensionMessagesFiles['TranslateSvg'] = $dir . 'TranslateSvg.i18n.php';
 25+$wgExtensionAliasesFiles['TranslateSvg'] = $dir . 'TranslateSvg.alias.php';
2426 $wgSpecialPages['TranslateSvg'] = 'SpecialTranslateSvg'; # Tell MediaWiki about the new special page and its class name
2527 $wgSpecialPageGroups['TranslateSvg'] = 'media';
2628
2729 $wgResourceModules['ext.translateSvg'] = array(
2830 'scripts' => array( 'ext.translateSvg.core.js' ),
2931 // 'styles' => 'css/ext.translateSvg.css',
30 - 'messages' => array( 'translatesvg-add', 'translatesvg-addlink' ),
 32+ 'messages' => array( 'translatesvg-add', 'translatesvg-addlink', 'translatesvg-specify' ),
3133 'localBasePath' => dirname( __FILE__ ),
3234 'remoteExtPath' => 'translateSvg'
3335 );
\ No newline at end of file
Index: trunk/extensions/TranslateSvg/SpecialTranslateSvg.php
@@ -138,23 +138,22 @@
139139 $groups = array();
140140 foreach( $this->translations as $language=>$translations ){
141141 $languages = Language::getLanguageNames();
142 - $languages['fallback'] = "Default (no language specified)"; //TODO: localise
143 - $languages['qqq'] = "Advice to translators"; //TODO: localise
 142+ $languages['fallback'] = wfMsg( 'translatesvg-fallbackdesc');
 143+ $languages['qqq'] = wfMsg( 'translatesvg-qqqdesc' );
144144
145145 $html .= Html::openElement( 'fieldset', array( 'id' => $language ) ) .
146146 Html::element( 'legend', null, $languages[$language] );
147147 $groups = array();
148148 for( $i = 0; $i < $this->number; $i++ ){
149 - $fallback = $this->getfallback( $i );
150 - $default = $this->getDefault( $i, $language );
151 - $grouphtml = Xml::inputLabel( $fallback['text'], $language.'-'.$i.'-text', $language.'-'.$i.'-text', 50, $default['text'] );
 149+ $fallback = $this->getFallback( $i );
 150+ $existing = $this->getExisting( $i, $language );
 151+ $desc = ( $language === 'qqq' ) ? '' : '&#160;' . Html::element( 'small', null, $this->getDescriptor( $i ) );
 152+ list( $label, $input ) = Xml::inputLabelSep( $fallback['text'], $language.'-'.$i.'-text', $language.'-'.$i.'-text', 50, $existing['text'] );
 153+ $grouphtml = $label . $desc . '&#160;&#160;&#160;' . $input;
152154 if( $language !== 'qqq' ){
153155 $grouphtml .= Html::element( 'br' ) .
154 - "&nbsp;&nbsp;&nbsp;" . Xml::inputLabel( wfMsg( 'translatesvg-xcoordinate-pre' ), $language.'-'.$i.'-x', $language.'-'.$i.'-x', 5, $default['x'] ) .
155 - "&nbsp;&nbsp;&nbsp;" . Xml::inputLabel( wfMsg( 'translatesvg-ycoordinate-pre' ), $language.'-'.$i.'-y', $language.'-'.$i.'-y', 5, $default['y'] );
156 - if( trim( $this->getQQQ( $i ) ) !== '' ){
157 - $grouphtml .= "&nbsp" . Html::element( 'small', null, $this->getQQQ( $i ) );
158 - }
 156+ "&#160;&#160;&#160;" . Xml::inputLabel( wfMsg( 'translatesvg-xcoordinate-pre' ), $language.'-'.$i.'-x', $language.'-'.$i.'-x', 5, $existing['x'] ) .
 157+ "&#160;&#160;&#160;" . Xml::inputLabel( wfMsg( 'translatesvg-ycoordinate-pre' ), $language.'-'.$i.'-y', $language.'-'.$i.'-y', 5, $existing['y'] );
159158 }
160159 $groups[] = $grouphtml;
161160 }
@@ -166,27 +165,46 @@
167166 $this->getOutput()->addHTML( $html );
168167 }
169168
170 - function getfallback( $num ){
 169+ function getFallback( $num ){
171170 if( isset( $this->translations['fallback'][$num] ) ){
172171 return $this->translations['fallback'][$num];
173172 } else {
174173 //TODO
175174 }
176175 }
177 - function getDefault( $num, $language ){
 176+
 177+ /*
 178+ Return the existing translation of a text: the starting point that the translator works with.
 179+ Autofill is annoying at best, but it's useful for numbers. Hence scrub all non-numeric text (but
 180+ keep other properties).
 181+ This function is useful when translations are missing for zero or more but not all text elements.
 182+ For the equivalent function for when they are missing for all text, see the JavaScript function.
 183+ */
 184+ function getExisting( $num, $language ){
178185 if( isset( $this->translations[$language][$num] ) ){
179186 return $this->translations[$language][$num];
180187 } else {
181 - //TODO
 188+ $fallback = $this->getFallback( $num );
 189+ $fallback = trim( $fallback['text'] );
 190+ if( preg_match( '/^[0-9 .,]+$/', $fallback ) ){
 191+ return $fallback;
 192+ } else {
 193+ return '';
 194+ }
182195 }
183196 }
184 - function getQQQ( $num ){
 197+
 198+ function getDescriptor( $num ){
 199+ $qqq = '';
185200 if( isset( $this->translations['qqq'][$num]['text'] ) ){
186 - return $this->translations['qqq'][$num]['text'];
187 - } else {
188 - return '(no description)';
 201+ $qqq = trim( $this->translations['qqq'][$num]['text'] );
189202 }
 203+ if( $qqq === '' ) {
 204+ $qqq = wfMsg( 'translatesvg-nodesc' );
 205+ }
 206+ return $qqq;
190207 }
 208+
191209 function updateTranslations( $params ){
192210 foreach( $params as $name=>$value ){
193211 list( $lang, $num, $param ) = explode( '-', $name );
@@ -290,7 +308,6 @@
291309 if( count( $this->added ) > 0 ) $comment .= " added " . implode( ", ", array_keys( $this->added ) ) . ";";
292310 if( count( $this->modified ) > 0 ) $comment .= " modified " . implode( ", ", array_keys( $this->modified ) ) . ";";
293311 $comment = trim( $comment, ";" ) . ".";
294 - die( $comment );
295312 $status = $mUpload->performUpload( $comment, false, $watch, $this->getUser() );
296313 if ( !$status->isGood() ) {
297314 //TODO
Index: trunk/extensions/TranslateSvg/TranslateSvg.alias.php
@@ -0,0 +1,16 @@
 2+<?php
 3+/**
 4+ * Aliases for extension TranslateSvg
 5+ *
 6+ * @file
 7+ * @ingroup Extensions
 8+ */
 9+
 10+$specialPageAliases = array();
 11+
 12+/** English
 13+ * @author Harry Burt
 14+ */
 15+$specialPageAliases['en'] = array(
 16+ 'TranslateSvg' => array( 'TranslateSVG', 'TranslateSvg' ),
 17+);
\ No newline at end of file
Property changes on: trunk/extensions/TranslateSvg/TranslateSvg.alias.php
___________________________________________________________________
Added: svn:eol-style
118 + native
Index: trunk/extensions/TranslateSvg/ext.translateSvg.core.js
@@ -1,12 +1,13 @@
22 var link = $('<a id="newtrans" href="#"></a>')
33 .text( mw.msg('translatesvg-addlink') )
44 .click(function() {
5 - var langcode = prompt("Specify new language code (e.g. en, fr, de, es...)");
 5+ var langcode = prompt( mw.msg('translatesvg-specify') );
66 if( langcode !== null ){
77 var newfieldset = $('fieldset#fallback').clone();
88 newfieldset.find('input').each( function (){
99 $(this).attr( 'id', $(this).attr( 'id' ).toString().replace( 'fallback', langcode ) );
1010 $(this).attr( 'name', $(this).attr( 'name' ).toString().replace( 'fallback', langcode ) );
 11+ $(this).attr( 'value', getExisting( $(this).attr( 'value' ) ) );
1112 });
1213 newfieldset.find('label').each( function (){
1314 $(this).attr( 'for', $(this).attr( 'for' ).toString().replace( 'fallback', langcode ) );
@@ -14,10 +15,23 @@
1516 newfieldset.attr( 'id', langcode );
1617 newfieldset = $('a#newtrans').after( newfieldset );
1718 $('fieldset#' + langcode + ' legend').remove();
18 - $('fieldset#' + langcode ).prepend( '<legend>' + langcode + '</legend>' );
 19+ $('fieldset#' + langcode ).prepend( '<legend>' + codeToText( langcode ) + '</legend>' );
1920 }
2021 return false;
21 -}); //TODO: localise, validate input, en=>English
 22+}); //TODO: validate input
2223 var paragraph = $('<p></p>').text( mw.msg('translatesvg-add'))
2324 .append( link );
24 -$('form#specialtranslatesvg').prepend(paragraph);
\ No newline at end of file
 25+$('form#specialtranslatesvg').prepend(paragraph);
 26+
 27+function getExisting( fallback ){
 28+ //No need to check for an existing translation since we're creating a new language box
 29+ if( fallback.match( /^[0-9 .,]+$/ ) ){
 30+ return fallback;
 31+ } else {
 32+ return '';
 33+ }
 34+}
 35+function codeToText( langcode ){
 36+ //TODO
 37+ return langcode;
 38+}
\ No newline at end of file

Status & tagging log