Add BCP 47 codes to $wgDummyLanguageCodes to ensure that
Language::factory() will return a valid MediaWiki-internal code if
given a BCP 47 alias. We will want to make $wgDummyLanguageCodes a
private property of LanguageCode eventually, but let's start with
removing it from user configuration.
Setting $wgDummyLanguageCodes in LocalSettings.php has been deprecated
since 1.29. Hard deprecate adding entries to $wgDummyLanguageCodes so
that we can eventually remove manual overrides from user
configuration.
This is a follow-up to
48ab87d0a37da80c2e2ae3a20f645548d2a787f9,
which described the various categories of codes, and
21ead7a98d1a103b77f1e3ba29a85493782d398b, which added the correct
BCP 47 mappings.
Bug: T207433
Change-Id: I9f6dda3360f79ab65f6392f44c98926588d851c8
* @since 1.29
*/
$wgExtraLanguageCodes = [
+ // Language codes of macro languages, which get mapped to the main language
'bh' => 'bho', // Bihari language family
'no' => 'nb', // Norwegian language family
+
+ // Language variants which get mapped to the main language
'simple' => 'en', // Simple English
];
$wgCanonicalNamespaceNames = $wgCanonicalNamespaceNames + $wgExtraNamespaces;
}
+// Hard-deprecate setting $wgDummyLanguageCodes in LocalSettings.php
+if ( count( $wgDummyLanguageCodes ) !== 0 ) {
+ wfDeprecated( '$wgDummyLanguageCodes', '1.29' );
+}
// Merge in the legacy language codes, incorporating overrides from the config
$wgDummyLanguageCodes += [
+ // Internal language codes of the private-use area which get mapped to
+ // themselves.
'qqq' => 'qqq', // Used for message documentation
'qqx' => 'qqx', // Used for viewing message keys
] + $wgExtraLanguageCodes + LanguageCode::getDeprecatedCodeMapping();
+// Merge in (inverted) BCP 47 mappings
+foreach ( LanguageCode::getNonstandardLanguageCodeMapping() as $code => $bcp47 ) {
+ $bcp47 = strtolower( $bcp47 ); // force case-insensitivity
+ if ( !isset( $wgDummyLanguageCodes[$bcp47] ) ) {
+ $wgDummyLanguageCodes[$bcp47] = $wgDummyLanguageCodes[$code] ?? $code;
+ }
+}
// These are now the same, always
// To determine the user language, use $wgLang->getCode()
* Mapping of deprecated language codes that were used in previous
* versions of MediaWiki to up-to-date, current language codes.
* These may or may not be valid BCP 47 codes; they are included here
- * because MediaWiki remapped these particular codes at some point.
+ * because MediaWiki renamed these particular codes at some point.
*
- * @var array Mapping from language code to language code
+ * @var array Mapping from deprecated MediaWiki-internal language code
+ * to replacement MediaWiki-internal language code.
*
* @since 1.30
* @see https://meta.wikimedia.org/wiki/Special_language_codes
* `kk-Cyrl` is a valid code, although some validators may emit
* a warning note.
*
- * @var array Mapping from nonstandard codes to BCP 47 codes
+ * @var array Mapping from nonstandard MediaWiki-internal codes to
+ * BCP 47 codes
*
* @since 1.32
* @see https://meta.wikimedia.org/wiki/Special_language_codes