* in this case. Right now this is only used by zh.
*
* @param $variant String: the language code of the variant
- * @return String: The code of the fallback language or the
+ * @return String|array: The code of the fallback language or the
* main code if there is no fallback
*/
public function getVariantFallbacks( $variant ) {
// not memoized (i.e. there return value is not cached) since
// new information might appear during processing after this
// is first called.
- if ( $req = $this->validateVariant( $req ) ) {
+ if ( $this->validateVariant( $req ) ) {
return $req;
}
return $this->mMainLanguageCode;
$sourceBlob .= substr( $text, $startPos, $elementPos - $startPos ) . "\000";
// Advance to the next position
- $startPos = $elementPos + strlen( $element );
+ $startPos = $elementPos + strlen( $element );
// Translate any alt or title attributes inside the matched element
- if ( $element !== '' && preg_match( '/^(<[^>\s]*)\s([^>]*)(.*)$/', $element,
- $elementMatches ) )
+ if ( $element !== '' && preg_match( '/^(<[^>\s]*)\s([^>]*)(.*)$/', $element,
+ $elementMatches ) )
{
$attrs = Sanitizer::decodeTagAttributes( $elementMatches[2] );
$changed = false;
if ( !strpos( $attr, '://' ) ) {
$attr = $this->translate( $attr, $toVariant );
}
-
+
// Remove HTML tags to avoid disrupting the layout
$attr = preg_replace( '/<[^>]+>/', '', $attr );
if ( $attr !== $attrs[$attrName] ) {
}
}
if ( $changed ) {
- $element = $elementMatches[1] . Html::expandAttributes( $attrs ) .
+ $element = $elementMatches[1] . Html::expandAttributes( $attrs ) .
$elementMatches[3];
}
}
if ( isset( $this->mVariantFlags[$variant] ) ) {
// then convert <text to convert> to current language
$this->mRules = $this->mConverter->autoConvert( $this->mRules,
- $variant );
+ $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 ( isset( $this->mVariantFlags[$variantFallback] ) ) {
- // then convert <text to convert> to fallback language
- $this->mRules =
- $this->mConverter->autoConvert( $this->mRules,
- $variantFallback );
- break;
+ if( is_array( $variantFallbacks ) ) {
+ foreach ( $variantFallbacks as $variantFallback ) {
+ // if current variant's fallback exist in flags
+ if ( isset( $this->mVariantFlags[$variantFallback] ) ) {
+ // then convert <text to convert> to fallback language
+ $this->mRules =
+ $this->mConverter->autoConvert( $this->mRules,
+ $variantFallback );
+ break;
+ }
}
}
}