X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=languages%2FLanguageCode.php;h=f50c55fe765d90de964ac630e2e06a5d90adcc4f;hb=ae314346d5dddf07f7dcac956db6160ceae46e8c;hp=54d7fbe275d31f47ceafc03ed5944161ae9a18c7;hpb=659e164e938788a154fba8f3efc42d48b07e02ce;p=lhc%2Fweb%2Fwiklou.git diff --git a/languages/LanguageCode.php b/languages/LanguageCode.php index 54d7fbe275..f50c55fe76 100644 --- a/languages/LanguageCode.php +++ b/languages/LanguageCode.php @@ -30,85 +30,22 @@ 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. * * @var array Mapping from language code to language code * * @since 1.30 - * @see https://meta.wikimedia.org/wiki/Special_language_codes */ private static $deprecatedLanguageCodeMapping = [ // 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', // T25215 - 'bat-smg' => 'sgs', // T27522 - 'be-x-old' => 'be-tarask', // T11823 - 'fiu-vro' => 'vro', // T31186 - 'roa-rup' => 'rup', // T17988 - 'zh-classical' => 'lzh', // T30443 - 'zh-min-nan' => 'nan', // T30442 - 'zh-yue' => 'yue', // T30441 - ]; - - /** - * Mapping of non-standard language codes used in MediaWiki to - * standardized BCP 47 codes. These are not deprecated (yet?): - * IANA may eventually recognize the subtag, in which case the `-x-` - * infix could be removed, or else we could rename the code in - * MediaWiki, in which case they'd move up to the above mapping - * of deprecated codes. - * - * As a rule, we preserve all distinctions made by MediaWiki - * internally. For example, `de-formal` becomes `de-x-formal` - * instead of just `de` because MediaWiki distinguishes `de-formal` - * from `de` (for example, for interface translations). Similarly, - * BCP 47 indicates that `kk-Cyrl` SHOULD not be used because it - * "typically does not add information", but in our case MediaWiki - * LanguageConverter distinguishes `kk` (render content in a mix of - * Kurdish variants) from `kk-Cyrl` (convert content to be uniformly - * Cyrillic). As the BCP 47 requirement is a SHOULD not a MUST, - * `kk-Cyrl` is a valid code, although some validators may emit - * a warning note. - * - * @var array Mapping from nonstandard codes to BCP 47 codes - * - * @since 1.32 - * @see https://meta.wikimedia.org/wiki/Special_language_codes - * @see https://phabricator.wikimedia.org/T125073 - */ - private static $nonstandardLanguageCodeMapping = [ - // All codes returned by Language::fetchLanguageNames() validated - // against IANA registry at - // https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry - // with help of validator at - // http://schneegans.de/lv/ - 'cbk-zam' => 'cbk', // T124657 - 'de-formal' => 'de-x-formal', - 'eml' => 'egl', // T36217 - 'en-rtl' => 'en-x-rtl', - 'es-formal' => 'es-x-formal', - 'hu-formal' => 'hu-x-formal', - 'map-bms' => 'jv-x-bms', // [[en:Banyumasan_dialect]] T125073 - 'mo' => 'ro-MD', // T125073 - 'nrm' => 'nrf', // [[en:Norman_language]] T25216 - 'nl-informal' => 'nl-x-informal', - 'roa-tara' => 'nap-x-tara', // [[en:Tarantino_dialect]] - 'simple' => 'en-simple', - 'sr-ec' => 'sr-Cyrl', // T117845 - 'sr-el' => 'sr-Latn', // T117845 - - // Although these next codes aren't *wrong* per se, including - // both the script and the country code helps compatibility with - // other BCP 47 users. Note that MW also uses `zh-Hans`/`zh-Hant`, - // without a country code, and those should be left alone. - // (See $variantfallbacks in LanguageZh.php for Hans/Hant id.) - 'zh-cn' => 'zh-Hans-CN', - 'zh-sg' => 'zh-Hans-SG', - 'zh-my' => 'zh-Hans-MY', - 'zh-tw' => 'zh-Hant-TW', - 'zh-hk' => 'zh-Hant-HK', - 'zh-mo' => 'zh-Hant-MO', + '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', ]; /** @@ -127,29 +64,6 @@ class LanguageCode { return self::$deprecatedLanguageCodeMapping; } - /** - * Returns a mapping of non-standard language codes used by - * (current and previous version of) MediaWiki, mapped to standard - * BCP 47 names. - * - * This array is exported to JavaScript to ensure - * mediawiki.language.bcp47 stays in sync with LanguageCode::bcp47(). - * - * @return string[] - * - * @since 1.32 - */ - public static function getNonstandardLanguageCodeMapping() { - $result = []; - foreach ( self::$deprecatedLanguageCodeMapping as $code => $ignore ) { - $result[$code] = self::bcp47( $code ); - } - foreach ( self::$nonstandardLanguageCodeMapping as $code => $ignore ) { - $result[$code] = self::bcp47( $code ); - } - return $result; - } - /** * Replace deprecated language codes that were used in previous * versions of MediaWiki to up-to-date, current language codes. @@ -173,15 +87,11 @@ class LanguageCode { * See mediawiki.language.bcp47 for the JavaScript implementation. * * @param string $code The language code. - * @return string A language code complying with BCP 47 standards. + * @return string The language code which complying with BCP 47 standards. * * @since 1.31 */ public static function bcp47( $code ) { - $code = self::replaceDeprecatedCodes( strtolower( $code ) ); - if ( isset( self::$nonstandardLanguageCodeMapping[$code] ) ) { - $code = self::$nonstandardLanguageCodeMapping[$code]; - } $codeSegment = explode( '-', $code ); $codeBCP = []; foreach ( $codeSegment as $segNo => $seg ) {