r78657 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78656‎ | r78657 | r78658 >
Date:00:44, 21 December 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Follow up to r78652 - fixed trimming issue
Modified paths:
  • /trunk/extensions/LiveTranslate/includes/ext.livetranslate.js (modified) (history)

Diff [purge]

Index: trunk/extensions/LiveTranslate/includes/ext.livetranslate.js
@@ -87,9 +87,9 @@
8888
8989 element.contents().each( function() {
9090 // If it's a text node, then translate it.
91 - if ( this.nodeType == 3 ) {
 91+ if ( this.nodeType == 3 && this.wholeText.trim().length > 0 ) {
9292 runningJobs++;
93 - translateChunk( this.wholeText, [], 500, sourceLang, targetLang, this );
 93+ translateChunk( this.wholeText, [], 498, sourceLang, targetLang, this );
9494 }
9595 // If it's an html element, check to see if it should be ignored, and if not, apply function again.
9696 else if ( $.inArray( $( this ).attr( 'id' ), [ 'livetranslatediv', 'siteSub', 'jump-to-nav' ] ) == -1
@@ -99,18 +99,22 @@
100100 }
101101 } );
102102
103 - runningJobs--;
 103+ handleTranslationCompletion( targetLang );
104104 }
105105
106106 function translateChunk( untranslatedText, chunks, currentMaxSize, sourceLang, targetLang, element ) {
107107 var chunkSize = Math.min( untranslatedText.length, currentMaxSize );
108108
109109 google.language.translate(
110 - untranslatedText.substr( 0, chunkSize ),
 110+ // Surround the text stuff so spaces and newlines don't get trimmed away.
 111+ '|' + untranslatedText.substr( 0, chunkSize ) + '|',
111112 sourceLang,
112113 targetLang,
113114 function(result) {
114 - chunks.push( result.translation );
 115+ if ( result.translation.length >= 2 ) {
 116+ // Remove the trim-preventing stuff and add the result to the chunks array.
 117+ chunks.push( result.translation.substr( 1, result.translation.length -2 ) );
 118+ }
115119
116120 if ( chunkSize < currentMaxSize ) {
117121 element.replaceWholeText( chunks.join() );

Follow-up revisions

RevisionCommit summaryAuthorDate
r78659Follow up to r78657 - fixed stupid errorjeroendedauw01:02, 21 December 2010

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r78652Follow up to r78646jeroendedauw00:18, 21 December 2010

Status & tagging log