Index: trunk/phase3/languages/classes/LanguageZh.php |
— | — | @@ -14,6 +14,8 @@ |
15 | 15 | $markup=array(), |
16 | 16 | $flags = array(), |
17 | 17 | $manualLevel = array() ) { |
| 18 | + $this->mDescCodeSep = ':'; |
| 19 | + $this->mDescVarSep = ';'; |
18 | 20 | parent::__construct($langobj, $maincode, |
19 | 21 | $variants, |
20 | 22 | $variantfallbacks, |
— | — | @@ -65,14 +67,6 @@ |
66 | 68 | function markNoConversion($text, $noParse = false) { |
67 | 69 | return $text; |
68 | 70 | } |
69 | | - |
70 | | - /* description of convert code in chinese language*/ |
71 | | - function getRulesDesc($bidtable,$unidtable){ |
72 | | - $text=parent::getRulesDesc($bidtable,$unidtable); |
73 | | - $text=str_replace(':',':',$text); |
74 | | - $text=str_replace(';',';',$text); |
75 | | - return $text; |
76 | | - } |
77 | 71 | |
78 | 72 | function convertCategoryKey( $key ) { |
79 | 73 | return $this->autoConvert( $key, 'zh' ); |
Index: trunk/phase3/languages/LanguageConverter.php |
— | — | @@ -1,13 +1,20 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | /** |
5 | | - * @ingroup Language |
6 | | - * |
7 | | - * @author Zhengzhu Feng <zhengzhu@gmail.com> |
8 | | - * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License |
9 | | - * @maintainers fdcn <fdcn64@gmail.com>, shinjiman <shinjiman@gmail.com> |
10 | | - */ |
| 5 | + * Contains the LanguageConverter class and ConverterRule class |
| 6 | + * @ingroup Language |
| 7 | + * |
| 8 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License |
| 9 | + * @file |
| 10 | + */ |
11 | 11 | |
| 12 | +/** |
| 13 | + * base class for language convert |
| 14 | + * @ingroup Language |
| 15 | + * |
| 16 | + * @author Zhengzhu Feng <zhengzhu@gmail.com> |
| 17 | + * @maintainers fdcn <fdcn64@gmail.com>, shinjiman <shinjiman@gmail.com> |
| 18 | + */ |
12 | 19 | class LanguageConverter { |
13 | 20 | var $mPreferredVariant=''; |
14 | 21 | var $mMainLanguageCode; |
— | — | @@ -22,6 +29,7 @@ |
23 | 30 | var $mLangObj; |
24 | 31 | var $mMarkup; |
25 | 32 | var $mFlags; |
| 33 | + var $mDescCodeSep = ':',$mDescVarSep = ';'; |
26 | 34 | var $mUcfirst = false; |
27 | 35 | |
28 | 36 | const CACHE_VERSION_KEY = 'VERSION 6'; |
— | — | @@ -34,7 +42,7 @@ |
35 | 43 | * @param array $variantfallback the fallback language of each variant |
36 | 44 | * @param array $markup array defining the markup used for manual conversion |
37 | 45 | * @param array $flags array defining the custom strings that maps to the flags |
38 | | - * @access public |
| 46 | + * @public |
39 | 47 | */ |
40 | 48 | function __construct($langobj, $maincode, |
41 | 49 | $variants=array(), |
— | — | @@ -94,7 +102,7 @@ |
95 | 103 | * |
96 | 104 | * @param string $v the language code of the variant |
97 | 105 | * @return string array the code of the fallback language or false if there is no fallback |
98 | | - * @private |
| 106 | + * @public |
99 | 107 | */ |
100 | 108 | function getVariantFallbacks($v) { |
101 | 109 | if( isset( $this->mVariantFallbacks[$v] ) ) { |
— | — | @@ -304,6 +312,31 @@ |
305 | 313 | |
306 | 314 | |
307 | 315 | /** |
| 316 | + * apply manual conversion |
| 317 | + * @private |
| 318 | + */ |
| 319 | + function applyManualConv($convRule){ |
| 320 | + // use syntax -{T|zh:TitleZh;zh-tw:TitleTw}- for custom conversion in title |
| 321 | + $title = $convRule->getTitle(); |
| 322 | + if($title){ |
| 323 | + $this->mTitleFromFlag = true; |
| 324 | + $this->mTitleDisplay = $title; |
| 325 | + } |
| 326 | + |
| 327 | + //add manual conversion table to global table |
| 328 | + $convTable = $convRule->getConvTable(); |
| 329 | + $isAdd = $convRule->getRulesAction()=="add"; |
| 330 | + $isRemove = $convRule->getRulesAction()=="remove"; |
| 331 | + foreach($convTable as $v=>$t) { |
| 332 | + if( !in_array($v,$this->mVariants) )continue; |
| 333 | + if( $isAdd ) |
| 334 | + $this->mTables[$v]->mergeArray($t); |
| 335 | + elseif ( $isRemove ) |
| 336 | + $this->mTables[$v]->removeArray($t); |
| 337 | + } |
| 338 | + } |
| 339 | + |
| 340 | + /** |
308 | 341 | * Convert text using a parser object for context |
309 | 342 | * @public |
310 | 343 | */ |
— | — | @@ -325,66 +358,6 @@ |
326 | 359 | } |
327 | 360 | |
328 | 361 | /** |
329 | | - * @private |
330 | | - */ |
331 | | - function applyManualConv($convRule,$variant){ |
332 | | - if(!$variant) $variant = $this->getPreferredVariant(); |
333 | | - $rules = $convRule->getRules(); |
334 | | - $flags = $convRule->getFlags(); |
335 | | - list($bidtable, $unidtable) = $convRule->getConvTable(); |
336 | | - |
337 | | - $is_title_flag = in_array('T', $flags); |
338 | | - // use syntax -{T|zh:TitleZh;zh-tw:TitleTw}- for custom conversion in title |
339 | | - if($is_title_flag){ |
340 | | - $this->mTitleFromFlag = true; |
341 | | - $this->mTitleDisplay = $convRule->getTitle(); |
342 | | - } |
343 | | - |
344 | | - if($this->mManualLevel[$variant]=='disable') return; |
345 | | - |
346 | | - $is_remove_flag = !$is_title_flag && in_array('-', $flags); |
347 | | - $is_add_flag = !$is_remove_flag && in_array('+', $flags); |
348 | | - $is_bidMC = $this->mManualLevel[$variant]=='bidirectional'; |
349 | | - $is_unidMC = $this->mManualLevel[$variant]=='unidirectional'; |
350 | | - $vmarked=array(); |
351 | | - |
352 | | - foreach($this->mVariants as $v) { |
353 | | - /* for bidirectional array |
354 | | - fill in the missing variants, if any, |
355 | | - with fallbacks */ |
356 | | - if($is_bidMC && !array_key_exists($v, $bidtable)) { |
357 | | - $vf = $convRule->getTextInBidtable($this->getVariantFallbacks($v) ); |
358 | | - if($vf) $bidtable[$v] = $vf; |
359 | | - } |
360 | | - if($is_bidMC && array_key_exists($v,$bidtable)){ |
361 | | - foreach($vmarked as $vo){ |
362 | | - // use syntax: |
363 | | - // -{A|zh:WordZh;zh-tw:WordTw}- or -{+|zh:WordZh;zh-tw:WordTw}- |
364 | | - // to introduce a custom mapping between |
365 | | - // words WordZh and WordTw in the whole text |
366 | | - if($is_add_flag){ |
367 | | - $this->mTables[$v]->setPair($bidtable[$vo], $bidtable[$v]); |
368 | | - $this->mTables[$vo]->setPair($bidtable[$v], $bidtable[$vo]); |
369 | | - } |
370 | | - // use syntax -{-|zh:WordZh;zh-tw:WordTw}- to remove a conversion |
371 | | - // words WordZh and WordTw in the whole text |
372 | | - if($is_remove_flag){ |
373 | | - $this->mTables[$v]->removePair($bidtable[$vo]); |
374 | | - $this->mTables[$vo]->removePair($bidtable[$v]); |
375 | | - } |
376 | | - } |
377 | | - $vmarked[]=$v; |
378 | | - } |
379 | | - /*for unidirectional array |
380 | | - fill to convert tables */ |
381 | | - if($is_unidMC && array_key_exists($v,$unidtable)){ |
382 | | - if($is_add_flag)$this->mTables[$v]->mergeArray($unidtable[$v]); |
383 | | - if($is_remove_flag)$this->mTables[$v]->removeArray($unidtable[$v]); |
384 | | - } |
385 | | - } |
386 | | - } |
387 | | - |
388 | | - /** |
389 | 362 | * convert title |
390 | 363 | * @private |
391 | 364 | */ |
— | — | @@ -447,33 +420,23 @@ |
448 | 421 | if ($isTitle) return $this->convertTitle($text); |
449 | 422 | |
450 | 423 | $plang = $this->getPreferredVariant(); |
451 | | - |
452 | | - $tarray = explode($this->mMarkup['begin'], $text); |
453 | | - $tfirst = array_shift($tarray); |
454 | | - if($this->mDoContentConvert) |
455 | | - $text = $this->autoConvert($tfirst,$plang); |
456 | | - else |
457 | | - $text = $tfirst; |
| 424 | + $tarray = explode($this->mMarkup['end'], $text); |
| 425 | + $text = ''; |
458 | 426 | foreach($tarray as $txt) { |
459 | | - $marked = explode($this->mMarkup['end'], $txt, 2); |
| 427 | + $marked = explode($this->mMarkup['begin'], $txt, 2); |
460 | 428 | |
461 | | - // strip the flags from syntax like -{T| ... }- |
462 | | - $crule = new ConverterRule($marked[0], |
463 | | - $this->mMarkup, $this->mFlags, |
464 | | - $this->mVariantNames, |
465 | | - $this->mDoContentConvert, |
466 | | - $this->mDoTitleConvert); |
467 | | - $crule->parse($plang, |
468 | | - $this->getVariantFallbacks($plang), |
469 | | - $this->mManualLevel[$plang]=='disable'); |
470 | | - $text .= $crule->getDisplay(); |
471 | | - $this->applyManualConv($crule,$plang); |
| 429 | + if( $this->mDoContentConvert ) |
| 430 | + $text .= $this->autoConvert($marked[0],$plang); |
| 431 | + else |
| 432 | + $text .= $marked[0]; |
472 | 433 | |
473 | 434 | if(array_key_exists(1, $marked)){ |
474 | | - if( $this->mDoContentConvert ) |
475 | | - $text .= $this->autoConvert($marked[1],$plang); |
476 | | - else |
477 | | - $text .= $marked[1]; |
| 435 | + // strip the flags from syntax like -{T| ... }- |
| 436 | + $crule = new ConverterRule($marked[1], $this); |
| 437 | + $crule->parse($plang); |
| 438 | + |
| 439 | + $text .= $crule->getDisplay(); |
| 440 | + $this->applyManualConv($crule); |
478 | 441 | } |
479 | 442 | } |
480 | 443 | |
— | — | @@ -805,37 +768,29 @@ |
806 | 769 | */ |
807 | 770 | class ConverterRule { |
808 | 771 | var $mText; // original text in -{text}- |
809 | | - var $mVariantNames; |
810 | | - var $mMarkup; |
811 | | - var $mRules; |
812 | | - var $mFlags; |
813 | | - var $mManualCodeError='<span style="color: red;">code error!</span>'; |
814 | | - var $mDoTitleConvert=true, $mDoContentConvert=true; |
815 | | - var $ruleDisplay = '',$ruleTitle=false; |
816 | | - var $rules = '';// string $rule the text of the rule |
817 | | - var $flags = array(); |
818 | | - var $bidtable = array();// array of the translation in each variant |
819 | | - var $unidtable = array();// array of the translation in each variant |
| 772 | + var $mConverter; // LanguageConverter object |
| 773 | + var $mManualCodeError='<strong class="error">code error!</strong>'; |
| 774 | + var $mRuleDisplay = '',$mRuleTitle=false; |
| 775 | + var $mRules = '';// string : the text of the rules |
| 776 | + var $mRulesAction = 'none'; |
| 777 | + var $mFlags = array(); |
| 778 | + var $mConvTable = array(); |
| 779 | + var $mBidtable = array();// array of the translation in each variant |
| 780 | + var $mUnidtable = array();// array of the translation in each variant |
820 | 781 | |
821 | 782 | /** |
822 | 783 | * Constructor |
823 | 784 | * |
824 | 785 | * @param string $text the text between -{ and }- |
825 | | - * @param array $markup the supported markup for conversion |
826 | | - * @param array $flags the supported flags for conversion |
827 | | - * @param array $variantNames the names list of supported language |
828 | | - * @param bool $doTitleConvert if do title convert |
829 | | - * @param bool $doContentConvert if do content convert |
| 786 | + * @param object $converter a LanguageConverter object |
830 | 787 | * @access public |
831 | 788 | */ |
832 | | - function __construct($text,$markup,$flags,$variantNames, |
833 | | - $doTitleConvert=true, $doContentConvert=true){ |
| 789 | + function __construct($text,$converter){ |
834 | 790 | $this->mText = $text; |
835 | | - $this->mMarkup = $markup; |
836 | | - $this->mFlags = $flags; |
837 | | - $this->mVariantNames = $variantNames; |
838 | | - $this->mDoTitleConvert=$doTitleConvert; |
839 | | - $this->mDoContentConvert=$doContentConvert; |
| 791 | + $this->mConverter=$converter; |
| 792 | + foreach($converter->mVariants as $v){ |
| 793 | + $this->mConvTable[$v]=array(); |
| 794 | + } |
840 | 795 | } |
841 | 796 | |
842 | 797 | /** |
— | — | @@ -849,13 +804,13 @@ |
850 | 805 | if(is_string($variants)){ $variants=array($variants); } |
851 | 806 | if(!is_array($variants)) return false; |
852 | 807 | foreach ($variants as $variant){ |
853 | | - if(array_key_exists($variant, $this->bidtable)){ |
854 | | - return $this->bidtable[$variant]; |
| 808 | + if(array_key_exists($variant, $this->mBidtable)){ |
| 809 | + return $this->mBidtable[$variant]; |
855 | 810 | } |
856 | 811 | } |
857 | 812 | return false; |
858 | 813 | } |
859 | | - |
| 814 | + |
860 | 815 | /** |
861 | 816 | * Parse flags with syntax -{FLAG| ... }- |
862 | 817 | * @private |
— | — | @@ -863,21 +818,23 @@ |
864 | 819 | function parseFlags(){ |
865 | 820 | $text = $this->mText; |
866 | 821 | if(strlen($text) < 2 ) { |
867 | | - $this->flags = array( 'R' ); |
868 | | - $this->rules = $text; |
| 822 | + $this->mFlags = array( 'R' ); |
| 823 | + $this->mRules = $text; |
869 | 824 | return; |
870 | 825 | } |
871 | 826 | |
872 | 827 | $flags = array(); |
873 | | - $tt = explode($this->mMarkup['flagsep'], $text, 2); |
| 828 | + $markup = $this->mConverter->mMarkup; |
| 829 | + $validFlags = $this->mConverter->mFlags; |
874 | 830 | |
| 831 | + $tt = explode($markup['flagsep'], $text, 2); |
875 | 832 | if(count($tt) == 2) { |
876 | | - $f = explode($this->mMarkup['varsep'], $tt[0]); |
| 833 | + $f = explode($markup['varsep'], $tt[0]); |
877 | 834 | foreach($f as $ff) { |
878 | 835 | $ff = trim($ff); |
879 | | - if(array_key_exists($ff, $this->mFlags) && |
880 | | - !in_array($this->mFlags[$ff], $flags)) |
881 | | - $flags[] = $this->mFlags[$ff]; |
| 836 | + if(array_key_exists($ff, $validFlags) && |
| 837 | + !in_array($validFlags[$ff], $flags)) |
| 838 | + $flags[] = $validFlags[$ff]; |
882 | 839 | } |
883 | 840 | $rules = $tt[1]; |
884 | 841 | } else { |
— | — | @@ -917,27 +874,29 @@ |
918 | 875 | } |
919 | 876 | if ( count($flags)==0 ) |
920 | 877 | $flags = array('S'); |
921 | | - $this->rules=$rules; |
922 | | - $this->flags=$flags; |
| 878 | + $this->mRules=$rules; |
| 879 | + $this->mFlags=$flags; |
923 | 880 | } |
924 | 881 | |
925 | 882 | /** |
926 | 883 | * generate conversion table |
927 | 884 | * @private |
928 | 885 | */ |
929 | | - function generateConvTable() { |
930 | | - $rules = $this->rules; |
931 | | - $flags = $this->flags; |
| 886 | + function parseRules() { |
| 887 | + $rules = $this->mRules; |
| 888 | + $flags = $this->mFlags; |
932 | 889 | $bidtable = array(); |
933 | 890 | $unidtable = array(); |
934 | | - $choice = explode($this->mMarkup['varsep'], $rules ); |
| 891 | + $markup = $this->mConverter->mMarkup; |
| 892 | + |
| 893 | + $choice = explode($markup['varsep'], $rules ); |
935 | 894 | foreach($choice as $c) { |
936 | | - $v = explode($this->mMarkup['codesep'], $c); |
| 895 | + $v = explode($markup['codesep'], $c); |
937 | 896 | if(count($v) != 2) |
938 | 897 | continue;// syntax error, skip |
939 | 898 | $to=trim($v[1]); |
940 | 899 | $v=trim($v[0]); |
941 | | - $u = explode($this->mMarkup['unidsep'], $v); |
| 900 | + $u = explode($markup['unidsep'], $v); |
942 | 901 | if(count($u) == 1) { |
943 | 902 | $bidtable[$v] = $to; |
944 | 903 | } else if(count($u) == 2){ |
— | — | @@ -948,23 +907,28 @@ |
949 | 908 | $unidtable[$v][$from]=$to; |
950 | 909 | } |
951 | 910 | // syntax error, pass |
952 | | - if (!array_key_exists($v,$this->mVariantNames)) |
953 | | - return; |
| 911 | + if (!array_key_exists($v,$this->mConverter->mVariantNames)){ |
| 912 | + $bidtable = array(); |
| 913 | + $unidtable = array(); |
| 914 | + break; |
| 915 | + } |
954 | 916 | } |
955 | | - $this->bidtable = $bidtable; |
956 | | - $this->unidtable = $unidtable; |
| 917 | + $this->mBidtable = $bidtable; |
| 918 | + $this->mUnidtable = $unidtable; |
957 | 919 | } |
958 | 920 | |
959 | 921 | /** |
960 | 922 | * @private |
961 | 923 | */ |
962 | 924 | function getRulesDesc(){ |
| 925 | + $codesep = $this->mConverter->mDescCodeSep; |
| 926 | + $varsep = $this->mConverter->mDescVarSep; |
963 | 927 | $text=''; |
964 | | - foreach($this->bidtable as $k => $v) |
965 | | - $text .= $this->mVariantNames[$k].':'.$v.';'; |
966 | | - foreach($this->unidtable as $k => $a) |
| 928 | + foreach($this->mBidtable as $k => $v) |
| 929 | + $text .= $this->mConverter->mVariantNames[$k]."$codesep$v$varsep"; |
| 930 | + foreach($this->mUnidtable as $k => $a) |
967 | 931 | foreach($a as $from=>$to) |
968 | | - $text.=$from.'⇒'.$this->mVariantNames[$k].':'.$to.';'; |
| 932 | + $text.=$from.'⇒'.$this->mConverter->mVariantNames[$k]."$codesep$to$varsep"; |
969 | 933 | return $text; |
970 | 934 | } |
971 | 935 | |
— | — | @@ -972,26 +936,26 @@ |
973 | 937 | * Parse rules conversion |
974 | 938 | * @private |
975 | 939 | */ |
976 | | - function getRuleConvertedStr($variant,$variantFallbacks, |
977 | | - $doConvert,$isMCDisable=false){ |
978 | | - $bidtable = $this->bidtable; |
979 | | - $unidtable = $this->unidtable; |
| 940 | + function getRuleConvertedStr($variant,$doConvert){ |
| 941 | + $bidtable = $this->mBidtable; |
| 942 | + $unidtable = $this->mUnidtable; |
980 | 943 | |
981 | 944 | if( count($bidtable) + count($unidtable) == 0 ){ |
982 | | - return $this->rules; |
| 945 | + return $this->mRules; |
983 | 946 | } elseif ($doConvert){// the text converted |
984 | 947 | // display current variant in bidirectional array |
985 | 948 | $disp = $this->getTextInBidtable($variant); |
986 | 949 | // or display current variant in fallbacks |
987 | 950 | if(!$disp) |
988 | | - $disp = $this->getTextInBidtable($variantFallbacks); |
| 951 | + $disp = $this->getTextInBidtable( |
| 952 | + $this->mConverter->getVariantFallbacks($variant)); |
989 | 953 | // or display current variant in unidirectional array |
990 | 954 | if(!$disp && array_key_exists($variant,$unidtable)){ |
991 | 955 | $disp = array_values($unidtable[$variant]); |
992 | 956 | $disp = $disp[0]; |
993 | 957 | } |
994 | 958 | // or display frist text under disable manual convert |
995 | | - if(!$disp && $isMCDisable) { |
| 959 | + if(!$disp && $this->mConverter->mManualLevel[$variant]=='disable') { |
996 | 960 | if(count($bidtable)>0){ |
997 | 961 | $disp = array_values($bidtable); |
998 | 962 | $disp = $disp[0]; |
— | — | @@ -1003,61 +967,126 @@ |
1004 | 968 | } |
1005 | 969 | return $disp; |
1006 | 970 | } else {// no convert |
1007 | | - return $this->rules; |
| 971 | + return $this->mRules; |
1008 | 972 | } |
1009 | 973 | } |
1010 | 974 | |
1011 | 975 | /** |
| 976 | + * generate conversion table for all text |
| 977 | + * @private |
| 978 | + */ |
| 979 | + function generateConvTable(){ |
| 980 | + //$rules = $this->mRules; |
| 981 | + $flags = $this->mFlags; |
| 982 | + $bidtable = $this->mBidtable; |
| 983 | + $unidtable = $this->mUnidtable; |
| 984 | + $manLevel = $this->mConverter->mManualLevel; |
| 985 | + |
| 986 | + $vmarked=array(); |
| 987 | + foreach($this->mConverter->mVariants as $v) { |
| 988 | + /* for bidirectional array |
| 989 | + fill in the missing variants, if any, |
| 990 | + with fallbacks */ |
| 991 | + if(!array_key_exists($v, $bidtable)) { |
| 992 | + $variantFallbacks = $this->mConverter->getVariantFallbacks($v); |
| 993 | + $vf = $this->getTextInBidtable($variantFallbacks); |
| 994 | + if($vf) $bidtable[$v] = $vf; |
| 995 | + } |
| 996 | + |
| 997 | + if(array_key_exists($v,$bidtable)){ |
| 998 | + foreach($vmarked as $vo){ |
| 999 | + // use syntax: -{A|zh:WordZh;zh-tw:WordTw}- |
| 1000 | + // or -{H|zh:WordZh;zh-tw:WordTw}- or -{-|zh:WordZh;zh-tw:WordTw}- |
| 1001 | + // to introduce a custom mapping between |
| 1002 | + // words WordZh and WordTw in the whole text |
| 1003 | + if($manLevel[$v]=='bidirectional'){ |
| 1004 | + $this->mConvTable[$v][$bidtable[$vo]]=$bidtable[$v]; |
| 1005 | + } |
| 1006 | + if($manLevel[$vo]=='bidirectional'){ |
| 1007 | + $this->mConvTable[$vo][$bidtable[$v]]=$bidtable[$vo]; |
| 1008 | + } |
| 1009 | + } |
| 1010 | + $vmarked[]=$v; |
| 1011 | + } |
| 1012 | + /*for unidirectional array |
| 1013 | + fill to convert tables */ |
| 1014 | + $allow_unid = $manLevel[$v]=='bidirectional' |
| 1015 | + || $manLevel[$v]=='unidirectional'; |
| 1016 | + if($allow_unid && array_key_exists($v,$unidtable)){ |
| 1017 | + $ct=$this->mConvTable[$v]; |
| 1018 | + $this->mConvTable[$v] = array_merge($ct,$unidtable[$v]); |
| 1019 | + } |
| 1020 | + } |
| 1021 | + } |
| 1022 | + |
| 1023 | + /** |
1012 | 1024 | * Parse rules and flags |
1013 | 1025 | * @public |
1014 | 1026 | */ |
1015 | | - function parse($variant,$variantFallbacks,$isMCDisable=false){ |
| 1027 | + function parse($variant){ |
| 1028 | + if(!$variant) $variant = $this->mConverter->getPreferredVariant(); |
| 1029 | + |
1016 | 1030 | $this->parseFlags(); |
1017 | | - $this->generateConvTable(); |
| 1031 | + $this->parseRules(); |
1018 | 1032 | |
1019 | | - $rules = $this->rules; |
1020 | | - $flags = $this->flags; |
| 1033 | + $rules = $this->mRules; |
| 1034 | + $flags = $this->mFlags; |
1021 | 1035 | |
1022 | | - if(count($this->bidtable)==0 && count($this->unidtable)==0 |
1023 | | - && !in_array('N',$flags) && !in_array('T',$flags) ) |
1024 | | - { |
1025 | | - $this->flags = $flags = array('R'); |
| 1036 | + if(count($this->mBidtable)==0 && count($this->mUnidtable)==0){ |
| 1037 | + if(in_array('+',$flags) || in_array('-',$flags)) |
| 1038 | + // fill all variants if text in -{A/H/-|text} without rules |
| 1039 | + foreach($this->mConverter->mVariants as $v) |
| 1040 | + $this->mBidtable[$v] = $rules; |
| 1041 | + elseif (!in_array('N',$flags) && !in_array('T',$flags) ) |
| 1042 | + $this->mFlags = $flags = array('R'); |
1026 | 1043 | } |
1027 | 1044 | |
1028 | 1045 | if( in_array('R',$flags) ) { |
1029 | 1046 | // if we don't do content convert, still strip the -{}- tags |
1030 | | - $this->ruleDisplay = $rules; |
| 1047 | + $this->mRuleDisplay = $rules; |
1031 | 1048 | } elseif ( in_array('N',$flags) ){ |
1032 | 1049 | // proces N flag: output current variant name |
1033 | | - $this->ruleDisplay = $this->mVariantNames[trim($rules)]; |
| 1050 | + $this->mRuleDisplay = $this->mConverter->mVariantNames[trim($rules)]; |
1034 | 1051 | } elseif ( in_array('D',$flags) ){ |
1035 | 1052 | // proces D flag: output rules description |
1036 | | - $this->ruleDisplay = $this->getRulesDesc(); |
| 1053 | + $this->mRuleDisplay = $this->getRulesDesc(); |
1037 | 1054 | } elseif ( in_array('H',$flags) || in_array('-',$flags) ) { |
1038 | 1055 | // proces H,- flag or T only: output nothing |
1039 | | - $this->ruleDisplay = ''; |
| 1056 | + $this->mRuleDisplay = ''; |
1040 | 1057 | } elseif ( in_array('S',$flags) ){ |
1041 | | - $this->ruleDisplay = $this->getRuleConvertedStr( |
1042 | | - $variant,$variantFallbacks, |
1043 | | - $this->mDoContentConvert,$isMCDisable); |
| 1058 | + $this->mRuleDisplay = $this->getRuleConvertedStr($variant, |
| 1059 | + $this->mConverter->mDoContentConvert); |
1044 | 1060 | } else { |
1045 | | - $this->ruleDisplay= $this->mManualCodeError; |
| 1061 | + $this->mRuleDisplay= $this->mManualCodeError; |
1046 | 1062 | } |
1047 | 1063 | // proces T flag : output nothing |
1048 | 1064 | if ( in_array('T',$flags) ) { |
1049 | | - $this->ruleTitle = $this->getRuleConvertedStr( |
1050 | | - $variant,$variantFallbacks, |
1051 | | - $this->mDoTitleConvert,$isMCDisable); |
| 1065 | + $this->mRuleTitle = $this->getRuleConvertedStr($variant, |
| 1066 | + $this->mConverter->mDoTitleConvert); |
1052 | 1067 | } |
| 1068 | + |
| 1069 | + if (in_array('-', $flags)) |
| 1070 | + $this->mRulesAction='remove'; |
| 1071 | + if (in_array('+', $flags)) |
| 1072 | + $this->mRulesAction='add'; |
| 1073 | + |
| 1074 | + $this->generateConvTable(); |
1053 | 1075 | } |
1054 | 1076 | |
1055 | 1077 | /** |
| 1078 | + * @public |
| 1079 | + */ |
| 1080 | + function hasRules(){ |
| 1081 | + // TODO: |
| 1082 | + } |
| 1083 | + |
| 1084 | + /** |
1056 | 1085 | * get display text on markup -{...}- |
1057 | 1086 | * @param string $variant the current variant |
1058 | 1087 | * @public |
1059 | 1088 | */ |
1060 | 1089 | function getDisplay(){ |
1061 | | - return $this->ruleDisplay; |
| 1090 | + return $this->mRuleDisplay; |
1062 | 1091 | } |
1063 | 1092 | /** |
1064 | 1093 | * get converted title |
— | — | @@ -1065,15 +1094,23 @@ |
1066 | 1095 | * @public |
1067 | 1096 | */ |
1068 | 1097 | function getTitle(){ |
1069 | | - return $this->ruleTitle; |
| 1098 | + return $this->mRuleTitle; |
1070 | 1099 | } |
1071 | 1100 | |
1072 | 1101 | /** |
| 1102 | + * return how deal with conversion rules |
| 1103 | + * @public |
| 1104 | + */ |
| 1105 | + function getRulesAction(){ |
| 1106 | + return $this->mRulesAction; |
| 1107 | + } |
| 1108 | + |
| 1109 | + /** |
1073 | 1110 | * get conversion table ( bidirectional and unidirectional conversion table ) |
1074 | 1111 | * @public |
1075 | 1112 | */ |
1076 | 1113 | function getConvTable(){ |
1077 | | - return array($this->bidtable, $this->unidtable); |
| 1114 | + return $this->mConvTable; |
1078 | 1115 | } |
1079 | 1116 | |
1080 | 1117 | /** |
— | — | @@ -1081,7 +1118,7 @@ |
1082 | 1119 | * @public |
1083 | 1120 | */ |
1084 | 1121 | function getRules(){ |
1085 | | - return $this->rules; |
| 1122 | + return $this->mRules; |
1086 | 1123 | } |
1087 | 1124 | |
1088 | 1125 | /** |
— | — | @@ -1089,6 +1126,6 @@ |
1090 | 1127 | * @public |
1091 | 1128 | */ |
1092 | 1129 | function getFlags(){ |
1093 | | - return $this->flags; |
| 1130 | + return $this->mFlags; |
1094 | 1131 | } |
1095 | 1132 | } |