Index: trunk/phase3/languages/LanguageConverter.php |
— | — | @@ -77,7 +77,7 @@ |
78 | 78 | // these flags above are reserved for program |
79 | 79 | 'A'=>'A', // add rule for convert code (all text convert) |
80 | 80 | 'T'=>'T', // title convert |
81 | | - 'R'=>'R', // raw content |
| 81 | + 'R'=>'R', // row content |
82 | 82 | 'D'=>'D', // convert description (subclass implement) |
83 | 83 | '-'=>'-', // remove convert (not implement) |
84 | 84 | 'H'=>'H', // add rule for convert code (but no display in placed code ) |
— | — | @@ -91,6 +91,7 @@ |
92 | 92 | $this->mManualAddTables[$v] = array(); |
93 | 93 | $this->mManualRemoveTables[$v] = array(); |
94 | 94 | $this->mNamespaceTables[$v] = array(); |
| 95 | + $this->mFlags[$v] = $v; |
95 | 96 | } |
96 | 97 | } |
97 | 98 | |
— | — | @@ -873,7 +874,7 @@ |
874 | 875 | /** |
875 | 876 | * parser for rules of language conversion , parse rules in -{ }- tag |
876 | 877 | * @ingroup Language |
877 | | - * @author fdcn <fdcn64@gmail.com> |
| 878 | + * @author fdcn <fdcn64@gmail.com>, PhiLiP <philip.npc@gmail.com> |
878 | 879 | */ |
879 | 880 | class ConverterRule { |
880 | 881 | var $mText; // original text in -{text}- |
— | — | @@ -935,6 +936,7 @@ |
936 | 937 | $flags = array(); |
937 | 938 | $markup = $this->mConverter->mMarkup; |
938 | 939 | $validFlags = $this->mConverter->mFlags; |
| 940 | + $variants = $this->mConverter->mVariants; |
939 | 941 | |
940 | 942 | $tt = explode($markup['flagsep'], $text, 2); |
941 | 943 | if(count($tt) == 2) { |
— | — | @@ -966,14 +968,21 @@ |
967 | 969 | if(in_array('D',$flags)) $temp[] = 'D'; |
968 | 970 | $flags = $temp; |
969 | 971 | } else { |
970 | | - if ( in_array('A',$flags)) { |
| 972 | + if ( in_array('A',$flags) ) { |
971 | 973 | $flags[]='+'; |
972 | 974 | $flags[]='S'; |
973 | 975 | } |
974 | 976 | if ( in_array('D',$flags) ) |
975 | 977 | $flags=array_diff($flags,array('S')); |
| 978 | + $flags_temp = array(); |
| 979 | + foreach ($variants as $variant) { |
| 980 | + if ( in_array($variant, $flags) ) |
| 981 | + $flags_temp[] = $variant; |
| 982 | + } |
| 983 | + if ( count($flags_temp) == 0 ) |
| 984 | + $flags = $flags_temp; |
976 | 985 | } |
977 | | - if ( count($flags)==0 ) |
| 986 | + if ( count($flags) == 0 ) |
978 | 987 | $flags = array('S'); |
979 | 988 | $this->mRules=$rules; |
980 | 989 | $this->mFlags=$flags; |
— | — | @@ -992,23 +1001,24 @@ |
993 | 1002 | |
994 | 1003 | $choice = explode($markup['varsep'], $rules); |
995 | 1004 | foreach($choice as $c) { |
996 | | - $v = explode($markup['codesep'], $c, 2); |
997 | | - if(count($v) != 2) |
| 1005 | + $v = explode($markup['codesep'], $c, 2); |
| 1006 | + if( count($v) != 2 ) |
998 | 1007 | continue;// syntax error, skip |
999 | | - $to=trim($v[1]); |
1000 | | - $v=trim($v[0]); |
1001 | | - $u = explode($markup['unidsep'], $v); |
1002 | | - if(count($u) == 1) { |
| 1008 | + $to = trim($v[1]); |
| 1009 | + $v = trim($v[0]); |
| 1010 | + $u = explode($markup['unidsep'], $v); |
| 1011 | + if( count($u) == 1 ) { |
1003 | 1012 | $bidtable[$v] = $to; |
1004 | 1013 | } else if(count($u) == 2){ |
1005 | | - $from=trim($u[0]);$v=trim($u[1]); |
1006 | | - if( array_key_exists($v,$unidtable) && !is_array($unidtable[$v]) ) |
1007 | | - $unidtable[$v]=array($from=>$to); |
| 1014 | + $from = trim($u[0]); |
| 1015 | + $v = trim($u[1]); |
| 1016 | + if( array_key_exists( $v, $unidtable ) && !is_array( $unidtable[$v] ) ) |
| 1017 | + $unidtable[$v] = array( $from=>$to ); |
1008 | 1018 | else |
1009 | | - $unidtable[$v][$from]=$to; |
| 1019 | + $unidtable[$v][$from] = $to; |
1010 | 1020 | } |
1011 | 1021 | // syntax error, pass |
1012 | | - if (!array_key_exists($v,$this->mConverter->mVariantNames)){ |
| 1022 | + if ( !array_key_exists( $v, $this->mConverter->mVariantNames ) ){ |
1013 | 1023 | $bidtable = array(); |
1014 | 1024 | $unidtable = array(); |
1015 | 1025 | break; |
— | — | @@ -1124,12 +1134,30 @@ |
1125 | 1135 | * @public |
1126 | 1136 | */ |
1127 | 1137 | function parse($variant){ |
1128 | | - if(!$variant) $variant = $this->mConverter->getPreferredVariant(); |
| 1138 | + if(!$variant) |
| 1139 | + $variant = $this->mConverter->getPreferredVariant(); |
1129 | 1140 | |
| 1141 | + $variants = $this->mConverter->mVariants; |
1130 | 1142 | $this->parseFlags(); |
1131 | 1143 | $flags = $this->mFlags; |
1132 | 1144 | |
1133 | | - if( !in_array('R',$flags) || !in_array('N',$flags) ){ |
| 1145 | + //convert to specified variant |
| 1146 | + if( count( array_diff( $flags, $variants ) ) == 0 and count( $flags ) != 0 ) { |
| 1147 | + if ( in_array( $variant, $flags ) ) |
| 1148 | + $this->mRules = $this->mConverter->autoConvert( $this->mRules, $variant ); |
| 1149 | + else { |
| 1150 | + $variantFallbacks = $this->mConverter->getVariantFallbacks($variant); |
| 1151 | + foreach ( $variantFallbacks as $variantFallback ) { |
| 1152 | + if ( in_array( $variantFallback, $flags ) ) { |
| 1153 | + $this->mRules = $this->mConverter->autoConvert( $this->mRules, $variantFallback ); |
| 1154 | + break; |
| 1155 | + } |
| 1156 | + } |
| 1157 | + } |
| 1158 | + $this->mFlags = $flags = array('R'); |
| 1159 | + } |
| 1160 | + |
| 1161 | + if( !in_array( 'R', $flags ) || !in_array( 'N', $flags ) ) { |
1134 | 1162 | //FIXME: may cause trouble here... |
1135 | 1163 | //strip since it interferes with the parsing, plus, |
1136 | 1164 | //all spaces should be stripped in this tag anyway. |
— | — | @@ -1141,7 +1169,7 @@ |
1142 | 1170 | } |
1143 | 1171 | $rules = $this->mRules; |
1144 | 1172 | |
1145 | | - if(count($this->mBidtable)==0 && count($this->mUnidtable)==0){ |
| 1173 | + if( count( $this->mBidtable ) == 0 && count( $this->mUnidtable ) == 0 ){ |
1146 | 1174 | if(in_array('+',$flags) || in_array('-',$flags)) |
1147 | 1175 | // fill all variants if text in -{A/H/-|text} without rules |
1148 | 1176 | foreach($this->mConverter->mVariants as $v) |
Index: trunk/phase3/languages/classes/LanguageZh.php |
— | — | @@ -53,7 +53,7 @@ |
54 | 54 | 'Special' => '特殊', |
55 | 55 | 'Talk' => '讨论', |
56 | 56 | 'User' => '用户', |
57 | | - 'User Talk' => '用户讨论', |
| 57 | + 'User talk' => '用户讨论', |
58 | 58 | $nsproject |
59 | 59 | => isset($projecttable[$nsproject]) ? |
60 | 60 | $projecttable[$nsproject] : $nsproject, |
Index: trunk/phase3/RELEASE-NOTES |
— | — | @@ -125,6 +125,8 @@ |
126 | 126 | with class 'mw-specialpage-summary' |
127 | 127 | * $wgSummarySpamRegex added to handle edit summary spam. This is used *instead* |
128 | 128 | of $wgSpamRegex for edit summary checks. Text checks still use $wgSpamRegex. |
| 129 | +* New function to convert content text to specified language (only applies on wiki with |
| 130 | + LanguageConverter class) |
129 | 131 | |
130 | 132 | === Bug fixes in 1.15 === |
131 | 133 | * (bug 16968) Special:Upload no longer throws useless warnings. |