From f2e0516934c489bd6883b7602d57accf959018e0 Mon Sep 17 00:00:00 2001 From: "C. Scott Ananian" Date: Fri, 19 Oct 2018 10:40:38 -0400 Subject: [PATCH] Include BCP 47 codes in $wgDummyLanguageCodes, but deprecate it 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 --- includes/DefaultSettings.php | 3 +++ includes/Setup.php | 13 +++++++++++++ languages/LanguageCode.php | 8 +++++--- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 15d2627214..e954517888 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -3002,8 +3002,11 @@ $wgExtraLanguageNames = []; * @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 ]; diff --git a/includes/Setup.php b/includes/Setup.php index bdfce62293..aba050d6e3 100644 --- a/includes/Setup.php +++ b/includes/Setup.php @@ -498,11 +498,24 @@ if ( is_array( $wgExtraNamespaces ) ) { $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() diff --git a/languages/LanguageCode.php b/languages/LanguageCode.php index b0baec1341..1e10496984 100644 --- a/languages/LanguageCode.php +++ b/languages/LanguageCode.php @@ -31,9 +31,10 @@ class LanguageCode { * 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 @@ -71,7 +72,8 @@ class LanguageCode { * `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 -- 2.20.1