Index: trunk/extensions/LiveTranslate/includes/ext.livetranslate.js |
— | — | @@ -87,9 +87,9 @@ |
88 | 88 | |
89 | 89 | element.contents().each( function() { |
90 | 90 | // If it's a text node, then translate it. |
91 | | - if ( this.nodeType == 3 ) { |
| 91 | + if ( this.nodeType == 3 && this.wholeText.trim().length > 0 ) { |
92 | 92 | runningJobs++; |
93 | | - translateChunk( this.wholeText, [], 500, sourceLang, targetLang, this ); |
| 93 | + translateChunk( this.wholeText, [], 498, sourceLang, targetLang, this ); |
94 | 94 | } |
95 | 95 | // If it's an html element, check to see if it should be ignored, and if not, apply function again. |
96 | 96 | else if ( $.inArray( $( this ).attr( 'id' ), [ 'livetranslatediv', 'siteSub', 'jump-to-nav' ] ) == -1 |
— | — | @@ -99,18 +99,22 @@ |
100 | 100 | } |
101 | 101 | } ); |
102 | 102 | |
103 | | - runningJobs--; |
| 103 | + handleTranslationCompletion( targetLang ); |
104 | 104 | } |
105 | 105 | |
106 | 106 | function translateChunk( untranslatedText, chunks, currentMaxSize, sourceLang, targetLang, element ) { |
107 | 107 | var chunkSize = Math.min( untranslatedText.length, currentMaxSize ); |
108 | 108 | |
109 | 109 | 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 ) + '|', |
111 | 112 | sourceLang, |
112 | 113 | targetLang, |
113 | 114 | 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 | + } |
115 | 119 | |
116 | 120 | if ( chunkSize < currentMaxSize ) { |
117 | 121 | element.replaceWholeText( chunks.join() ); |