Index: trunk/extensions/LiveTranslate/includes/ext.livetranslate.js |
— | — | @@ -31,22 +31,28 @@ |
32 | 32 | var words = getSpecialWords(); |
33 | 33 | var newLang = $( '#livetranslatelang' ).val(); |
34 | 34 | |
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 | + } |
48 | 53 | } |
49 | | - } |
50 | | - ); |
| 54 | + ); |
| 55 | + } |
| 56 | + |
51 | 57 | }); |
52 | 58 | |
53 | 59 | function getSpecialWords() { |
— | — | @@ -74,14 +80,25 @@ |
75 | 81 | { |
76 | 82 | 'key': window.wgGoogleApiKey, |
77 | 83 | 'format': 'html', |
78 | | - 'q': ''//$( '#bodyContent' ).text(), |
| 84 | + 'q': '',//$( '#bodyContent' ).text(), |
79 | 85 | 'source': sourceLang, |
80 | 86 | 'target': targetLang, |
81 | 87 | }, |
82 | 88 | 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 | + } |
85 | 94 | } |
| 95 | + else { |
| 96 | + if ( response.error ) { |
| 97 | + alert( response.error.message ); // TODO: i18n |
| 98 | + } |
| 99 | + else { |
| 100 | + // TODO: unknown error |
| 101 | + } |
| 102 | + } |
86 | 103 | |
87 | 104 | currentLang = targetLang; |
88 | 105 | |