- if( !in_array('R',$flags) || !in_array('N',$flags) ){
- //FIXME: may cause trouble here...
- //strip since it interferes with the parsing, plus,
- //all spaces should be stripped in this tag anyway.
- $this->mRules = str_replace(' ', '', $this->mRules);
+ // convert to specified variant
+ // syntax: -{zh-hans;zh-hant[;...]|<text to convert>}-
+ if( count( array_diff( $flags, $variants ) ) == 0 and count( $flags ) != 0 ) {
+ if ( in_array( $variant, $flags ) ) // check if current variant in flags
+ // then convert <text to convert> to current language
+ $this->mRules = $this->mConverter->autoConvert( $this->mRules, $variant );
+ else { // if current variant no in flags,
+ // then we check its fallback variants.
+ $variantFallbacks = $this->mConverter->getVariantFallbacks($variant);
+ foreach ( $variantFallbacks as $variantFallback ) {
+ // if current variant's fallback exist in flags
+ if ( in_array( $variantFallback, $flags ) ) {
+ // then convert <text to convert> to fallback language
+ $this->mRules = $this->mConverter->autoConvert( $this->mRules, $variantFallback );
+ break;
+ }
+ }
+ }
+ $this->mFlags = $flags = array('R');
+ }
+
+ if( !in_array( 'R', $flags ) || !in_array( 'N', $flags ) ) {