jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/330041 )

Change subject: Map MediaWiki's fake language codes to real ones
......................................................................


Map MediaWiki's fake language codes to real ones

'My understanding of the problem is that when someone uses
{{#babel:zh-classical}}, the extension puts the user into "Category:User
zh-classical" instead of into "Category:User lzh" even though they mean
the same thing. Instead, it should understand that zh-classical is a
legacy code and convert it to lzh, to avoid duplicate categories.'
-- Nikki at the phab task

Bug: T101086
Depends-On: If73c74ee87d8235381449cab7dcd9f46b0f23590
Change-Id: I1ae053574805e4d118389f6bbf6dcf391fbed73b
---
M BabelLanguageCodes.class.php
M tests/phpunit/BabelLanguageCodesTest.php
2 files changed, 12 insertions(+), 0 deletions(-)

Approvals:
  jenkins-bot: Verified
  Thiemo Mättig (WMDE): Looks good to me, but someone else must approve
  Nikerabbit: Looks good to me, approved



diff --git a/BabelLanguageCodes.class.php b/BabelLanguageCodes.class.php
index dfd2e73..41586de 100644
--- a/BabelLanguageCodes.class.php
+++ b/BabelLanguageCodes.class.php
@@ -21,11 +21,22 @@
         * @return string|bool Language code, or false for invalid language 
code.
         */
        public static function getCode( $code ) {
+               // Is the code one of MediaWiki's legacy fake codes? If so, 
return the modern
+               // equivalent code (T101086)
+               if ( method_exists( 'LanguageCode', 'getDeprecatedCodeMapping' 
) ) {
+                       $mapping = LanguageCode::getDeprecatedCodeMapping();
+                       if ( isset( $mapping[strtolower( $code )] ) ) {
+                               return $mapping[strtolower( $code )];
+                       }
+               }
+
+               // Is the code known to MediaWiki?
                $mediawiki = Language::fetchLanguageName( $code );
                if ( $mediawiki !== '' ) {
                        return $code;
                }
 
+               // Otherwise, fall back to the ISO 639 codes database
                $codes = false;
                try {
                        $codesCdb = Cdb\Reader::open( __DIR__ . '/codes.cdb' );
diff --git a/tests/phpunit/BabelLanguageCodesTest.php 
b/tests/phpunit/BabelLanguageCodesTest.php
index 64cebec..624b65b 100644
--- a/tests/phpunit/BabelLanguageCodesTest.php
+++ b/tests/phpunit/BabelLanguageCodesTest.php
@@ -29,6 +29,7 @@
                        [ 'eng', 'en' ],
                        [ 'en-gb', 'en-gb' ],
                        [ 'de', 'de' ],
+                       [ 'be-x-old', 'be-tarask' ],
                ];
        }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/330041
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I1ae053574805e4d118389f6bbf6dcf391fbed73b
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/Babel
Gerrit-Branch: master
Gerrit-Owner: TTO <at.li...@live.com.au>
Gerrit-Reviewer: Amire80 <amir.ahar...@mail.huji.ac.il>
Gerrit-Reviewer: Fomafix <foma...@googlemail.com>
Gerrit-Reviewer: Liuxinyu970226 <541329...@qq.com>
Gerrit-Reviewer: Nemo bis <federicol...@tiscali.it>
Gerrit-Reviewer: Nikerabbit <niklas.laxst...@gmail.com>
Gerrit-Reviewer: TTO <at.li...@live.com.au>
Gerrit-Reviewer: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to