Page MenuHomePhabricator

langtag_normalization.patch

Authored By
bzimport
Nov 21 2014, 11:59 PM
Size
1 KB
Referenced Files
None
Subscribers
None

langtag_normalization.patch

Index: languages/Language.php
===================================================================
--- languages/Language.php (revision 105772)
+++ languages/Language.php (working copy)
@@ -132,6 +132,25 @@
'hijri-calendar-m10', 'hijri-calendar-m11', 'hijri-calendar-m12'
);
+ static public $mBCP47Normalizations = array(
+ 'simple' => 'en-x-simple',
+ 'als' => 'gsw', // als is now ISO gsw, but might later be moved to aeg
+ 'bat-smg' => 'sgs',
+ 'be-x-old' => 'be-tarask',
+ 'cbk-zam' => 'cbk', // Family name
+ 'ksh' => 'gem', // Family name. No ripuarian macrolanguage code, ksh too specific
+ 'fiu-vro' => 'vro',
+ 'map-bms' => 'map', // Family name. No Banyumasan langaguage code
+ 'ms' => 'zsm',
+ 'nds-nl' => 'nl', // A collection of dutch low saxon dialects
+ 'no' => 'nb',
+ 'roa-rup' => 'rup',
+ 'roa-tara' => 'roa', // Family name, no Tarantino language code
+ 'sq' => 'als',
+ 'zh-classical' => 'lzh',
+ 'zh-min-nan' => 'nan'
+ );
+
/**
* Get a cached language object for a given language code
* @param $code String
@@ -690,6 +709,22 @@
}
/**
+ * Get the BCP-47 tag of a MediaWiki language code
+ *
+ * http://tools.ietf.org/rfc/bcp/bcp47.txt
+ * http://en.wikipedia.org/wiki/IETF_language_tag
+ *
+ * @param $code String Language code.
+ * @return String bcp-47 code. If unknown, fallback to $code
+ */
+ public static function getBCP47LanguageTag( $code ) {
+ if( array_key_exists( $code, self::$mBCP47Normalizations ) ) {
+ return self::$mBCP47Normalizations[$code];
+ }
+ return $code;
+ }
+
+ /**
* Get a message from the MediaWiki namespace.
*
* @param $msg String: message name
@@ -3446,7 +3481,7 @@
* @return string
*/
function getCode() {
- return $this->mCode;
+ return Language::getBCP47LanguageTag($this->mCode);
}
/**

File Metadata

Mime Type
text/x-diff
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
7946
Default Alt Text
langtag_normalization.patch (1 KB)

Event Timeline