Index: trunk/phase3/languages/LanguageConverter.php |
— | — | @@ -976,6 +976,8 @@ |
977 | 977 | $flags=array_diff($flags,array('S')); |
978 | 978 | $flags_temp = array(); |
979 | 979 | foreach ($variants as $variant) { |
| 980 | + // try to find flags like "zh-hans", "zh-hant" |
| 981 | + // allow syntaxes like "-{zh-hans;zh-hant|XXXX}-" |
980 | 982 | if ( in_array($variant, $flags) ) |
981 | 983 | $flags_temp[] = $variant; |
982 | 984 | } |
— | — | @@ -1000,6 +1002,16 @@ |
1001 | 1003 | $markup = $this->mConverter->mMarkup; |
1002 | 1004 | $variants = $this->mConverter->mVariants; |
1003 | 1005 | |
| 1006 | + // varsep_pattern for preg_split: |
| 1007 | + // text should be splited by ";" only if a valid variant |
| 1008 | + // name exist after the markup, for example: |
| 1009 | + // -{zh-hans:<span style="font-size:120%;">xxx</span>;zh-hant:<span style="font-size:120%;">yyy</span>;}- |
| 1010 | + // we should split it as: |
| 1011 | + // array( |
| 1012 | + // [0] => 'zh-hans:<span style="font-size:120%;">xxx</span>' |
| 1013 | + // [1] => 'zh-hant:<span style="font-size:120%;">yyy</span>' |
| 1014 | + // [2] => '' |
| 1015 | + // ) |
1004 | 1016 | $varsep_pattern = '/' . $markup['varsep'] . '\s*' . '(?='; |
1005 | 1017 | foreach( $variants as $variant ) |
1006 | 1018 | $varsep_pattern .= $variant . '\s*' . $markup['codesep'] . '|'; |
— | — | @@ -1013,6 +1025,7 @@ |
1014 | 1026 | $to = trim($v[1]); |
1015 | 1027 | $v = trim($v[0]); |
1016 | 1028 | $u = explode($markup['unidsep'], $v); |
| 1029 | + // if $to is empty, strtr() could return a wrong result |
1017 | 1030 | if( count($u) == 1 && $to && in_array( $v, $variants ) ) { |
1018 | 1031 | $bidtable[$v] = $to; |
1019 | 1032 | } else if(count($u) == 2){ |
— | — | @@ -1148,14 +1161,19 @@ |
1149 | 1162 | $this->parseFlags(); |
1150 | 1163 | $flags = $this->mFlags; |
1151 | 1164 | |
1152 | | - //convert to specified variant |
| 1165 | + // convert to specified variant |
| 1166 | + // syntax: -{zh-hans;zh-hant[;...]|<text to convert>}- |
1153 | 1167 | if( count( array_diff( $flags, $variants ) ) == 0 and count( $flags ) != 0 ) { |
1154 | | - if ( in_array( $variant, $flags ) ) |
| 1168 | + if ( in_array( $variant, $flags ) ) // check if current variant in flags |
| 1169 | + // then convert <text to convert> to current language |
1155 | 1170 | $this->mRules = $this->mConverter->autoConvert( $this->mRules, $variant ); |
1156 | | - else { |
| 1171 | + else { // if current variant no in flags, |
| 1172 | + // then we check its fallback variants. |
1157 | 1173 | $variantFallbacks = $this->mConverter->getVariantFallbacks($variant); |
1158 | 1174 | foreach ( $variantFallbacks as $variantFallback ) { |
| 1175 | + // if current variant's fallback exist in flags |
1159 | 1176 | if ( in_array( $variantFallback, $flags ) ) { |
| 1177 | + // then convert <text to convert> to fallback language |
1160 | 1178 | $this->mRules = $this->mConverter->autoConvert( $this->mRules, $variantFallback ); |
1161 | 1179 | break; |
1162 | 1180 | } |