function getPreferredVariant() {
global $wgUser;
-
+
+ $lang ='';
+
// if user logged in, get in from user's preference
- if( $wgUser->getID() != 0 )
- return $wgUser->getOption( 'variant' );
-
+ if( $wgUser->getID() != 0 ) {
+ $lang = $wgUser->getOption( 'variant' );
+ }
+ if($lang != '')
+ return $lang;
+
// if we have multiple variants for this langauge,
- // pick the first one as default
+ // pick the first one that's not utf8 (it could be
+ // utf8 if the language does not have a language file)
$v = $this->getVariants();
- if( !empty( $v ) )
- return $v{0};
-
- // otherwise there should really be just one variant,
+ if( !empty( $v ) ) {
+ foreach ($v as $v2) {
+ if($v2 != 'utf8') {
+ $lang = $v2;
+ break;
+ }
+ }
+ }
+ if($lang != '')
+ return $lang;
+
// get it from the class name
$lang = strtolower( substr( get_class( $this ), 8 ) );
+ if($lang == 'utf8')
+ $lang = 'en';
return $lang;
}
global $IP;
# overwrite language conversion option so that all variants
- # of the messages are initialised
+ # of the selected language are initialised
$wgDisableLangConversion = false;
- $langclass = 'Language'. str_replace( '-', '_', ucfirst( $wgContLanguageCode ) );
- require_once("$IP/languages/$langclass.php");
-
- $variants = $wgContLang->getVariants();
- if(!in_array($wgContLanguageCode, $variants))
- $variants[]=$wgContLanguageCode;
-
if ( $messageArray ) {
$sortedArray = $messageArray;
} else {
}
ksort( $sortedArray );
-
$messages=array();
- foreach ($variants as $v) {
- $langclass = 'Language'. str_replace( '-', '_', ucfirst( $v ) );
- $lang = new $langclass;
- if(!is_object($lang)) {
- die ("class $langclass not defined. perhaps you need to include the file $langclass.php in $wgContLangClass.php?");
- }
- if($v==$wgContLanguageCode)
- $suffix='';
- else
- $suffix="/$v";
+
+ /* check special case where the language does
+ not have a language file
+ */
+ if( get_class($wgContLang) != 'language'.strtolower($wgContLanguageCode) ) {
foreach ($sortedArray as $key => $msg) {
- $messages[$key.$suffix] = $lang->getMessage($key);
+ $messages[$key] = $wgContLang->getMessage($key);
+ }
+ }
+ else {
+ $variants = $wgContLang->getVariants();
+ if(!in_array($wgContLanguageCode, $variants))
+ $variants[]=$wgContLanguageCode;
+
+ foreach ($variants as $v) {
+ $langclass = 'Language'. str_replace( '-', '_', ucfirst( $v ) );
+ if( !class_exists($langclass) ) {
+ die ("class $langclass not defined. perhaps you need to include the file $langclass.php in $wgContLangClass.php?");
+ }
+ $lang = new $langclass;
+
+ if($v==$wgContLanguageCode)
+ $suffix='';
+ else
+ $suffix="/$v";
+ foreach ($sortedArray as $key => $msg) {
+ $messages[$key.$suffix] = $lang->getMessage($key);
+ }
}
}