Index: trunk/extensions/LiveTranslate/includes/ext.livetranslate.js |
— | — | @@ -205,8 +205,7 @@ |
206 | 206 | function translateElement( element, sourceLang, targetLang ) { |
207 | 207 | runningJobs++; |
208 | 208 | |
209 | | - // Max chunk size is 500 - 2 for the anti-trim delimiters. |
210 | | - var maxChunkLength = 498; |
| 209 | + var maxChunkLength = 500; |
211 | 210 | |
212 | 211 | element.contents().each( function() { |
213 | 212 | // If it's a text node, then translate it. |
— | — | @@ -288,15 +287,16 @@ |
289 | 288 | return; |
290 | 289 | } |
291 | 290 | |
| 291 | + var leadingSpace = chunk.substr( 0, 1 ) == ' ' ? ' ' : ''; |
| 292 | + var tailingSpace = ( chunk.length > 1 && chunk.substr( chunk.length - 1, 1 ) == ' ' ) ? ' ' : ''; |
| 293 | + |
292 | 294 | google.language.translate( |
293 | | - // Surround the text stuff so spaces and newlines don't get trimmed away. |
294 | | - '|' + chunk + '|', |
| 295 | + jQuery.trim( chunk ), |
295 | 296 | sourceLang, |
296 | 297 | targetLang, |
297 | 298 | function(result) { |
298 | | - if ( result.translation && result.translation.length >= 2 ) { |
299 | | - // Remove the trim-preventing stuff and add the result to the chunks array. |
300 | | - chunks.push( result.translation.substr( 1, result.translation.length -2 ) ); |
| 299 | + if ( result.translation ) { |
| 300 | + chunks.push( leadingSpace + result.translation + tailingSpace ); |
301 | 301 | } |
302 | 302 | else { |
303 | 303 | // If the translation failed, keep the original text. |
— | — | @@ -328,7 +328,7 @@ |
329 | 329 | if ( !--runningJobs ) { |
330 | 330 | currentLang = targetLang; |
331 | 331 | $( '#livetranslatebutton' ).attr( "disabled", false ).text( mediaWiki.msg( 'livetranslate-button-translate' ) ); |
332 | | - $('#ltrevertbutton').css( 'display', 'inline' ); |
| 332 | + $( '#ltrevertbutton' ).css( 'display', 'inline' ); |
333 | 333 | } |
334 | 334 | } |
335 | 335 | |