r78509 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78508‎ | r78509 | r78510 >
Date:19:15, 16 December 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Added javascript to translate the special words
Modified paths:
  • /trunk/extensions/LiveTranslate/LiveTranslate.hooks.php (modified) (history)
  • /trunk/extensions/LiveTranslate/LiveTranslate.php (modified) (history)
  • /trunk/extensions/LiveTranslate/includes/LiveTranslate_Functions.php (modified) (history)
  • /trunk/extensions/LiveTranslate/includes/ext.livetranslate.js (modified) (history)

Diff [purge]

Index: trunk/extensions/LiveTranslate/LiveTranslate.php
@@ -47,7 +47,7 @@
4848
4949 $wgAutoloadClasses['LiveTranslateHooks'] = $egLiveTranslateIP . '/LiveTranslate.hooks.php';
5050 $wgAutoloadClasses['ApiLiveTranslate'] = $egLiveTranslateIP . '/api/ApiLiveTranslate.php';
51 -$wgAutoloadClasses['LiveTranslateFunctions'] = $egLiveTranslateIP . '/includes/LiveTranslateFunctions.php';
 51+$wgAutoloadClasses['LiveTranslateFunctions'] = $egLiveTranslateIP . '/includes/LiveTranslate_Functions.php';
5252
5353 $wgAPIModules['livetranslate'] = 'ApiLiveTranslate';
5454
Index: trunk/extensions/LiveTranslate/LiveTranslate.hooks.php
@@ -49,6 +49,8 @@
5050 );
5151 }
5252
 53+ LiveTranslateFunctions::loadJs();
 54+
5355 return true;
5456 }
5557
@@ -244,7 +246,7 @@
245247 */
246248 public static function onOutputPageBeforeHTML( OutputPage &$out, &$text ) {
247249 // TODO: obtain source lang
248 - $sourceLang = 'English';
 250+ $sourceLang = 'en';
249251
250252 $specialWords = self::getSpecialWordsForLang( $sourceLang );
251253
Index: trunk/extensions/LiveTranslate/includes/ext.livetranslate.js
@@ -23,6 +23,43 @@
2424 }
2525 }
2626
 27+ $('#livetranslatebutton').click(function() {
 28+ var words = getSpecialWords();
 29+
 30+ $.getJSON(
 31+ wgScriptPath + '/api.php',
 32+ {
 33+ 'action': 'livetranslate',
 34+ 'format': 'json',
 35+ 'from': 'en', // TODO
 36+ 'to': 'nl', // TODO
 37+ 'words': words.join( '|' ),
 38+ },
 39+ function( data ) {
 40+ if ( data.translations ) {
 41+ replaceSpecialWords( data.translations );
 42+ }
 43+ }
 44+ );
 45+ });
2746
 47+ function getSpecialWords() {
 48+ var words = [];
 49+
 50+ $.each($(".notranslate"), function(i,v) {
 51+ words.push( $(v).text() );
 52+ });
 53+
 54+ return words;
 55+ }
2856
 57+ function replaceSpecialWords( translations ) {
 58+ $.each($(".notranslate"), function(i,v) {
 59+ var currentText = $(v).text();
 60+ if ( translations[currentText] ) {
 61+ $(v).text( translations[currentText] );
 62+ }
 63+ });
 64+ }
 65+
2966 } ); })(jQuery);
\ No newline at end of file
Index: trunk/extensions/LiveTranslate/includes/LiveTranslate_Functions.php
@@ -18,7 +18,7 @@
1919 *
2020 * @since 0.1
2121 */
22 - protected static function loadJs() {
 22+ public static function loadJs() {
2323 global $wgOut;
2424
2525 // For backward compatibility with MW < 1.17.
@@ -45,7 +45,7 @@
4646 *
4747 * @since 0.1
4848 */
49 - public static function addJSLocalisation() {
 49+ protected static function addJSLocalisation() {
5050 global $egLTJSMessages, $wgOut;
5151
5252 $data = array();

Follow-up revisions

RevisionCommit summaryAuthorDate
r78522Follow up to r78509jeroendedauw23:04, 16 December 2010

Status & tagging log