Index: trunk/extensions/LiveTranslate/LiveTranslate.php |
— | — | @@ -25,7 +25,7 @@ |
26 | 26 | die( 'Not an entry point.' ); |
27 | 27 | } |
28 | 28 | |
29 | | -define( 'LiveTranslate_VERSION', '0.3 rc1' ); |
| 29 | +define( 'LiveTranslate_VERSION', '0.3' ); |
30 | 30 | |
31 | 31 | $wgExtensionCredits['other'][] = array( |
32 | 32 | 'path' => __FILE__, |
Index: trunk/extensions/LiveTranslate/LiveTranslate.hooks.php |
— | — | @@ -175,4 +175,4 @@ |
176 | 176 | return true; |
177 | 177 | } |
178 | 178 | |
179 | | -} |
\ No newline at end of file |
| 179 | +} |
Index: trunk/extensions/LiveTranslate/includes/ext.livetranslate.js |
— | — | @@ -234,7 +234,7 @@ |
235 | 235 | |
236 | 236 | /** |
237 | 237 | * Determines a chunk to translate of an DOM elements contents and calls the Google Translate API. |
238 | | - * Then calls itself if there is any remaining word to be done. |
| 238 | + * Then calls itself if there is any remaining work to be done. |
239 | 239 | * |
240 | 240 | * @param {array} untranslatedsentences |
241 | 241 | * @param {array} chunks |
— | — | @@ -249,6 +249,7 @@ |
250 | 250 | var sentenceCount = 0; |
251 | 251 | var currentLength = 0; |
252 | 252 | |
| 253 | + // Find the scentances that can be put in the current chunk. |
253 | 254 | for ( i in untranslatedsentences ) { |
254 | 255 | sentenceCount++; |
255 | 256 | |
— | — | @@ -257,6 +258,7 @@ |
258 | 259 | } |
259 | 260 | else if ( untranslatedsentences[i].length > 0 ) { |
260 | 261 | if ( currentLength == 0 ) { |
| 262 | + // If the first scentance is longer then the max chunk legth, split it. |
261 | 263 | partToUse = untranslatedsentences[i].substr( 0, currentMaxSize - currentLength ); |
262 | 264 | remainingPart = untranslatedsentences[i].substr( currentMaxSize - currentLength ); |
263 | 265 | } |
— | — | @@ -267,6 +269,7 @@ |
268 | 270 | |
269 | 271 | var chunk = ''; |
270 | 272 | |
| 273 | + // Build the chunck. |
271 | 274 | for ( i = 0; i < sentenceCount; i++ ) { |
272 | 275 | var part = untranslatedsentences.shift(); |
273 | 276 | |
— | — | @@ -275,24 +278,28 @@ |
276 | 279 | } |
277 | 280 | } |
278 | 281 | |
| 282 | + // If there is a remaining part, re-add it to the scentances to translate list. |
279 | 283 | if ( remainingPart !== false ) { |
280 | 284 | untranslatedsentences.unshift( remainingPart ); |
281 | 285 | } |
282 | 286 | |
| 287 | + // If there is a partial scentance, add it to the chunk. |
283 | 288 | if ( partToUse !== false ) { |
284 | 289 | chunk += partToUse; |
285 | 290 | } |
286 | 291 | |
| 292 | + // If the lenght is 0, the element has been translated. |
287 | 293 | if ( chunk.length == 0 ) { |
288 | 294 | handleTranslationCompletion( targetLang ); |
289 | 295 | return; |
290 | 296 | } |
291 | 297 | |
| 298 | + // Keep track of leading and tailing spaces, as they often get modified by the GT API. |
292 | 299 | var leadingSpace = chunk.substr( 0, 1 ) == ' ' ? ' ' : ''; |
293 | 300 | var tailingSpace = ( chunk.length > 1 && chunk.substr( chunk.length - 1, 1 ) == ' ' ) ? ' ' : ''; |
294 | 301 | |
295 | 302 | google.language.translate( |
296 | | - jQuery.trim( chunk ), |
| 303 | + jQuery.trim( chunk ), // Trim, so the result does not contain preceding or tailing spaces. |
297 | 304 | sourceLang, |
298 | 305 | targetLang, |
299 | 306 | function(result) { |