Index: trunk/extensions/LiveTranslate/LiveTranslate.php |
— | — | @@ -47,7 +47,7 @@ |
48 | 48 | |
49 | 49 | $wgAutoloadClasses['LiveTranslateHooks'] = $egLiveTranslateIP . '/LiveTranslate.hooks.php'; |
50 | 50 | $wgAutoloadClasses['ApiLiveTranslate'] = $egLiveTranslateIP . '/api/ApiLiveTranslate.php'; |
51 | | -$wgAutoloadClasses['LiveTranslateFunctions'] = $egLiveTranslateIP . '/includes/LiveTranslateFunctions.php'; |
| 51 | +$wgAutoloadClasses['LiveTranslateFunctions'] = $egLiveTranslateIP . '/includes/LiveTranslate_Functions.php'; |
52 | 52 | |
53 | 53 | $wgAPIModules['livetranslate'] = 'ApiLiveTranslate'; |
54 | 54 | |
Index: trunk/extensions/LiveTranslate/LiveTranslate.hooks.php |
— | — | @@ -49,6 +49,8 @@ |
50 | 50 | ); |
51 | 51 | } |
52 | 52 | |
| 53 | + LiveTranslateFunctions::loadJs(); |
| 54 | + |
53 | 55 | return true; |
54 | 56 | } |
55 | 57 | |
— | — | @@ -244,7 +246,7 @@ |
245 | 247 | */ |
246 | 248 | public static function onOutputPageBeforeHTML( OutputPage &$out, &$text ) { |
247 | 249 | // TODO: obtain source lang |
248 | | - $sourceLang = 'English'; |
| 250 | + $sourceLang = 'en'; |
249 | 251 | |
250 | 252 | $specialWords = self::getSpecialWordsForLang( $sourceLang ); |
251 | 253 | |
Index: trunk/extensions/LiveTranslate/includes/ext.livetranslate.js |
— | — | @@ -23,6 +23,43 @@ |
24 | 24 | } |
25 | 25 | } |
26 | 26 | |
| 27 | + $('#livetranslatebutton').click(function() { |
| 28 | + var words = getSpecialWords(); |
| 29 | + |
| 30 | + $.getJSON( |
| 31 | + wgScriptPath + '/api.php', |
| 32 | + { |
| 33 | + 'action': 'livetranslate', |
| 34 | + 'format': 'json', |
| 35 | + 'from': 'en', // TODO |
| 36 | + 'to': 'nl', // TODO |
| 37 | + 'words': words.join( '|' ), |
| 38 | + }, |
| 39 | + function( data ) { |
| 40 | + if ( data.translations ) { |
| 41 | + replaceSpecialWords( data.translations ); |
| 42 | + } |
| 43 | + } |
| 44 | + ); |
| 45 | + }); |
27 | 46 | |
| 47 | + function getSpecialWords() { |
| 48 | + var words = []; |
| 49 | + |
| 50 | + $.each($(".notranslate"), function(i,v) { |
| 51 | + words.push( $(v).text() ); |
| 52 | + }); |
| 53 | + |
| 54 | + return words; |
| 55 | + } |
28 | 56 | |
| 57 | + function replaceSpecialWords( translations ) { |
| 58 | + $.each($(".notranslate"), function(i,v) { |
| 59 | + var currentText = $(v).text(); |
| 60 | + if ( translations[currentText] ) { |
| 61 | + $(v).text( translations[currentText] ); |
| 62 | + } |
| 63 | + }); |
| 64 | + } |
| 65 | + |
29 | 66 | } ); })(jQuery); |
\ No newline at end of file |
Index: trunk/extensions/LiveTranslate/includes/LiveTranslate_Functions.php |
— | — | @@ -18,7 +18,7 @@ |
19 | 19 | * |
20 | 20 | * @since 0.1 |
21 | 21 | */ |
22 | | - protected static function loadJs() { |
| 22 | + public static function loadJs() { |
23 | 23 | global $wgOut; |
24 | 24 | |
25 | 25 | // For backward compatibility with MW < 1.17. |
— | — | @@ -45,7 +45,7 @@ |
46 | 46 | * |
47 | 47 | * @since 0.1 |
48 | 48 | */ |
49 | | - public static function addJSLocalisation() { |
| 49 | + protected static function addJSLocalisation() { |
50 | 50 | global $egLTJSMessages, $wgOut; |
51 | 51 | |
52 | 52 | $data = array(); |