From e1eadafba831bf1536832a1ddb6732662cd7c747 Mon Sep 17 00:00:00 2001 From: Zheng Zhu Date: Fri, 8 Oct 2004 13:57:01 +0000 Subject: [PATCH] Added fallback in case the preferred language variant is not provided in the manual conversion markup. --- languages/Language.php | 24 +++++++++++++++++++++--- languages/LanguageZh.php | 10 ++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/languages/Language.php b/languages/Language.php index 106dd03948..19ac874274 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -2059,6 +2059,7 @@ class Language { $plang = $this->getPreferredVariant(); + $fallback = $this->getVariantFallback($plang); $tarray = explode("-{", $text); $tfirst = array_shift($tarray); @@ -2073,20 +2074,29 @@ class Language { $text .= $choice{0}; } else { + $choice1=false; + $choice2=false; foreach($choice as $c) { $v = explode(":", $c); if(!array_key_exists(1, $v)) { //syntax error in the markup, give up - $text .= $marked{0}; break; } $code = trim($v{0}); $content = trim($v{1}); if($code == $plang) { - $text .= $content; + $choice1 = $content; break; } + if($code == $fallback) + $choice2 = $content; } + if ( $choice1 ) + $text .= $choice1; + elseif ( $choice2 ) + $text .= $choice2; + else + $text .= $marked{0}; } if(array_key_exists(1, $marked)) $text .= $this->autoConvert($marked{1}); @@ -2109,7 +2119,15 @@ class Language { return array($lang); } - + # in case some variant is not defined in the markup, we need + # to have some fallback. for example, in zh, normally people + # will define zh-cn and zh-tw, but less so for zh-sg or zh-hk. + # when zh-sg is preferred but not defined, we will pick zh-cn + # in this case. right now this is only used by zh. + function getVariantFallback($v) { + return false; + } + function getPreferredVariant() { global $wgUser; diff --git a/languages/LanguageZh.php b/languages/LanguageZh.php index eb09c70116..b57b88b79b 100644 --- a/languages/LanguageZh.php +++ b/languages/LanguageZh.php @@ -104,5 +104,15 @@ class LanguageZh extends LanguageZh_cn { function getVariants() { return array("zh-cn", "zh-tw", "zh-sg", "zh-hk"); } + + function getVariantFallback($v) { + switch ($v) { + case 'zh-cn': return 'zh-sg'; break; + case 'zh-sg': return 'zh-cn'; break; + case 'zh-tw': return 'zh-hk'; break; + case 'zh-hk': return 'zh-tw'; break; + } + return false; + } } ?> -- 2.20.1