r79850 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r79849‎ | r79850 | r79851 >
Date:23:16, 7 January 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Version 0.3
Modified paths:
  • /trunk/extensions/LiveTranslate/LiveTranslate.hooks.php (modified) (history)
  • /trunk/extensions/LiveTranslate/LiveTranslate.php (modified) (history)
  • /trunk/extensions/LiveTranslate/includes/ext.livetranslate.js (modified) (history)

Diff [purge]

Index: trunk/extensions/LiveTranslate/LiveTranslate.php
@@ -25,7 +25,7 @@
2626 die( 'Not an entry point.' );
2727 }
2828
29 -define( 'LiveTranslate_VERSION', '0.3 rc1' );
 29+define( 'LiveTranslate_VERSION', '0.3' );
3030
3131 $wgExtensionCredits['other'][] = array(
3232 'path' => __FILE__,
Index: trunk/extensions/LiveTranslate/LiveTranslate.hooks.php
@@ -175,4 +175,4 @@
176176 return true;
177177 }
178178
179 -}
\ No newline at end of file
 179+}
Index: trunk/extensions/LiveTranslate/includes/ext.livetranslate.js
@@ -234,7 +234,7 @@
235235
236236 /**
237237 * 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.
239239 *
240240 * @param {array} untranslatedsentences
241241 * @param {array} chunks
@@ -249,6 +249,7 @@
250250 var sentenceCount = 0;
251251 var currentLength = 0;
252252
 253+ // Find the scentances that can be put in the current chunk.
253254 for ( i in untranslatedsentences ) {
254255 sentenceCount++;
255256
@@ -257,6 +258,7 @@
258259 }
259260 else if ( untranslatedsentences[i].length > 0 ) {
260261 if ( currentLength == 0 ) {
 262+ // If the first scentance is longer then the max chunk legth, split it.
261263 partToUse = untranslatedsentences[i].substr( 0, currentMaxSize - currentLength );
262264 remainingPart = untranslatedsentences[i].substr( currentMaxSize - currentLength );
263265 }
@@ -267,6 +269,7 @@
268270
269271 var chunk = '';
270272
 273+ // Build the chunck.
271274 for ( i = 0; i < sentenceCount; i++ ) {
272275 var part = untranslatedsentences.shift();
273276
@@ -275,24 +278,28 @@
276279 }
277280 }
278281
 282+ // If there is a remaining part, re-add it to the scentances to translate list.
279283 if ( remainingPart !== false ) {
280284 untranslatedsentences.unshift( remainingPart );
281285 }
282286
 287+ // If there is a partial scentance, add it to the chunk.
283288 if ( partToUse !== false ) {
284289 chunk += partToUse;
285290 }
286291
 292+ // If the lenght is 0, the element has been translated.
287293 if ( chunk.length == 0 ) {
288294 handleTranslationCompletion( targetLang );
289295 return;
290296 }
291297
 298+ // Keep track of leading and tailing spaces, as they often get modified by the GT API.
292299 var leadingSpace = chunk.substr( 0, 1 ) == ' ' ? ' ' : '';
293300 var tailingSpace = ( chunk.length > 1 && chunk.substr( chunk.length - 1, 1 ) == ' ' ) ? ' ' : '';
294301
295302 google.language.translate(
296 - jQuery.trim( chunk ),
 303+ jQuery.trim( chunk ), // Trim, so the result does not contain preceding or tailing spaces.
297304 sourceLang,
298305 targetLang,
299306 function(result) {

Status & tagging log