r78604 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78603‎ | r78604 | r78605 >
Date:21:14, 19 December 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Working on Google Translate interaction
Modified paths:
  • /trunk/extensions/LiveTranslate/LiveTranslate_Settings.php (modified) (history)
  • /trunk/extensions/LiveTranslate/includes/LiveTranslate_Functions.php (modified) (history)
  • /trunk/extensions/LiveTranslate/includes/ext.livetranslate.js (modified) (history)

Diff [purge]

Index: trunk/extensions/LiveTranslate/LiveTranslate_Settings.php
@@ -19,3 +19,6 @@
2020 }
2121
2222 $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 @@
2727 }
2828
2929 $('#livetranslatebutton').click(function() {
 30+ $( this ).attr( "disabled", true );
 31+
3032 var words = getSpecialWords();
3133 var newLang = $( '#livetranslatelang' ).val();
3234
@@ -35,13 +37,13 @@
3638 'action': 'livetranslate',
3739 'format': 'json',
3840 'from': currentLang,
39 - 'to': $( '#livetranslatelang' ).val(),
 41+ 'to': newLang,
4042 'words': words.join( '|' ),
4143 },
4244 function( data ) {
4345 if ( data.translations ) {
44 - currentLang = newLang;
4546 replaceSpecialWords( data.translations );
 47+ requestGoogleTranslate( currentLang, newLang );
4648 }
4749 }
4850 );
@@ -66,4 +68,26 @@
6769 });
6870 }
6971
 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+
7094 } ); })(jQuery);
\ No newline at end of file
Index: trunk/extensions/LiveTranslate/includes/LiveTranslate_Functions.php
@@ -19,8 +19,12 @@
2020 * @since 0.1
2121 */
2222 public static function loadJs() {
23 - global $wgOut;
 23+ global $wgOut, $egGoogleApiKey;
2424
 25+ $wgOut->addInlineScript(
 26+ 'var wgGoogleApiKey = ' . json_encode( $egGoogleApiKey ) . ';'
 27+ );
 28+
2529 // For backward compatibility with MW < 1.17.
2630 if ( is_callable( array( $wgOut, 'addModules' ) ) ) {
2731 $wgOut->addModules( 'ext.livetranslate' );

Follow-up revisions

RevisionCommit summaryAuthorDate
r78627Follow up to r78604jeroendedauw17:51, 20 December 2010

Status & tagging log