Index: trunk/extensions/LiveTranslate/LiveTranslate_Settings.php |
— | — | @@ -19,3 +19,6 @@ |
20 | 20 | } |
21 | 21 | |
22 | 22 | $egLiveTranslateDirPage = 'Live Translate Dictionary'; |
| 23 | + |
| 24 | +# https://code.google.com/apis/console |
| 25 | +$egGoogleApiKey = ''; |
Index: trunk/extensions/LiveTranslate/includes/ext.livetranslate.js |
— | — | @@ -26,6 +26,8 @@ |
27 | 27 | } |
28 | 28 | |
29 | 29 | $('#livetranslatebutton').click(function() { |
| 30 | + $( this ).attr( "disabled", true ); |
| 31 | + |
30 | 32 | var words = getSpecialWords(); |
31 | 33 | var newLang = $( '#livetranslatelang' ).val(); |
32 | 34 | |
— | — | @@ -35,13 +37,13 @@ |
36 | 38 | 'action': 'livetranslate', |
37 | 39 | 'format': 'json', |
38 | 40 | 'from': currentLang, |
39 | | - 'to': $( '#livetranslatelang' ).val(), |
| 41 | + 'to': newLang, |
40 | 42 | 'words': words.join( '|' ), |
41 | 43 | }, |
42 | 44 | function( data ) { |
43 | 45 | if ( data.translations ) { |
44 | | - currentLang = newLang; |
45 | 46 | replaceSpecialWords( data.translations ); |
| 47 | + requestGoogleTranslate( currentLang, newLang ); |
46 | 48 | } |
47 | 49 | } |
48 | 50 | ); |
— | — | @@ -66,4 +68,26 @@ |
67 | 69 | }); |
68 | 70 | } |
69 | 71 | |
| 72 | + function requestGoogleTranslate( sourceLang, targetLang ) { |
| 73 | + $.getJSON( |
| 74 | + 'https://www.googleapis.com/language/translate/v2?callback=?', |
| 75 | + { |
| 76 | + 'key': window.wgGoogleApiKey, |
| 77 | + 'format': 'html', |
| 78 | + 'q': ''//$( '#bodyContent' ).text(), |
| 79 | + 'source': sourceLang, |
| 80 | + 'target': targetLang, |
| 81 | + }, |
| 82 | + function( response ) { |
| 83 | + for ( i in response.data.translations ) { |
| 84 | + // TODO |
| 85 | + } |
| 86 | + |
| 87 | + currentLang = targetLang; |
| 88 | + |
| 89 | + $( '#livetranslatebutton' ).attr( "disabled", false ); |
| 90 | + } |
| 91 | + ); |
| 92 | + } |
| 93 | + |
70 | 94 | } ); })(jQuery); |
\ No newline at end of file |
Index: trunk/extensions/LiveTranslate/includes/LiveTranslate_Functions.php |
— | — | @@ -19,8 +19,12 @@ |
20 | 20 | * @since 0.1 |
21 | 21 | */ |
22 | 22 | public static function loadJs() { |
23 | | - global $wgOut; |
| 23 | + global $wgOut, $egGoogleApiKey; |
24 | 24 | |
| 25 | + $wgOut->addInlineScript( |
| 26 | + 'var wgGoogleApiKey = ' . json_encode( $egGoogleApiKey ) . ';' |
| 27 | + ); |
| 28 | + |
25 | 29 | // For backward compatibility with MW < 1.17. |
26 | 30 | if ( is_callable( array( $wgOut, 'addModules' ) ) ) { |
27 | 31 | $wgOut->addModules( 'ext.livetranslate' ); |