Index: trunk/extensions/LiveTranslate/LiveTranslate.hooks.php |
— | — | @@ -42,7 +42,7 @@ |
43 | 43 | ' ' . |
44 | 44 | Html::element( |
45 | 45 | 'button', |
46 | | - array( 'id' => 'livetranslatebutton' ), |
| 46 | + array( 'id' => 'livetranslatebutton', 'style' => 'height: 27px' ), |
47 | 47 | wfMsg( 'livetranslate-button-translate' ) |
48 | 48 | ) |
49 | 49 | ) |
— | — | @@ -62,20 +62,29 @@ |
63 | 63 | * @return string |
64 | 64 | */ |
65 | 65 | protected static function getLanguageSelector() { |
| 66 | + global $wgContLanguageCode; |
| 67 | + |
| 68 | + $languages = Language::getLanguageNames( false ); |
| 69 | + |
| 70 | + $currentLang = 'en'; // TODO |
| 71 | + |
| 72 | + $currentLang = array_key_exists( $currentLang, $languages ) ? $currentLang : $wgContLanguageCode; |
| 73 | + |
66 | 74 | $options = array(); |
| 75 | + ksort( $languages ); |
67 | 76 | |
68 | | - foreach ( self::getAvailableLanguages() as $language ) { |
69 | | - $options[] = Html::element( |
70 | | - 'option', |
71 | | - array(), |
72 | | - $language |
73 | | - ); |
| 77 | + foreach ( $languages as $code => $name ) { |
| 78 | + $display = wfBCP47( $code ) . ' - ' . $name; |
| 79 | + $options[$display] = $code; |
74 | 80 | } |
| 81 | + |
| 82 | + $languageSelector = new HTMLSelectField( array( |
| 83 | + 'id' => 'livetranslatelang', |
| 84 | + 'fieldname' => 'language', |
| 85 | + 'options' => $options |
| 86 | + ) ); |
75 | 87 | |
76 | | - return |
77 | | - Html::openElement( 'select', array( 'id' => 'livetranslatelang' ) ) . |
78 | | - implode( "\n", $options ) . |
79 | | - Html::closeElement( 'select' ); |
| 88 | + return $languageSelector->getInputHTML( $currentLang ); |
80 | 89 | } |
81 | 90 | |
82 | 91 | /** |
— | — | @@ -255,7 +264,7 @@ |
256 | 265 | $specialWord , |
257 | 266 | Html::element( |
258 | 267 | 'span', |
259 | | - array( 'class' => 'notranslate' ), |
| 268 | + array( 'class' => 'notranslate', 'original' => $specialWord ), |
260 | 269 | $specialWord |
261 | 270 | ), |
262 | 271 | $text |
Index: trunk/extensions/LiveTranslate/includes/ext.livetranslate.js |
— | — | @@ -7,6 +7,8 @@ |
8 | 8 | |
9 | 9 | (function($) { $( document ).ready( function() { |
10 | 10 | |
| 11 | + var currentLang = 'en'; // TODO |
| 12 | + |
11 | 13 | // Compatibility with pre-RL code. |
12 | 14 | // Messages will have been loaded into wgPushMessages. |
13 | 15 | if ( typeof mediaWiki === 'undefined' ) { |
— | — | @@ -25,18 +27,20 @@ |
26 | 28 | |
27 | 29 | $('#livetranslatebutton').click(function() { |
28 | 30 | var words = getSpecialWords(); |
| 31 | + var newLang = $( '#livetranslatelang' ).val(); |
29 | 32 | |
30 | 33 | $.getJSON( |
31 | 34 | wgScriptPath + '/api.php', |
32 | 35 | { |
33 | 36 | 'action': 'livetranslate', |
34 | 37 | 'format': 'json', |
35 | | - 'from': 'en', // TODO |
36 | | - 'to': 'nl', // TODO |
| 38 | + 'from': currentLang, |
| 39 | + 'to': $( '#livetranslatelang' ).val(), |
37 | 40 | 'words': words.join( '|' ), |
38 | 41 | }, |
39 | 42 | function( data ) { |
40 | 43 | if ( data.translations ) { |
| 44 | + currentLang = newLang; |
41 | 45 | replaceSpecialWords( data.translations ); |
42 | 46 | } |
43 | 47 | } |
— | — | @@ -46,7 +50,7 @@ |
47 | 51 | function getSpecialWords() { |
48 | 52 | var words = []; |
49 | 53 | |
50 | | - $.each($(".notranslate"), function(i,v) { |
| 54 | + $.each($( '.notranslate' ), function( i, v ) { |
51 | 55 | words.push( $(v).text() ); |
52 | 56 | }); |
53 | 57 | |