Translate extension for MediaWiki
 
Loading...
Searching...
No Matches
TranslatePreferences.php
Go to the documentation of this file.
1<?php
14use MediaWiki\MediaWikiServices;
15
28 public static function translationAssistLanguages( User $user, &$preferences ) {
29 // Get selector.
30 $select = self::languageSelector();
31 // Set target ID.
32 $select->setTargetId( 'mw-input-translate-editlangs' );
33 // Get available languages.
34 $languages = MediaWikiServices::getInstance()->getLanguageNameUtils()->getLanguageNames();
35
36 $preferences['translate-editlangs'] = [
37 'class' => HTMLJsSelectToInputField::class,
38 // prefs-translate
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 'name' => 'translate-editlangs',
45 ];
46
47 return true;
48 }
49
54 protected static function languageSelector() {
55 $lang = RequestContext::getMain()->getLanguage();
56 $languages = MediaWikiServices::getInstance()->getLanguageNameUtils()->getLanguageNames( $lang->getCode() );
57 ksort( $languages );
58
59 $selector = new XmlSelect( false, 'mw-language-selector' );
60 foreach ( $languages as $code => $name ) {
61 $selector->addOption( "$code - $name", $code );
62 }
63
64 $jsSelect = new JsSelectToInput( $selector );
65
66 return $jsSelect;
67 }
68}
Implementation of JsSelectToInput class which is compatible with MediaWiki's preferences system.
Code for JavaScript enhanced <option> selectors.
Class to add Translate specific preference settings.
static languageSelector()
JavsScript selector for language codes.
static translationAssistLanguages(User $user, &$preferences)
Add 'translate-editlangs' preference.