jenkins-bot has submitted this change and it was merged. ( https://gerrit.wikimedia.org/r/361724 )
Change subject: Add new static function LanguageCode::replaceDeprecatedCodes ...................................................................... Add new static function LanguageCode::replaceDeprecatedCodes Refactor the deprecatedLanguageCodeMapping to a private variable. Change-Id: I5f8e601e53de183e6268c9ef601eef8390b725cd --- M languages/LanguageCode.php M tests/phpunit/languages/LanguageCodeTest.php 2 files changed, 47 insertions(+), 12 deletions(-) Approvals: C. Scott Ananian: Looks good to me, approved jenkins-bot: Verified diff --git a/languages/LanguageCode.php b/languages/LanguageCode.php index 7c9da77..3fa3dc1 100644 --- a/languages/LanguageCode.php +++ b/languages/LanguageCode.php @@ -28,6 +28,27 @@ */ class LanguageCode { /** + * Mapping of deprecated language codes that were used in previous + * versions of MediaWiki to up-to-date, current language codes. + * + * @var array Mapping from language code to language code + * + * @since 1.30 + */ + 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', + 'bat-smg' => 'sgs', + 'be-x-old' => 'be-tarask', + 'fiu-vro' => 'vro', + 'roa-rup' => 'rup', + 'zh-classical' => 'lzh', + 'zh-min-nan' => 'nan', + 'zh-yue' => 'yue', + ]; + + /** * Returns a mapping of deprecated language codes that were used in previous * versions of MediaWiki to up-to-date, current language codes. * @@ -36,19 +57,27 @@ * MediaWiki's localisation system. * * @return string[] + * + * @since 1.29 */ 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', - ]; + return self::$deprecatedLanguageCodeMapping; + } + + /** + * Replace deprecated language codes that were used in previous + * versions of MediaWiki to up-to-date, current language codes. + * Other values will returned unchanged. + * + * @param string $code Old language code + * @return string New language code + * + * @since 1.30 + */ + public static function replaceDeprecatedCodes( $code ) { + if ( isset( self::$deprecatedLanguageCodeMapping[$code] ) ) { + return self::$deprecatedLanguageCodeMapping[$code]; + } + return $code; } } diff --git a/tests/phpunit/languages/LanguageCodeTest.php b/tests/phpunit/languages/LanguageCodeTest.php index b33360c..7689ef1 100644 --- a/tests/phpunit/languages/LanguageCodeTest.php +++ b/tests/phpunit/languages/LanguageCodeTest.php @@ -37,4 +37,10 @@ $this->assertArrayNotHasKey( 'simple', $map ); } + public function testReplaceDeprecatedCodes() { + $this->assertEquals( 'gsw', LanguageCode::replaceDeprecatedCodes( 'als' ) ); + $this->assertEquals( 'gsw', LanguageCode::replaceDeprecatedCodes( 'gsw' ) ); + $this->assertEquals( null, LanguageCode::replaceDeprecatedCodes( null ) ); + } + } -- To view, visit https://gerrit.wikimedia.org/r/361724 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I5f8e601e53de183e6268c9ef601eef8390b725cd Gerrit-PatchSet: 6 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Fomafix <foma...@googlemail.com> Gerrit-Reviewer: C. Scott Ananian <canan...@wikimedia.org> Gerrit-Reviewer: Fomafix <foma...@googlemail.com> Gerrit-Reviewer: jenkins-bot <> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits