Localisation updates from https://translatewiki.net.
[mediawiki.git] / includes / htmlform / fields / HTMLSelectLanguageField.php
blobcd49668957aceaaf711d164fd601e1eefb18c0fd
1 <?php
3 namespace MediaWiki\HTMLForm\Field;
5 use MediaWiki\HTMLForm\HTMLForm;
6 use MediaWiki\MainConfigNames;
7 use MediaWiki\MediaWikiServices;
9 /**
10 * Language select field.
12 * @stable to extend
14 class HTMLSelectLanguageField extends HTMLSelectField {
16 /**
17 * @stable to call
18 * @inheritDoc
20 public function __construct( $params ) {
21 parent::__construct( $params );
23 if ( $this->mParent instanceof HTMLForm ) {
24 $config = $this->mParent->getConfig();
25 $languageCode = $config->get( MainConfigNames::LanguageCode );
26 } else {
27 $languageCode = MediaWikiServices::getInstance()->getMainConfig()->get(
28 MainConfigNames::LanguageCode );
31 $languages = MediaWikiServices::getInstance()
32 ->getLanguageNameUtils()
33 ->getLanguageNames();
35 // Make sure the site language is in the list;
36 // a custom language code might not have a defined nameā€¦
37 if ( !array_key_exists( $languageCode, $languages ) ) {
38 $languages[$languageCode] = $languageCode;
41 ksort( $languages );
43 foreach ( $languages as $code => $name ) {
44 $this->mParams['options'][$code . ' - ' . $name] = $code;
47 $this->mParams['default'] ??= $languageCode;
51 /** @deprecated class alias since 1.42 */
52 class_alias( HTMLSelectLanguageField::class, 'HTMLSelectLanguageField' );