r78627 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78626‎ | r78627 | r78628 >
Date:17:51, 20 December 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Follow up to r78604
Modified paths:
  • /trunk/extensions/LiveTranslate/includes/ext.livetranslate.js (modified) (history)

Diff [purge]

Index: trunk/extensions/LiveTranslate/includes/ext.livetranslate.js
@@ -31,22 +31,28 @@
3232 var words = getSpecialWords();
3333 var newLang = $( '#livetranslatelang' ).val();
3434
35 - $.getJSON(
36 - wgScriptPath + '/api.php',
37 - {
38 - 'action': 'livetranslate',
39 - 'format': 'json',
40 - 'from': currentLang,
41 - 'to': newLang,
42 - 'words': words.join( '|' ),
43 - },
44 - function( data ) {
45 - if ( data.translations ) {
46 - replaceSpecialWords( data.translations );
47 - requestGoogleTranslate( currentLang, newLang );
 35+ if ( words.length == 0 ) {
 36+ requestGoogleTranslate( currentLang, newLang );
 37+ }
 38+ else {
 39+ $.getJSON(
 40+ wgScriptPath + '/api.php',
 41+ {
 42+ 'action': 'livetranslate',
 43+ 'format': 'json',
 44+ 'from': currentLang,
 45+ 'to': newLang,
 46+ 'words': words.join( '|' ),
 47+ },
 48+ function( data ) {
 49+ if ( data.translations ) {
 50+ replaceSpecialWords( data.translations );
 51+ requestGoogleTranslate( currentLang, newLang );
 52+ }
4853 }
49 - }
50 - );
 54+ );
 55+ }
 56+
5157 });
5258
5359 function getSpecialWords() {
@@ -74,14 +80,25 @@
7581 {
7682 'key': window.wgGoogleApiKey,
7783 'format': 'html',
78 - 'q': ''//$( '#bodyContent' ).text(),
 84+ 'q': '',//$( '#bodyContent' ).text(),
7985 'source': sourceLang,
8086 'target': targetLang,
8187 },
8288 function( response ) {
83 - for ( i in response.data.translations ) {
84 - // TODO
 89+ if ( response.data ) {
 90+ for ( i in response.data.translations ) {
 91+ // TODO
 92+ //alert( response.data.translations[i].translatedText );
 93+ }
8594 }
 95+ else {
 96+ if ( response.error ) {
 97+ alert( response.error.message ); // TODO: i18n
 98+ }
 99+ else {
 100+ // TODO: unknown error
 101+ }
 102+ }
86103
87104 currentLang = targetLang;
88105

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r78604Working on Google Translate interactionjeroendedauw21:14, 19 December 2010

Status & tagging log