Index: trunk/extensions/Translate/TranslateEditAddons.php |
— | — | @@ -134,8 +134,13 @@ |
135 | 135 | } |
136 | 136 | |
137 | 137 | private static function getFallbacks( $code ) { |
138 | | - global $wgTranslateLanguageFallbacks, $wgTranslateDocumentationLanguageCode; |
| 138 | + global $wgUser, $wgTranslateLanguageFallbacks; |
139 | 139 | |
| 140 | + $preference = $wgUser->getOption( 'translate-editlangs' ); |
| 141 | + if ( $preference !== 'default' ) { |
| 142 | + return array_map( 'trim', explode( ',', $preference ) ); |
| 143 | + } |
| 144 | + |
140 | 145 | $fallbacks = array(); |
141 | 146 | if ( isset( $wgTranslateLanguageFallbacks[$code] ) ) { |
142 | 147 | $temp = $wgTranslateLanguageFallbacks[$code]; |
— | — | @@ -287,6 +292,8 @@ |
288 | 293 | $namespace = $object->mTitle->getNsText(); |
289 | 294 | foreach ( self::getFallbacks( $code ) as $fbcode ) { |
290 | 295 | $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 ); |
291 | 298 | if ( $fb !== null ) { |
292 | 299 | /* add a link for editing the fallback messages */ |
293 | 300 | $inOtherLanguages[] = self::dobox( $fb, $fbcode, false, $namespace . ':' . $key . '/' . $fbcode ); |
Index: trunk/extensions/Translate/Translate.php |
— | — | @@ -55,7 +55,9 @@ |
56 | 56 | $wgHooks['SkinTemplateTabs'][] = 'TranslateEditAddons::tabs'; |
57 | 57 | |
58 | 58 | $wgDefaultUserOptions['translate'] = 0; |
| 59 | +$wgDefaultUserOptions['translate-editlangs'] = 'default'; |
59 | 60 | $wgHooks['GetPreferences'][] = 'TranslatePreferences::onGetPreferences'; |
| 61 | +$wgHooks['GetPreferences'][] = 'TranslatePreferences::translationAssistLanguages'; |
60 | 62 | |
61 | 63 | $wgHooks['SpecialRecentChangesQuery'][] = 'TranslateRcFilter::translationFilter'; |
62 | 64 | $wgHooks['SpecialRecentChangesPanel'][] = 'TranslateRcFilter::translationFilterForm'; |
Index: trunk/extensions/Translate/_autoload.php |
— | — | @@ -78,7 +78,9 @@ |
79 | 79 | $wgAutoloadClasses['MessageIndex'] = $dir . 'utils/MessageIndex.php'; |
80 | 80 | $wgAutoloadClasses['MessageTable'] = $dir . 'utils/MessageTable.php'; |
81 | 81 | $wgAutoloadClasses['JsSelectToInput'] = $dir . 'utils/JsSelectToInput.php'; |
| 82 | +$wgAutoloadClasses['HTMLJsSelectToInputField'] = $dir . 'utils/HTMLJsSelectToInputField.php'; |
82 | 83 | |
| 84 | + |
83 | 85 | # predefined groups |
84 | 86 | $wgAutoloadClasses['PremadeMediawikiExtensionGroups'] = $dir . 'groups/MediaWikiExtensions.php'; |
85 | 87 | $wgAutoloadClasses['CommonistMessageGroup'] = $dir . 'groups/Commonist.php'; |
Index: trunk/extensions/Translate/utils/UserToggles.php |
— | — | @@ -1,5 +1,4 @@ |
2 | 2 | <?php |
3 | | -if ( !defined( 'MEDIAWIKI' ) ) die(); |
4 | 3 | |
5 | 4 | class TranslatePreferences { |
6 | 5 | /** |
— | — | @@ -25,4 +24,46 @@ |
26 | 25 | |
27 | 26 | return true; |
28 | 27 | } |
| 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 | + } |
29 | 70 | } |
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 @@ |
133 | 133 | 'translate-checks-escape' => 'The following escapes may be accidental: <strong>$1</strong>', |
134 | 134 | |
135 | 135 | '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 | + |
136 | 144 | 'right-translate' => 'Edit using the translate interface', |
137 | 145 | |
138 | 146 | 'translate-rc-translation-filter' => 'Filter translations:', |