Index: trunk/extensions/LiveTranslate/includes/ext.livetranslate.js |
— | — | @@ -119,7 +119,7 @@ |
120 | 120 | function insertNoTranslateTags( words ) { |
121 | 121 | for ( i in words ) { |
122 | 122 | $( '#bodyContent *' ).replaceText( |
123 | | - eval( "/\\b" + words[i] + "\\b/gi" ), // If you know how to kill the evil eval, let me know :) |
| 123 | + new RegExp( "\\b" + words[i] + "\\b", "g" ), |
124 | 124 | function( str ) { |
125 | 125 | return '<span class="notranslate">' + str + '</span>' |
126 | 126 | } |
— | — | @@ -159,8 +159,23 @@ |
160 | 160 | // If it's a text node, then translate it. |
161 | 161 | if ( this.nodeType == 3 && this.wholeText.trim().length > 0 ) { |
162 | 162 | runningJobs++; |
| 163 | + |
| 164 | + var sentances = this.wholeText.split( new RegExp( "(\\S.+?[.!?])(?=\\s+|$)", "gi" ) ); |
| 165 | + var chunk = ''; |
| 166 | + |
| 167 | + for ( i in sentances ) { |
| 168 | + var longerChunk = chunk + sentances[i]; |
| 169 | + |
| 170 | + if ( longerChunk.length < 498 ) { |
| 171 | + chunk = longerChunk; |
| 172 | + } |
| 173 | + else { |
| 174 | + break; |
| 175 | + } |
| 176 | + } |
| 177 | + |
163 | 178 | // Initiate translation of the text node. Max chunk size is 500 - 2 for the anti-trim delimiters. |
164 | | - translateChunk( this.wholeText, [], 498, sourceLang, targetLang, this ); |
| 179 | + translateChunk( this.wholeText, [], chunk.length, sourceLang, targetLang, this ); |
165 | 180 | } |
166 | 181 | // If it's an html element, check to see if it should be ignored, and if not, apply function again. |
167 | 182 | else if ( $.inArray( $( this ).attr( 'id' ), [ 'livetranslatediv', 'siteSub', 'jump-to-nav' ] ) == -1 |
— | — | @@ -175,7 +190,7 @@ |
176 | 191 | |
177 | 192 | function translateChunk( untranslatedText, chunks, currentMaxSize, sourceLang, targetLang, element ) { |
178 | 193 | var chunkSize = Math.min( untranslatedText.length, currentMaxSize ); |
179 | | - |
| 194 | + |
180 | 195 | google.language.translate( |
181 | 196 | // Surround the text stuff so spaces and newlines don't get trimmed away. |
182 | 197 | '|' + untranslatedText.substr( 0, chunkSize ) + '|', |