r79697 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79696‎ | r79697 | r79698 >
Date:01:15, 6 January 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Fixed issue with trim prevention
Modified paths:
  • /trunk/extensions/LiveTranslate/includes/ext.livetranslate.js (modified) (history)

Diff [purge]

Index: trunk/extensions/LiveTranslate/includes/ext.livetranslate.js
@@ -205,8 +205,7 @@
206206 function translateElement( element, sourceLang, targetLang ) {
207207 runningJobs++;
208208
209 - // Max chunk size is 500 - 2 for the anti-trim delimiters.
210 - var maxChunkLength = 498;
 209+ var maxChunkLength = 500;
211210
212211 element.contents().each( function() {
213212 // If it's a text node, then translate it.
@@ -288,15 +287,16 @@
289288 return;
290289 }
291290
 291+ var leadingSpace = chunk.substr( 0, 1 ) == ' ' ? ' ' : '';
 292+ var tailingSpace = ( chunk.length > 1 && chunk.substr( chunk.length - 1, 1 ) == ' ' ) ? ' ' : '';
 293+
292294 google.language.translate(
293 - // Surround the text stuff so spaces and newlines don't get trimmed away.
294 - '|' + chunk + '|',
 295+ jQuery.trim( chunk ),
295296 sourceLang,
296297 targetLang,
297298 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 );
301301 }
302302 else {
303303 // If the translation failed, keep the original text.
@@ -328,7 +328,7 @@
329329 if ( !--runningJobs ) {
330330 currentLang = targetLang;
331331 $( '#livetranslatebutton' ).attr( "disabled", false ).text( mediaWiki.msg( 'livetranslate-button-translate' ) );
332 - $('#ltrevertbutton').css( 'display', 'inline' );
 332+ $( '#ltrevertbutton' ).css( 'display', 'inline' );
333333 }
334334 }
335335

Status & tagging log