MediaWiki
REL1_19
|
00001 <?php 00006 /* 00007 * Conversion script between Latin and Tifinagh for Tachelhit. 00008 * - Tifinagh -> lowercase Latin 00009 * - lowercase/uppercase Latin -> Tifinagh 00010 * 00011 * 00012 * Based on: 00013 * - http://en.wikipedia.org/wiki/Shilha_language 00014 * - LanguageSr.php 00015 * 00016 * @ingroup Language 00017 */ 00018 require_once( dirname( __FILE__ ) . '/../LanguageConverter.php' ); 00019 00023 class ShiConverter extends LanguageConverter { 00024 00025 protected $mDoContentConvert; 00026 00027 var $mToLatin = array( 00028 'ⴰ' => 'a', 'ⴱ' => 'b', 'ⴳ' => 'g', 'ⴷ' => 'd', 'ⴹ' => 'ḍ', 'ⴻ' => 'e', 00029 'ⴼ' => 'f', 'ⴽ' => 'k', 'ⵀ' => 'h', 'ⵃ' => 'ḥ', 'ⵄ' => 'ε', 'ⵅ' => 'x', 00030 'ⵇ' => 'q', 'ⵉ' => 'i', 'ⵊ' => 'j', 'ⵍ' => 'l', 'ⵎ' => 'm', 'ⵏ' => 'n', 00031 'ⵓ' => 'u', 'ⵔ' => 'r', 'ⵕ' => 'ṛ', 'ⵖ' => 'γ', 'ⵙ' => 's', 'ⵚ' => 'ṣ', 00032 'ⵛ' => 'š', 'ⵜ' => 't', 'ⵟ' => 'ṭ', 'ⵡ' => 'w', 'ⵢ' => 'y', 'ⵣ' => 'z', 00033 'ⵥ' => 'ẓ', 'ⵯ' => 'ʷ', 'ⵖ' => 'ɣ', 'ⵠ' => 'v', 'ⵒ' => 'p', 00034 ); 00035 00036 var $mUpperToLowerCaseLatin = array( 00037 'A' => 'a', 'B' => 'b', 'C' => 'c', 'D' => 'd', 'E' => 'e', 00038 'F' => 'f', 'G' => 'g', 'H' => 'h', 'I' => 'i', 'J' => 'j', 00039 'K' => 'k', 'L' => 'l', 'M' => 'm', 'N' => 'n', 'O' => 'o', 00040 'P' => 'p', 'Q' => 'q', 'R' => 'r', 'S' => 's', 'T' => 't', 00041 'U' => 'u', 'V' => 'v', 'W' => 'w', 'X' => 'x', 'Y' => 'y', 00042 'Z' => 'z', 'Ɣ' => 'ɣ', 00043 ); 00044 00045 var $mToTifinagh = array( 00046 'a' => 'ⴰ', 'b' => 'ⴱ', 'g' => 'ⴳ', 'd' => 'ⴷ', 'ḍ' => 'ⴹ', 'e' => 'ⴻ', 00047 'f' => 'ⴼ', 'k' => 'ⴽ', 'h' => 'ⵀ', 'ḥ' => 'ⵃ', 'ε' => 'ⵄ', 'x' => 'ⵅ', 00048 'q' => 'ⵇ', 'i' => 'ⵉ', 'j' => 'ⵊ', 'l' => 'ⵍ', 'm' => 'ⵎ', 'n' => 'ⵏ', 00049 'u' => 'ⵓ', 'r' => 'ⵔ', 'ṛ' => 'ⵕ', 'γ' => 'ⵖ', 's' => 'ⵙ', 'ṣ' => 'ⵚ', 00050 'š' => 'ⵛ', 't' => 'ⵜ', 'ṭ' => 'ⵟ', 'w' => 'ⵡ', 'y' => 'ⵢ', 'z' => 'ⵣ', 00051 'ẓ' => 'ⵥ', 'ʷ' => 'ⵯ', 'ɣ' => 'ⵖ', 'v' => 'ⵠ', 'p' => 'ⵒ', 00052 ); 00053 00054 function loadDefaultTables() { 00055 $this->mTables = array( 00056 'lowercase' => new ReplacementArray( $this->mUpperToLowerCaseLatin ), 00057 'shi-tfng' => new ReplacementArray( $this->mToTifinagh ), 00058 'shi-latn' => new ReplacementArray( $this->mToLatin ), 00059 'shi' => new ReplacementArray() 00060 ); 00061 } 00062 00073 function parseManualRule( $rule, $flags = array() ) { 00074 if ( in_array( 'T', $flags ) ) { 00075 return parent::parseManualRule( $rule, $flags ); 00076 } 00077 00078 $carray = array(); 00079 // otherwise ignore all formatting 00080 foreach ( $this->mVariants as $v ) { 00081 $carray[$v] = $rule; 00082 } 00083 00084 return $carray; 00085 } 00086 00094 function parserConvert( $text, &$parser ) { 00095 $this->mDoContentConvert = !( is_object( $parser->getTitle() ) && $parser->getTitle()->isTalkPage() ); 00096 00097 return parent::parserConvert( $text, $parser ); 00098 } 00099 00110 function findVariantLink( &$link, &$nt, $ignoreOtherCond = false ) { 00111 // check for user namespace 00112 if ( is_object( $nt ) ) { 00113 $ns = $nt->getNamespace(); 00114 if ( $ns == NS_USER || $ns == NS_USER_TALK ) 00115 return; 00116 } 00117 00118 $oldlink = $link; 00119 parent::findVariantLink( $link, $nt, $ignoreOtherCond ); 00120 if ( $this->getPreferredVariant() == $this->mMainLanguageCode ) 00121 $link = $oldlink; 00122 } 00123 00133 function markNoConversion( $text, $noParse = false ) { 00134 if ( $noParse || preg_match( "/^https?:\/\/|ftp:\/\/|irc:\/\//", $text ) ) 00135 return parent::markNoConversion( $text ); 00136 return $text; 00137 } 00138 00148 function autoConvert( $text, $toVariant = false ) { 00149 global $wgTitle; 00150 if ( is_object( $wgTitle ) && $wgTitle->getNameSpace() == NS_FILE ) { 00151 $imagename = $wgTitle->getNsText(); 00152 if ( preg_match( "/^$imagename:/", $text ) ) return $text; 00153 } 00154 return parent::autoConvert( $text, $toVariant ); 00155 } 00156 00165 function translate( $text, $toVariant ) { 00166 // If $text is empty or only includes spaces, do nothing 00167 // Otherwise translate it 00168 if ( trim( $text ) ) { 00169 $this->loadTables(); 00170 // To Tifinagh, first translate uppercase to lowercase Latin 00171 if( $toVariant == 'shi-tfng' ) { 00172 $text = $this->mTables['lowercase']->replace( $text ); 00173 } 00174 $text = $this->mTables[$toVariant]->replace( $text ); 00175 } 00176 return $text; 00177 } 00178 } 00179 00185 class LanguageShi extends Language { 00186 function __construct() { 00187 global $wgHooks; 00188 00189 parent::__construct(); 00190 00191 $variants = array( 'shi', 'shi-tfng', 'shi-latn' ); 00192 $variantfallbacks = array( 00193 'shi' => 'shi-tfng', 00194 'shi-tfng' => 'shi', 00195 'shi-latn' => 'shi', 00196 ); 00197 00198 $flags = array(); 00199 $this->mConverter = new ShiConverter( $this, 'shi', $variants, $variantfallbacks, $flags ); 00200 $wgHooks['ArticleSaveComplete'][] = $this->mConverter; 00201 } 00202 }