r94440 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r94439‎ | r94440 | r94441 >
Date:01:08, 14 August 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
docs++
Modified paths:
  • /trunk/extensions/LiveTranslate/RELEASE-NOTES (modified) (history)
  • /trunk/extensions/LiveTranslate/includes/jquery.liveTranslate.js (modified) (history)

Diff [purge]

Index: trunk/extensions/LiveTranslate/RELEASE-NOTES
@@ -5,7 +5,7 @@
66
77
88 === Version 1.2 ===
9 -2011-08-xx
 9+2011-08-14
1010
1111 * Rewrote translation control JavaScript to a jQuery plugin.
1212 * Added caching layer utilizing memory and LocalStorage when available to speed up local translations.
Index: trunk/extensions/LiveTranslate/includes/jquery.liveTranslate.js
@@ -10,6 +10,11 @@
1111
1212 var _this = this;
1313
 14+ /**
 15+ * Start both the local and remote components of the translation process.
 16+ *
 17+ * @since 1.2
 18+ */
1419 this.doTranslations = function() {
1520 _this.runningJobs = 2;
1621
@@ -17,6 +22,15 @@
1823 _this.doRemoteTranslation( _this.completeTranslationProcess );
1924 };
2025
 26+ /**
 27+ * Finds and returns the special words in the page by looking
 28+ * for spans with notranslate class. This obviously only works
 29+ * after these tags have been inserted with insertSpecialWords.
 30+ *
 31+ * @since 1.2
 32+ *
 33+ * @return Array
 34+ */
2135 this.findSpecialWords = function() {
2236 var words = [];
2337
@@ -26,7 +40,16 @@
2741
2842 return words;
2943 };
30 -
 44+
 45+ /**
 46+ * Does the local transltaions by obtaining the
 47+ * translations for the special words and replacing
 48+ * them where a translation is available.
 49+ *
 50+ * @since 1.2
 51+ *
 52+ * @param {Function} callback
 53+ */
3154 this.doLocalTranslation = function( callback ) {
3255 _this.memory.getTranslations(
3356 {
@@ -49,13 +72,27 @@
5073 );
5174 };
5275
 76+ /**
 77+ * Does the remote translation, ie everything not in notranslate spans.
 78+ *
 79+ * @since 1.2
 80+ *
 81+ * @param {Function} callback
 82+ */
5383 this.doRemoteTranslation = function( callback ) {
5484 var translator = new window.translationService();
5585 translator.done = callback;
5686 lt.debug( 'Initiating remote translation' );
5787 translator.translateElement( $( '#bodyContent' ), _this.currentLang, _this.select.val() );
5888 };
59 -
 89+
 90+ /**
 91+ * Function to be called once a transslation job has finished.
 92+ * Once there are no more running jobs, the state of the translation
 93+ * control is updated to translation completion.
 94+ *
 95+ * @since 1.2
 96+ */
6097 this.completeTranslationProcess = function() {
6198 if ( !--_this.runningJobs ) {
6299 _this.translateButton.attr( "disabled", false ).text( lt.msg( 'livetranslate-button-translate' ) );
@@ -67,6 +104,8 @@
68105 /**
69106 * Inserts notranslate spans around the words specified in the passed array in the page content.
70107 *
 108+ * @since 1.2
 109+ *
71110 * @param {Array} words
72111 */
73112 this.insertSpecialWords = function( words ) {
@@ -82,6 +121,13 @@
83122 }
84123 };
85124
 125+ /**
 126+ * Obtain the special words and wrap occurances of them into notranslate spans.
 127+ *
 128+ * @since 1.2
 129+ *
 130+ * @param {Function} callback
 131+ */
86132 this.obatinAndInsetSpecialWords = function( callback ) {
87133 // TODO: only run at first translation
88134 _this.memory.getSpecialWords( _this.currentLang, function( specialWords ) {
@@ -92,6 +138,12 @@
93139 } );
94140 };
95141
 142+ /**
 143+ * Setup the translation control.
 144+ * Should be called on construction.
 145+ *
 146+ * @since 1.2
 147+ */
96148 this.setup = function() {
97149 var defaults = {
98150 languages: {},
@@ -123,6 +175,11 @@
124176 _this.bindEvents();
125177 };
126178
 179+ /**
 180+ * Build up the HTML for the translation control and add it to the DOM element.
 181+ *
 182+ * @since 1.2
 183+ */
127184 this.buildHtml = function() {
128185 _this.attr( {
129186 style: 'display:inline; float:right',
@@ -150,6 +207,11 @@
151208 _this.append( _this.select, _this.translateButton, _this.revertButton );
152209 };
153210
 211+ /**
 212+ * Bind the event handlers to the components of the transltaion control.
 213+ *
 214+ * @since 1.2
 215+ */
154216 this.bindEvents = function() {
155217 _this.translateButton.click( function() {
156218 _this.originalHtml = $( '#bodyContent' ).html();

Status & tagging log