r78522 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r78521‎ | r78522 | r78523 >
Date:23:04, 16 December 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Follow up to r78509
Modified paths:
  • /trunk/extensions/LiveTranslate/LiveTranslate.hooks.php (modified) (history)
  • /trunk/extensions/LiveTranslate/includes/ext.livetranslate.js (modified) (history)

Diff [purge]

Index: trunk/extensions/LiveTranslate/LiveTranslate.hooks.php
@@ -42,7 +42,7 @@
4343 ' ' .
4444 Html::element(
4545 'button',
46 - array( 'id' => 'livetranslatebutton' ),
 46+ array( 'id' => 'livetranslatebutton', 'style' => 'height: 27px' ),
4747 wfMsg( 'livetranslate-button-translate' )
4848 )
4949 )
@@ -62,20 +62,29 @@
6363 * @return string
6464 */
6565 protected static function getLanguageSelector() {
 66+ global $wgContLanguageCode;
 67+
 68+ $languages = Language::getLanguageNames( false );
 69+
 70+ $currentLang = 'en'; // TODO
 71+
 72+ $currentLang = array_key_exists( $currentLang, $languages ) ? $currentLang : $wgContLanguageCode;
 73+
6674 $options = array();
 75+ ksort( $languages );
6776
68 - foreach ( self::getAvailableLanguages() as $language ) {
69 - $options[] = Html::element(
70 - 'option',
71 - array(),
72 - $language
73 - );
 77+ foreach ( $languages as $code => $name ) {
 78+ $display = wfBCP47( $code ) . ' - ' . $name;
 79+ $options[$display] = $code;
7480 }
 81+
 82+ $languageSelector = new HTMLSelectField( array(
 83+ 'id' => 'livetranslatelang',
 84+ 'fieldname' => 'language',
 85+ 'options' => $options
 86+ ) );
7587
76 - return
77 - Html::openElement( 'select', array( 'id' => 'livetranslatelang' ) ) .
78 - implode( "\n", $options ) .
79 - Html::closeElement( 'select' );
 88+ return $languageSelector->getInputHTML( $currentLang );
8089 }
8190
8291 /**
@@ -255,7 +264,7 @@
256265 $specialWord ,
257266 Html::element(
258267 'span',
259 - array( 'class' => 'notranslate' ),
 268+ array( 'class' => 'notranslate', 'original' => $specialWord ),
260269 $specialWord
261270 ),
262271 $text
Index: trunk/extensions/LiveTranslate/includes/ext.livetranslate.js
@@ -7,6 +7,8 @@
88
99 (function($) { $( document ).ready( function() {
1010
 11+ var currentLang = 'en'; // TODO
 12+
1113 // Compatibility with pre-RL code.
1214 // Messages will have been loaded into wgPushMessages.
1315 if ( typeof mediaWiki === 'undefined' ) {
@@ -25,18 +27,20 @@
2628
2729 $('#livetranslatebutton').click(function() {
2830 var words = getSpecialWords();
 31+ var newLang = $( '#livetranslatelang' ).val();
2932
3033 $.getJSON(
3134 wgScriptPath + '/api.php',
3235 {
3336 'action': 'livetranslate',
3437 'format': 'json',
35 - 'from': 'en', // TODO
36 - 'to': 'nl', // TODO
 38+ 'from': currentLang,
 39+ 'to': $( '#livetranslatelang' ).val(),
3740 'words': words.join( '|' ),
3841 },
3942 function( data ) {
4043 if ( data.translations ) {
 44+ currentLang = newLang;
4145 replaceSpecialWords( data.translations );
4246 }
4347 }
@@ -46,7 +50,7 @@
4751 function getSpecialWords() {
4852 var words = [];
4953
50 - $.each($(".notranslate"), function(i,v) {
 54+ $.each($( '.notranslate' ), function( i, v ) {
5155 words.push( $(v).text() );
5256 });
5357

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r78509Added javascript to translate the special wordsjeroendedauw19:15, 16 December 2010

Status & tagging log