r48040 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r48039‎ | r48040 | r48041 >
Date:02:23, 5 March 2009
Author:philip
Status:ok
Tags:
Comment:
More code comments in LanguageConverter.php.
Modified paths:
  • /trunk/phase3/languages/LanguageConverter.php (modified) (history)

Diff [purge]

Index: trunk/phase3/languages/LanguageConverter.php
@@ -976,6 +976,8 @@
977977 $flags=array_diff($flags,array('S'));
978978 $flags_temp = array();
979979 foreach ($variants as $variant) {
 980+ // try to find flags like "zh-hans", "zh-hant"
 981+ // allow syntaxes like "-{zh-hans;zh-hant|XXXX}-"
980982 if ( in_array($variant, $flags) )
981983 $flags_temp[] = $variant;
982984 }
@@ -1000,6 +1002,16 @@
10011003 $markup = $this->mConverter->mMarkup;
10021004 $variants = $this->mConverter->mVariants;
10031005
 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+ // )
10041016 $varsep_pattern = '/' . $markup['varsep'] . '\s*' . '(?=';
10051017 foreach( $variants as $variant )
10061018 $varsep_pattern .= $variant . '\s*' . $markup['codesep'] . '|';
@@ -1013,6 +1025,7 @@
10141026 $to = trim($v[1]);
10151027 $v = trim($v[0]);
10161028 $u = explode($markup['unidsep'], $v);
 1029+ // if $to is empty, strtr() could return a wrong result
10171030 if( count($u) == 1 && $to && in_array( $v, $variants ) ) {
10181031 $bidtable[$v] = $to;
10191032 } else if(count($u) == 2){
@@ -1148,14 +1161,19 @@
11491162 $this->parseFlags();
11501163 $flags = $this->mFlags;
11511164
1152 - //convert to specified variant
 1165+ // convert to specified variant
 1166+ // syntax: -{zh-hans;zh-hant[;...]|<text to convert>}-
11531167 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
11551170 $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.
11571173 $variantFallbacks = $this->mConverter->getVariantFallbacks($variant);
11581174 foreach ( $variantFallbacks as $variantFallback ) {
 1175+ // if current variant's fallback exist in flags
11591176 if ( in_array( $variantFallback, $flags ) ) {
 1177+ // then convert <text to convert> to fallback language
11601178 $this->mRules = $this->mConverter->autoConvert( $this->mRules, $variantFallback );
11611179 break;
11621180 }

Status & tagging log