r52463 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r52462‎ | r52463 | r52464 >
Date:14:37, 26 June 2009
Author:nikerabbit
Status:ok
Tags:
Comment:
User preferences to choose translation assistant languages
Modified paths:
  • /trunk/extensions/Translate/Translate.i18n.php (modified) (history)
  • /trunk/extensions/Translate/Translate.php (modified) (history)
  • /trunk/extensions/Translate/TranslateEditAddons.php (modified) (history)
  • /trunk/extensions/Translate/_autoload.php (modified) (history)
  • /trunk/extensions/Translate/utils/HTMLJsSelectToInputField.php (added) (history)
  • /trunk/extensions/Translate/utils/UserToggles.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Translate/TranslateEditAddons.php
@@ -134,8 +134,13 @@
135135 }
136136
137137 private static function getFallbacks( $code ) {
138 - global $wgTranslateLanguageFallbacks, $wgTranslateDocumentationLanguageCode;
 138+ global $wgUser, $wgTranslateLanguageFallbacks;
139139
 140+ $preference = $wgUser->getOption( 'translate-editlangs' );
 141+ if ( $preference !== 'default' ) {
 142+ return array_map( 'trim', explode( ',', $preference ) );
 143+ }
 144+
140145 $fallbacks = array();
141146 if ( isset( $wgTranslateLanguageFallbacks[$code] ) ) {
142147 $temp = $wgTranslateLanguageFallbacks[$code];
@@ -287,6 +292,8 @@
288293 $namespace = $object->mTitle->getNsText();
289294 foreach ( self::getFallbacks( $code ) as $fbcode ) {
290295 $fb = TranslateUtils::getMessageContent( $key, $fbcode, $nsMain );
 296+ // Try harder TODO: fixme with the new localisation cache
 297+ if ( $fb === null ) $fb = $group->getMessage( $key, $fbcode );
291298 if ( $fb !== null ) {
292299 /* add a link for editing the fallback messages */
293300 $inOtherLanguages[] = self::dobox( $fb, $fbcode, false, $namespace . ':' . $key . '/' . $fbcode );
Index: trunk/extensions/Translate/Translate.php
@@ -55,7 +55,9 @@
5656 $wgHooks['SkinTemplateTabs'][] = 'TranslateEditAddons::tabs';
5757
5858 $wgDefaultUserOptions['translate'] = 0;
 59+$wgDefaultUserOptions['translate-editlangs'] = 'default';
5960 $wgHooks['GetPreferences'][] = 'TranslatePreferences::onGetPreferences';
 61+$wgHooks['GetPreferences'][] = 'TranslatePreferences::translationAssistLanguages';
6062
6163 $wgHooks['SpecialRecentChangesQuery'][] = 'TranslateRcFilter::translationFilter';
6264 $wgHooks['SpecialRecentChangesPanel'][] = 'TranslateRcFilter::translationFilterForm';
Index: trunk/extensions/Translate/_autoload.php
@@ -78,7 +78,9 @@
7979 $wgAutoloadClasses['MessageIndex'] = $dir . 'utils/MessageIndex.php';
8080 $wgAutoloadClasses['MessageTable'] = $dir . 'utils/MessageTable.php';
8181 $wgAutoloadClasses['JsSelectToInput'] = $dir . 'utils/JsSelectToInput.php';
 82+$wgAutoloadClasses['HTMLJsSelectToInputField'] = $dir . 'utils/HTMLJsSelectToInputField.php';
8283
 84+
8385 # predefined groups
8486 $wgAutoloadClasses['PremadeMediawikiExtensionGroups'] = $dir . 'groups/MediaWikiExtensions.php';
8587 $wgAutoloadClasses['CommonistMessageGroup'] = $dir . 'groups/Commonist.php';
Index: trunk/extensions/Translate/utils/UserToggles.php
@@ -1,5 +1,4 @@
22 <?php
3 -if ( !defined( 'MEDIAWIKI' ) ) die();
43
54 class TranslatePreferences {
65 /**
@@ -25,4 +24,46 @@
2625
2726 return true;
2827 }
 28+
 29+
 30+ public static function translationAssistLanguages( $user, &$preferences ) {
 31+ $select = self::languageSelector();
 32+ $select->setTargetId( 'mw-input-translate-edit-lang' );
 33+
 34+
 35+ $languages = Language::getLanguageNames( false );
 36+
 37+ $preferences['translate-editlangs'] = array(
 38+ 'class' => 'HTMLJsSelectToInputField',
 39+ 'section' => 'editing/translate',
 40+ 'label-message' => 'translate-pref-editassistlang',
 41+ 'help-message' => 'translate-pref-editassistlang-help',
 42+ 'select' => $select,
 43+ 'valid-values' => array_keys( $languages ),
 44+ );
 45+
 46+ return true;
 47+ }
 48+
 49+ protected static function languageSelector() {
 50+ global $wgLang;
 51+ if ( is_callable( array( 'LanguageNames', 'getNames' ) ) ) {
 52+ $languages = LanguageNames::getNames( $wgLang->getCode(),
 53+ LanguageNames::FALLBACK_NORMAL
 54+ );
 55+ } else {
 56+ $languages = Language::getLanguageNames( false );
 57+ }
 58+
 59+ ksort( $languages );
 60+
 61+ $selector = new XmlSelect( 'mw-language-selector', 'mw-language-selector' );
 62+ foreach ( $languages as $code => $name ) {
 63+ $selector->addOption( "$code - $name", $code );
 64+ }
 65+
 66+ $jsSelect = new JsSelectToInput( $selector );
 67+ $jsSelect->setSourceId( 'mw-language-selector' );
 68+ return $jsSelect;
 69+ }
2970 }
Index: trunk/extensions/Translate/utils/HTMLJsSelectToInputField.php
@@ -0,0 +1,39 @@
 2+<?php
 3+
 4+class HTMLJsSelectToInputField extends HTMLTextField {
 5+ function getInputHTML( $value ) {
 6+ $input = parent::getInputHTML( $value );
 7+ if ( isset($this->mParams['select']) ) {
 8+ $input .= ' ' . $this->mParams['select']->getHtmlAndPrepareJs();
 9+ }
 10+ return $input;
 11+ }
 12+
 13+ function tidy( $value ) {
 14+ $value = array_map( 'trim', explode( ',', $value ) );
 15+ $value = array_unique( array_filter( $value ) );
 16+ return $value;
 17+ }
 18+
 19+ function validate( $value, $alldata ) {
 20+ $p = parent::validate( $value, $alldata );
 21+ if( $p !== true ) return $p;
 22+
 23+ if ( !isset($this->mParams['valid-values']) ) return true;
 24+
 25+ if ( $value === 'default' ) return true;
 26+
 27+ $codes = $this->tidy( $value );
 28+ $valid = array_flip( $this->mParams['valid-values'] );
 29+ foreach ( $codes as $code ) {
 30+ if ( !isset($valid[$code]) )
 31+ return wfMsgExt( 'translate-pref-editassistlang-bad', 'parse', $code );
 32+ }
 33+ return true;
 34+ }
 35+
 36+ function filter( $value, $alldata ) {
 37+ $value = parent::filter( $value, $alldata );
 38+ return implode( ', ', $this->tidy( $value ) );
 39+ }
 40+}
\ No newline at end of file
Index: trunk/extensions/Translate/Translate.i18n.php
@@ -132,6 +132,14 @@
133133 'translate-checks-escape' => 'The following escapes may be accidental: <strong>$1</strong>',
134134
135135 'translate-pref-nonewsletter' => 'Do not send me e-mail newsletters',
 136+ 'translate-pref-editassistlang' => 'Assistant languages',
 137+ 'prefs-translate' => 'Translation options',
 138+ 'translate-pref-editassistlang-help' => 'Comma separated list of language codes.
 139+Translation of a message in these languages are shown when you are translating.
 140+The default list of languages depends on your language.',
 141+ 'translate-pref-editassistlang-bad' => 'Invalid language code in the list:
 142+<nowiki>$1</nowiki>.',
 143+
136144 'right-translate' => 'Edit using the translate interface',
137145
138146 'translate-rc-translation-filter' => 'Filter translations:',

Follow-up revisions

RevisionCommit summaryAuthorDate
r52464Some fixed to r52463nikerabbit15:00, 26 June 2009

Status & tagging log