Index: trunk/extensions/TranslateSvg/TranslateSvg.i18n.php |
— | — | @@ -14,8 +14,8 @@ |
15 | 15 | //'translatesvg-xcoordinate-post' => '', |
16 | 16 | 'translatesvg-ycoordinate-pre' => 'Y-coordinate (vertical): ', |
17 | 17 | //'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 @@ |
19 | 19 | 'version' => '1.0.0', |
20 | 20 | ); |
21 | 21 | |
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'; |
24 | 26 | $wgSpecialPages['TranslateSvg'] = 'SpecialTranslateSvg'; # Tell MediaWiki about the new special page and its class name |
25 | 27 | $wgSpecialPageGroups['TranslateSvg'] = 'media'; |
26 | 28 | |
27 | 29 | $wgResourceModules['ext.translateSvg'] = array( |
28 | 30 | 'scripts' => array( 'ext.translateSvg.core.js' ), |
29 | 31 | // 'styles' => 'css/ext.translateSvg.css', |
30 | | - 'messages' => array( 'translatesvg-add', 'translatesvg-addlink' ), |
| 32 | + 'messages' => array( 'translatesvg-add', 'translatesvg-addlink', 'translatesvg-specify' ), |
31 | 33 | 'localBasePath' => dirname( __FILE__ ), |
32 | 34 | 'remoteExtPath' => 'translateSvg' |
33 | 35 | ); |
\ No newline at end of file |
Index: trunk/extensions/TranslateSvg/SpecialTranslateSvg.php |
— | — | @@ -138,23 +138,22 @@ |
139 | 139 | $groups = array(); |
140 | 140 | foreach( $this->translations as $language=>$translations ){ |
141 | 141 | $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' ); |
144 | 144 | |
145 | 145 | $html .= Html::openElement( 'fieldset', array( 'id' => $language ) ) . |
146 | 146 | Html::element( 'legend', null, $languages[$language] ); |
147 | 147 | $groups = array(); |
148 | 148 | 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' ) ? '' : ' ' . 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 . '   ' . $input; |
152 | 154 | if( $language !== 'qqq' ){ |
153 | 155 | $grouphtml .= Html::element( 'br' ) . |
154 | | - " " . Xml::inputLabel( wfMsg( 'translatesvg-xcoordinate-pre' ), $language.'-'.$i.'-x', $language.'-'.$i.'-x', 5, $default['x'] ) . |
155 | | - " " . Xml::inputLabel( wfMsg( 'translatesvg-ycoordinate-pre' ), $language.'-'.$i.'-y', $language.'-'.$i.'-y', 5, $default['y'] ); |
156 | | - if( trim( $this->getQQQ( $i ) ) !== '' ){ |
157 | | - $grouphtml .= " " . Html::element( 'small', null, $this->getQQQ( $i ) ); |
158 | | - } |
| 156 | + "   " . Xml::inputLabel( wfMsg( 'translatesvg-xcoordinate-pre' ), $language.'-'.$i.'-x', $language.'-'.$i.'-x', 5, $existing['x'] ) . |
| 157 | + "   " . Xml::inputLabel( wfMsg( 'translatesvg-ycoordinate-pre' ), $language.'-'.$i.'-y', $language.'-'.$i.'-y', 5, $existing['y'] ); |
159 | 158 | } |
160 | 159 | $groups[] = $grouphtml; |
161 | 160 | } |
— | — | @@ -166,27 +165,46 @@ |
167 | 166 | $this->getOutput()->addHTML( $html ); |
168 | 167 | } |
169 | 168 | |
170 | | - function getfallback( $num ){ |
| 169 | + function getFallback( $num ){ |
171 | 170 | if( isset( $this->translations['fallback'][$num] ) ){ |
172 | 171 | return $this->translations['fallback'][$num]; |
173 | 172 | } else { |
174 | 173 | //TODO |
175 | 174 | } |
176 | 175 | } |
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 ){ |
178 | 185 | if( isset( $this->translations[$language][$num] ) ){ |
179 | 186 | return $this->translations[$language][$num]; |
180 | 187 | } 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 | + } |
182 | 195 | } |
183 | 196 | } |
184 | | - function getQQQ( $num ){ |
| 197 | + |
| 198 | + function getDescriptor( $num ){ |
| 199 | + $qqq = ''; |
185 | 200 | 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'] ); |
189 | 202 | } |
| 203 | + if( $qqq === '' ) { |
| 204 | + $qqq = wfMsg( 'translatesvg-nodesc' ); |
| 205 | + } |
| 206 | + return $qqq; |
190 | 207 | } |
| 208 | + |
191 | 209 | function updateTranslations( $params ){ |
192 | 210 | foreach( $params as $name=>$value ){ |
193 | 211 | list( $lang, $num, $param ) = explode( '-', $name ); |
— | — | @@ -290,7 +308,6 @@ |
291 | 309 | if( count( $this->added ) > 0 ) $comment .= " added " . implode( ", ", array_keys( $this->added ) ) . ";"; |
292 | 310 | if( count( $this->modified ) > 0 ) $comment .= " modified " . implode( ", ", array_keys( $this->modified ) ) . ";"; |
293 | 311 | $comment = trim( $comment, ";" ) . "."; |
294 | | - die( $comment ); |
295 | 312 | $status = $mUpload->performUpload( $comment, false, $watch, $this->getUser() ); |
296 | 313 | if ( !$status->isGood() ) { |
297 | 314 | //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 |
1 | 18 | + native |
Index: trunk/extensions/TranslateSvg/ext.translateSvg.core.js |
— | — | @@ -1,12 +1,13 @@ |
2 | 2 | var link = $('<a id="newtrans" href="#"></a>') |
3 | 3 | .text( mw.msg('translatesvg-addlink') ) |
4 | 4 | .click(function() { |
5 | | - var langcode = prompt("Specify new language code (e.g. en, fr, de, es...)"); |
| 5 | + var langcode = prompt( mw.msg('translatesvg-specify') ); |
6 | 6 | if( langcode !== null ){ |
7 | 7 | var newfieldset = $('fieldset#fallback').clone(); |
8 | 8 | newfieldset.find('input').each( function (){ |
9 | 9 | $(this).attr( 'id', $(this).attr( 'id' ).toString().replace( 'fallback', langcode ) ); |
10 | 10 | $(this).attr( 'name', $(this).attr( 'name' ).toString().replace( 'fallback', langcode ) ); |
| 11 | + $(this).attr( 'value', getExisting( $(this).attr( 'value' ) ) ); |
11 | 12 | }); |
12 | 13 | newfieldset.find('label').each( function (){ |
13 | 14 | $(this).attr( 'for', $(this).attr( 'for' ).toString().replace( 'fallback', langcode ) ); |
— | — | @@ -14,10 +15,23 @@ |
15 | 16 | newfieldset.attr( 'id', langcode ); |
16 | 17 | newfieldset = $('a#newtrans').after( newfieldset ); |
17 | 18 | $('fieldset#' + langcode + ' legend').remove(); |
18 | | - $('fieldset#' + langcode ).prepend( '<legend>' + langcode + '</legend>' ); |
| 19 | + $('fieldset#' + langcode ).prepend( '<legend>' + codeToText( langcode ) + '</legend>' ); |
19 | 20 | } |
20 | 21 | return false; |
21 | | -}); //TODO: localise, validate input, en=>English |
| 22 | +}); //TODO: validate input |
22 | 23 | var paragraph = $('<p></p>').text( mw.msg('translatesvg-add')) |
23 | 24 | .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 |