From: Shinjiman Date: Fri, 24 Jul 2009 17:41:01 +0000 (+0000) Subject: Tweak the language code display more comply with the BCP 47 standards, using a new... X-Git-Tag: 1.31.0-rc.0~40741 X-Git-Url: https://git.cyclocoop.org/%242?a=commitdiff_plain;h=0a114fd1ea0e7ec3e573c4babdfb5c8b145279e1;p=lhc%2Fweb%2Fwiklou.git Tweak the language code display more comply with the BCP 47 standards, using a new global function wfBCP47(). --- diff --git a/RELEASE-NOTES b/RELEASE-NOTES index 950508ceb2..e389e0278b 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -324,7 +324,9 @@ this. Was used when mwEmbed was going to be an extension. * (bug 16877) Moving a page over a redirect no longer leaves an orphan entry in the recentchanges table * (bug 16009) Limit selection forms based on Pager now links to the correct page - when using long urls + when using long urls +* The display of the language list on the preferences is more comply with the + BCP 47 standards. == API changes in 1.16 == diff --git a/config/index.php b/config/index.php index 0bce9e670d..12b45b7010 100644 --- a/config/index.php +++ b/config/index.php @@ -2094,7 +2094,7 @@ function getLanguageList() { if( preg_match( '/Messages([A-Z][a-z_]+)\.php$/', $f, $m ) ) { $code = str_replace( '_', '-', strtolower( $m[1] ) ); if( isset( $wgLanguageNames[$code] ) ) { - $name = $code . ' - ' . $wgLanguageNames[$code]; + $name = wfBCP47( $code ) . ' - ' . $wgLanguageNames[$code]; } else { $name = $code; } diff --git a/includes/GlobalFunctions.php b/includes/GlobalFunctions.php index 621b1fb516..f10f30cd44 100644 --- a/includes/GlobalFunctions.php +++ b/includes/GlobalFunctions.php @@ -3190,3 +3190,22 @@ function wfObjectToArray( $object, $recursive = true ) { return $array; } + +/* get the noramised IETF language tag */ +function wfBCP47( $code ) { + $codeSegment = explode( '-', $code ); + foreach ( $codeSegment as $segNo => $seg ) { + // ISO 3166 country code + if ( ( strlen( $seg ) == 2 ) && ( $segNo > 0 ) ) + $codeBCP[$segNo] = strtoupper ( $seg ); + // ISO 15924 script code + else if ( ( strlen( $seg ) == 4 ) && ( $segNo > 0 ) ) + $codeBCP[$segNo] = ucfirst( $seg ); + // Keep casing for other cases + else + $codeBCP[$segNo] = $seg; + } + $langCode = implode ( '-' , $codeBCP ); + return $langCode; +} + diff --git a/includes/Preferences.php b/includes/Preferences.php index e81ed5b658..49cdd0fc37 100644 --- a/includes/Preferences.php +++ b/includes/Preferences.php @@ -208,7 +208,7 @@ class Preferences { $options = array(); foreach( $languages as $code => $name ) { - $display = "$code - $name"; + $display = wfBCP47( $code ) . ' - ' . $name; $options[$display] = $code; } $defaultPreferences['language'] = @@ -237,7 +237,7 @@ class Preferences { $options = array(); foreach( $variantArray as $code => $name ) { - $display = "$code - $name"; + $display = wfBCP47( $code ) . ' - ' . $name; $options[$display] = $code; }