Index: trunk/phase3/languages/LanguageConverter.php |
— | — | @@ -183,7 +183,7 @@ |
184 | 184 | // explode by comma |
185 | 185 | $result = explode(',', $acceptLanguage); |
186 | 186 | |
187 | | - $languages = array(); |
| 187 | + $languages = array(); |
188 | 188 | |
189 | 189 | foreach( $result as $elem ) { |
190 | 190 | // if $elem likes 'zh-cn;q=0.9' |
— | — | @@ -196,14 +196,32 @@ |
197 | 197 | } |
198 | 198 | } |
199 | 199 | |
| 200 | + $fallback_languages = array(); |
200 | 201 | foreach( $languages as $language ) { |
201 | 202 | // strip whitespace |
202 | 203 | $language = trim( $language ); |
203 | 204 | if( in_array( $language, $this->mVariants ) ) { |
204 | | - $this->mPreferredVariant = $language; |
205 | | - return $this->mPreferredVariant; |
| 205 | + return $language; |
206 | 206 | } |
| 207 | + else { |
| 208 | + // To see if there are fallbacks of current language. |
| 209 | + // We record these fallback variants, and process |
| 210 | + // them later. |
| 211 | + $fallbacks = $this->getVariantFallbacks( $language ); |
| 212 | + if( is_string( $fallbacks ) ) |
| 213 | + $fallback_languages[] = $fallbacks; |
| 214 | + elseif( is_array( $fallbacks ) ) |
| 215 | + $fallback_languages = array_merge( $fallback_languages, $fallbacks ); |
| 216 | + } |
207 | 217 | } |
| 218 | + |
| 219 | + // process fallback languages now |
| 220 | + $fallback_languages = array_unique( $fallback_languages ); |
| 221 | + foreach( $fallback_languages as $language ) { |
| 222 | + if( in_array( $language, $this->mVariants ) ) { |
| 223 | + return $language; |
| 224 | + } |
| 225 | + } |
208 | 226 | } |
209 | 227 | } |
210 | 228 | |
Index: trunk/phase3/languages/classes/LanguageZh.php |
— | — | @@ -132,7 +132,17 @@ |
133 | 133 | global $wgHooks; |
134 | 134 | parent::__construct(); |
135 | 135 | |
136 | | - $variants = array('zh','zh-hans','zh-hant','zh-cn','zh-hk','zh-mo','zh-my','zh-sg','zh-tw'); |
| 136 | + $variants_all = array('zh','zh-hans','zh-hant','zh-cn','zh-hk','zh-mo','zh-my','zh-sg','zh-tw'); |
| 137 | + $variants = array(); |
| 138 | + |
| 139 | + // If a wiki disabled some variants, |
| 140 | + // LanguageConverter shouldn't process them |
| 141 | + foreach( $variants_all as $variant ) { |
| 142 | + $status = wfMsgExt( "variantname-$variant", array( 'parsemag', 'language' => $this ) ); |
| 143 | + if( trim($status) != 'disable' ) |
| 144 | + $variants[] = $variant; |
| 145 | + } |
| 146 | + |
137 | 147 | $variantfallbacks = array( |
138 | 148 | 'zh' => array('zh-hans','zh-hant','zh-cn','zh-tw','zh-hk','zh-sg','zh-mo','zh-my'), |
139 | 149 | 'zh-hans' => array('zh-cn','zh-sg','zh-my'), |