+ // see if some supported language variant is set in the
+ // HTTP header.
+ $languages = array_keys( $wgRequest->getAcceptLang() );
+ if ( empty( $languages ) ) {
+ return null;
+ }
+
+ $fallbackLanguages = array();
+ foreach ( $languages as $language ) {
+ $this->mHeaderVariant = $this->validateVariant( $language );
+ if ( $this->mHeaderVariant ) {
+ break;
+ }
+
+ // To see if there are fallbacks of current language.
+ // We record these fallback variants, and process
+ // them later.
+ $fallbacks = $this->getVariantFallbacks( $language );
+ if ( is_string( $fallbacks ) ) {
+ $fallbackLanguages[] = $fallbacks;
+ } elseif ( is_array( $fallbacks ) ) {
+ $fallbackLanguages =
+ array_merge( $fallbackLanguages, $fallbacks );
+ }
+ }
+
+ if ( !$this->mHeaderVariant ) {
+ // process fallback languages now
+ $fallback_languages = array_unique( $fallbackLanguages );
+ foreach ( $fallback_languages as $language ) {
+ $this->mHeaderVariant = $this->validateVariant( $language );
+ if ( $this->mHeaderVariant ) {
+ break;
+ }
+ }
+ }
+
+ return $this->mHeaderVariant;
+ }
+
+ /**
+ * Dictionary-based conversion.
+ * This function would not parse the conversion rules.
+ * If you want to parse rules, try to use convert() or
+ * convertTo().
+ *
+ * @param $text String the text to be converted
+ * @param $toVariant bool|string the target language code
+ * @return String the converted text
+ */
+ public function autoConvert( $text, $toVariant = false ) {
+ wfProfileIn( __METHOD__ );