'LanguageBe_tarask' => __DIR__ . '/languages/classes/LanguageBe_tarask.php',
'LanguageBg' => __DIR__ . '/languages/classes/LanguageBg.php',
'LanguageBs' => __DIR__ . '/languages/classes/LanguageBs.php',
+ 'LanguageCode' => __DIR__ . '/languages/LanguageCode.php',
'LanguageConverter' => __DIR__ . '/languages/LanguageConverter.php',
'LanguageCu' => __DIR__ . '/languages/classes/LanguageCu.php',
'LanguageDsb' => __DIR__ . '/languages/classes/LanguageDsb.php',
* MediaWiki out of the box. Not all languages listed there have translations,
* see languages/messages/ for the list of languages with some localisation.
*
- * Warning: Don't use language codes listed in $wgDummyLanguageCodes like "no"
- * for Norwegian (use "nb" instead), or things will break unexpectedly.
+ * Warning: Don't use any of MediaWiki's deprecated language codes listed in
+ * LanguageCode::getDeprecatedCodeMapping or $wgDummyLanguageCodes, like "no"
+ * for Norwegian (use "nb" instead). If you do, things will break unexpectedly.
*
* This defines the default interface language for all users, but users can
* change it in their preferences.
$wgExtraLanguageNames = [];
/**
- * List of language codes that don't correspond to an actual language.
- * These codes are mostly left-offs from renames, or other legacy things.
- * This array makes them not appear as a selectable language on the installer,
- * and excludes them when running the transstat.php script.
- */
-$wgDummyLanguageCodes = [
- 'als' => 'gsw',
- 'bat-smg' => 'sgs',
- 'be-x-old' => 'be-tarask',
- 'bh' => 'bho',
- 'fiu-vro' => 'vro',
- 'no' => 'nb',
- 'qqq' => 'qqq', # Used for message documentation.
- 'qqx' => 'qqx', # Used for viewing message keys.
- 'roa-rup' => 'rup',
- 'simple' => 'en',
- 'zh-classical' => 'lzh',
- 'zh-min-nan' => 'nan',
- 'zh-yue' => 'yue',
+ * List of mappings from one language code to another.
+ * This array makes the codes not appear as a selectable language on the
+ * installer, and excludes them when running the transstat.php script.
+ *
+ * In Setup.php, the variable $wgDummyLanguageCodes is created by combining
+ * these codes with a list of "deprecated" codes, which are mostly leftovers
+ * from renames or other legacy things, and the internal codes 'qqq' and 'qqx'.
+ * If a mapping in $wgExtraLanguageCodes collide with a built-in mapping, the
+ * value in $wgExtraLanguageCodes will be used.
+ *
+ * @since 1.29
+ */
+$wgExtraLanguageCodes = [
+ 'bh' => 'bho', // Bihari language family
+ 'no' => 'nb', // Norwegian language family
+ 'simple' => 'en', // Simple English
];
/**
$wgCanonicalNamespaceNames = $wgCanonicalNamespaceNames + $wgExtraNamespaces;
}
+// Merge in the legacy language codes, unless overridden in the config
+if ( !isset( $wgDummyLanguageCodes ) ) {
+ $wgDummyLanguageCodes = [
+ 'qqq' => 'qqq', // Used for message documentation
+ 'qqx' => 'qqx', // Used for viewing message keys
+ ] + $wgExtraLanguageCodes + LanguageCode::getDeprecatedCodeMapping();
+}
+
// These are now the same, always
// To determine the user language, use $wgLang->getCode()
$wgContLanguageCode = $wgLanguageCode;
--- /dev/null
+<?php
+/**
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * http://www.gnu.org/copyleft/gpl.html
+ *
+ * @file
+ * @ingroup Language
+ */
+
+/**
+ * Methods for dealing with language codes.
+ * @todo Move some of the code-related static methods out of Language into this class
+ *
+ * @since 1.29
+ * @ingroup Language
+ */
+class LanguageCode {
+ /**
+ * Returns a mapping of deprecated language codes that were used in previous
+ * versions of MediaWiki to up-to-date, current language codes.
+ *
+ * This array is merged into $wgDummyLanguageCodes in Setup.php, along with
+ * the fake language codes 'qqq' and 'qqx', which are used internally by
+ * MediaWiki's localisation system.
+ *
+ * @return string[]
+ */
+ public static function getDeprecatedCodeMapping() {
+ return [
+ // Note that als is actually a valid ISO 639 code (Tosk Albanian), but it
+ // was previously used in MediaWiki for Alsatian, which comes under gsw
+ 'als' => 'gsw',
+ 'bat-smg' => 'sgs',
+ 'be-x-old' => 'be-tarask',
+ 'fiu-vro' => 'vro',
+ 'roa-rup' => 'rup',
+ 'zh-classical' => 'lzh',
+ 'zh-min-nan' => 'nan',
+ 'zh-yue' => 'yue',
+ ];
+ }
+}
--- /dev/null
+<?php
+
+/**
+ * @covers LanguageCode
+ *
+ * @group Language
+ *
+ * @license GPL-2.0+
+ * @author Thiemo Mättig
+ */
+class LanguageCodeTest extends PHPUnit_Framework_TestCase {
+
+ public function testConstructor() {
+ $instance = new LanguageCode();
+
+ $this->assertInstanceOf( LanguageCode::class, $instance );
+ }
+
+ public function testGetDeprecatedCodeMapping() {
+ $map = LanguageCode::getDeprecatedCodeMapping();
+
+ $this->assertInternalType( 'array', $map );
+ $this->assertContainsOnly( 'string', array_keys( $map ) );
+ $this->assertArrayNotHasKey( '', $map );
+ $this->assertContainsOnly( 'string', $map );
+ $this->assertNotContains( '', $map );
+
+ // Codes special to MediaWiki should never appear in a map of "deprecated" codes
+ $this->assertArrayNotHasKey( 'qqq', $map, 'documentation' );
+ $this->assertNotContains( 'qqq', $map, 'documentation' );
+ $this->assertArrayNotHasKey( 'qqx', $map, 'debug code' );
+ $this->assertNotContains( 'qqx', $map, 'debug code' );
+
+ // Valid language codes that are currently not "deprecated"
+ $this->assertArrayNotHasKey( 'bh', $map, 'family of Bihari languages' );
+ $this->assertArrayNotHasKey( 'no', $map, 'family of Norwegian languages' );
+ $this->assertArrayNotHasKey( 'simple', $map );
+ }
+
+}