A new optional param for LanguageConverter::convert(), to enable a new function named...
authorPhilip Tzou <philip@users.mediawiki.org>
Sat, 11 Apr 2009 10:56:09 +0000 (10:56 +0000)
committerPhilip Tzou <philip@users.mediawiki.org>
Sat, 11 Apr 2009 10:56:09 +0000 (10:56 +0000)
languages/Language.php
languages/LanguageConverter.php

index d629c48..cf4949c 100644 (file)
@@ -35,7 +35,7 @@ if( function_exists( 'mb_strtoupper' ) ) {
 class FakeConverter {
        var $mLang;
        function FakeConverter($langobj) {$this->mLang = $langobj;}
-       function convert($t, $i) {return $t;}
+       function convert($t, $i, $v) {return $t;}
        function parserConvert($t, $p) {return $t;}
        function getVariants() { return array( $this->mLang->getCode() ); }
        function getPreferredVariant() {return $this->mLang->getCode(); }
@@ -2183,8 +2183,8 @@ class Language {
        }
 
        # convert text to different variants of a language.
-       function convert( $text, $isTitle = false) {
-               return $this->mConverter->convert($text, $isTitle);
+       function convert( $text, $isTitle = false, $variant = none) {
+               return $this->mConverter->convert($text, $isTitle, $variant);
        }
 
        # Convert text from within Parser
index 0255d66..5b48ef9 100644 (file)
@@ -487,10 +487,11 @@ class LanguageConverter {
         *
         * @param string $text text to be converted
         * @param bool $isTitle whether this conversion is for the article title
+        * @param string $variant the variant we convert to
         * @return string converted text
         * @public
         */
-       function convert( $text, $isTitle = false ) {
+       function convert( $text, $isTitle = false, $variant = none ) {
 
                $mw =& MagicWord::get( 'notitleconvert' );
                if( $mw->matchAndRemove( $text ) )
@@ -505,7 +506,10 @@ class LanguageConverter {
                if( $mw->matchStart( $text ) )
                        return $text;
 
-               $plang = $this->getPreferredVariant();
+               if( $variant && in_array( $variant, $this->mVariants ) )
+                       $plang = $variant;
+               else
+                       $plang = $this->getPreferredVariant();
 
                // for title convertion
                if ( $isTitle ) return $this->convertTitle( $text, $plang );