[MediaWiki-commits] [Gerrit] mediawiki...Babel[master]: Map MediaWiki's fake language codes to real ones

2017-05-20 Thread jenkins-bot (Code Review)
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 
Gerrit-Reviewer: Amire80 
Gerrit-Reviewer: Fomafix 
Gerrit-Reviewer: Liuxinyu970226 <541329...@qq.com>
Gerrit-Reviewer: Nemo bis 
Gerrit-Reviewer: Nikerabbit 
Gerrit-Reviewer: TTO 
Gerrit-Reviewer: Thiemo Mättig (WMDE) 
Gerrit-Reviewer: jenkins-bot <>

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


[MediaWiki-commits] [Gerrit] mediawiki...Babel[master]: Map MediaWiki's fake language codes to real ones

2017-01-01 Thread TTO (Code Review)
TTO has uploaded a new change for review. ( 
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
Change-Id: I1ae053574805e4d118389f6bbf6dcf391fbed73b
---
M BabelLanguageCodes.class.php
1 file changed, 23 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Babel 
refs/changes/41/330041/1

diff --git a/BabelLanguageCodes.class.php b/BabelLanguageCodes.class.php
index dfd2e73..82dc50c 100644
--- a/BabelLanguageCodes.class.php
+++ b/BabelLanguageCodes.class.php
@@ -13,6 +13,24 @@
  */
 class BabelLanguageCodes {
/**
+* @var array A list of MediaWiki fake/legacy language codes, and the 
ISO
+* codes they correspond to. This is almost the same as core's
+* $wgDummyLanguageCodes variable, except that a few things that aren't
+* strictly aliases ('no' => 'nb', 'simple' => 'en') are left out.
+*/
+   public static $fakeCodes = [
+   'als' => 'gsw',
+   'bat-smg' => 'sgs',
+   'be-x-old' => 'be-tarask',
+   'bh' => 'bho',
+   'fiu-vro' => 'vro',
+   'roa-rup' => 'rup',
+   'zh-classical' => 'lzh',
+   'zh-min-nan' => 'nan',
+   'zh-yue' => 'yue',
+   ];
+
+   /**
 * Takes a language code, and attempt to obtain a better variant of it,
 * checks the MediaWiki language codes for a match, otherwise checks the
 * Babel language codes CDB (preferring ISO 639-1 over ISO 639-3).
@@ -21,6 +39,11 @@
 * @return string|bool Language code, or false for invalid language 
code.
 */
public static function getCode( $code ) {
+   // map fake MediaWiki language codes to their real counterparts 
(T101086)
+   if ( isset( self::$fakeCodes[$code] ) ) {
+   $code = self::$fakeCodes[$code];
+   }
+
$mediawiki = Language::fetchLanguageName( $code );
if ( $mediawiki !== '' ) {
return $code;

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I1ae053574805e4d118389f6bbf6dcf391fbed73b
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Babel
Gerrit-Branch: master
Gerrit-Owner: TTO 

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