MediaWiki
REL1_19
|
00001 <?php 00006 /* 00007 * Conversion script between Latin and Syllabics for Inuktitut. 00008 * - Syllabics -> lowercase Latin 00009 * - lowercase/uppercase Latin -> Syllabics 00010 * 00011 * 00012 * Based on: 00013 * - http://commons.wikimedia.org/wiki/Image:Inuktitut.png 00014 * - LanguageSr.php 00015 * 00016 * @ingroup Language 00017 */ 00018 require_once( dirname( __FILE__ ) . '/../LanguageConverter.php' ); 00019 00023 class IuConverter extends LanguageConverter { 00024 00025 protected $mDoContentConvert; 00026 var $mToLatin = array( 00027 'ᐦ' => 'h', 'ᐃ' => 'i', 'ᐄ' => 'ii', 'ᐅ' => 'u', 'ᐆ' => 'uu', 'ᐊ' => 'a', 'ᐋ' => 'aa', 00028 'ᑉ' => 'p', 'ᐱ' => 'pi', 'ᐲ' => 'pii', 'ᐳ' => 'pu', 'ᐴ' => 'puu', 'ᐸ' => 'pa', 'ᐹ' => 'paa', 00029 'ᑦ' => 't', 'ᑎ' => 'ti', 'ᑏ' => 'tii', 'ᑐ' => 'tu', 'ᑑ' => 'tuu', 'ᑕ' => 'ta', 'ᑖ' => 'taa', 00030 'ᒃ' => 'k', 'ᑭ' => 'ki', 'ᑮ' => 'kii', 'ᑯ' => 'ku', 'ᑰ' => 'kuu', 'ᑲ' => 'ka', 'ᑳ' => 'kaa', 00031 'ᖅᒃ' => 'qq', 'ᖅᑭ' => 'qqi', 'ᖅᑮ' => 'qqii', 'ᖅᑯ' => 'qqu', 'ᖅᑰ' => 'ᖅqquu', 'ᖅᑲ' => 'qqa', 'ᖅᑳ' => 'qqaa', 00032 'ᒡ' => 'g', 'ᒋ' => 'gi', 'ᒌ' => 'gii', 'ᒍ' => 'gu', 'ᒎ' => 'guu', 'ᒐ' => 'ga', 'ᒑ' => 'gaa', 00033 'ᒻ' => 'm', 'ᒥ' => 'mi', 'ᒦ' => 'mii', 'ᒧ' => 'mu', 'ᒨ' => 'muu', 'ᒪ' => 'ma', 'ᒫ' => 'maa', 00034 'ᓐ' => 'n', 'ᓂ' => 'ni', 'ᓃ' => 'nii', 'ᓄ' => 'nu', 'ᓅ' => 'nuu', 'ᓇ' => 'na', 'ᓈ' => 'naa', 00035 'ᔅ' => 's', 'ᓯ' => 'si', 'ᓰ' => 'sii', 'ᓱ' => 'su', 'ᓲ' => 'suu', 'ᓴ' => 'sa', 'ᓵ' => 'saa', 00036 'ᓪ' => 'l', 'ᓕ' => 'li', 'ᓖ' => 'lii', 'ᓗ' => 'lu', 'ᓘ' => 'luu', 'ᓚ' => 'la', 'ᓛ' => 'laa', 00037 'ᔾ' => 'j', 'ᔨ' => 'ji', 'ᔩ' => 'jii', 'ᔪ' => 'ju', 'ᔫ' => 'juu', 'ᔭ' => 'ja', 'ᔮ' => 'jaa', 00038 'ᕝ' => 'v', 'ᕕ' => 'vi', 'ᕖ' => 'vii', 'ᕗ' => 'vu', 'ᕘ' => 'vuu', 'ᕙ' => 'va', 'ᕚ' => 'vaa', 00039 'ᕐ' => 'r', 'ᕆ' => 'ri', 'ᕇ' => 'rii', 'ᕈ' => 'ru', 'ᕉ' => 'ruu', 'ᕋ' => 'ra', 'ᕌ' => 'raa', 00040 'ᖅ' => 'q', 'ᕿ' => 'qi', 'ᖀ' => 'qii', 'ᖁ' => 'qu', 'ᖂ' => 'quu', 'ᖃ' => 'qa', 'ᖄ' => 'qaa', 00041 'ᖕ' => 'ng', 'ᖏ' => 'ngi', 'ᖐ' => 'ngii', 'ᖑ' => 'ngu', 'ᖒ' => 'nguu', 'ᖓ' => 'nga', 'ᖔ' => 'ngaa', 00042 'ᖖ' => 'nng', 'ᙱ' => 'nngi', 'ᙲ' => 'nngii', 'ᙳ' => 'nngu', 'ᙴ' => 'nnguu', 'ᙵ' => 'nnga', 'ᙶ' => 'nngaa', 00043 'ᖦ' => 'ɫ', 'ᖠ' => 'ɫi', 'ᖡ' => 'ɫii', 'ᖢ' => 'ɫu', 'ᖣ' => 'ɫuu', 'ᖤ' => 'ɫa', 'ᖥ' => 'ɫaa', 00044 ); 00045 00046 var $mUpperToLowerCaseLatin = array( 00047 'A' => 'a', 'B' => 'b', 'C' => 'c', 'D' => 'd', 'E' => 'e', 00048 'F' => 'f', 'G' => 'g', 'H' => 'h', 'I' => 'i', 'J' => 'j', 00049 'K' => 'k', 'L' => 'l', 'M' => 'm', 'N' => 'n', 'O' => 'o', 00050 'P' => 'p', 'Q' => 'q', 'R' => 'r', 'S' => 's', 'T' => 't', 00051 'U' => 'u', 'V' => 'v', 'W' => 'w', 'X' => 'x', 'Y' => 'y', 00052 'Z' => 'z', 00053 ); 00054 00055 var $mToSyllabics = array( 00056 'h' => 'ᐦ', 'i' => 'ᐃ', 'ii' => 'ᐄ', 'u' => 'ᐅ', 'uu' => 'ᐆ', 'a' => 'ᐊ', 'aa' => 'ᐋ', 00057 'p' => 'ᑉ', 'pi' => 'ᐱ', 'pii' => 'ᐲ', 'pu' => 'ᐳ', 'puu' => 'ᐴ', 'pa' => 'ᐸ', 'paa' => 'ᐹ', 00058 't' => 'ᑦ', 'ti' => 'ᑎ', 'tii' => 'ᑏ', 'tu' => 'ᑐ', 'tuu' => 'ᑑ', 'ta' => 'ᑕ', 'taa' => 'ᑖ', 00059 'k' => 'ᒃ', 'ki' => 'ᑭ', 'kii' => 'ᑮ', 'ku' => 'ᑯ', 'kuu' => 'ᑰ', 'ka' => 'ᑲ', 'kaa' => 'ᑳ', 00060 'g' => 'ᒡ', 'gi' => 'ᒋ', 'gii' => 'ᒌ', 'gu' => 'ᒍ', 'guu' => 'ᒎ', 'ga' => 'ᒐ', 'gaa' => 'ᒑ', 00061 'm' => 'ᒻ', 'mi' => 'ᒥ', 'mii' => 'ᒦ', 'mu' => 'ᒧ', 'muu' => 'ᒨ', 'ma' => 'ᒪ', 'maa' => 'ᒫ', 00062 'n' => 'ᓐ', 'ni' => 'ᓂ', 'nii' => 'ᓃ', 'nu' => 'ᓄ', 'nuu' => 'ᓅ', 'na' => 'ᓇ', 'naa' => 'ᓈ', 00063 's' => 'ᔅ', 'si' => 'ᓯ', 'sii' => 'ᓰ', 'su' => 'ᓱ', 'suu' => 'ᓲ', 'sa' => 'ᓴ', 'saa' => 'ᓵ', 00064 'l' => 'ᓪ', 'li' => 'ᓕ', 'lii' => 'ᓖ', 'lu' => 'ᓗ', 'luu' => 'ᓘ', 'la' => 'ᓚ', 'laa' => 'ᓛ', 00065 'j' => 'ᔾ', 'ji' => 'ᔨ', 'jii' => 'ᔩ', 'ju' => 'ᔪ', 'juu' => 'ᔫ', 'ja' => 'ᔭ', 'jaa' => 'ᔮ', 00066 'v' => 'ᕝ', 'vi' => 'ᕕ', 'vii' => 'ᕖ', 'vu' => 'ᕗ', 'vuu' => 'ᕘ', 'va' => 'ᕙ', 'vaa' => 'ᕚ', 00067 'r' => 'ᕐ', 'ri' => 'ᕆ', 'rii' => 'ᕇ', 'ru' => 'ᕈ', 'ruu' => 'ᕉ', 'ra' => 'ᕋ', 'raa' => 'ᕌ', 00068 'qq' => 'ᖅᒃ', 'qqi' => 'ᖅᑭ', 'qqii' => 'ᖅᑮ', 'qqu' => 'ᖅᑯ', 'qquu' => 'ᖅᑰ', 'qqa' => 'ᖅᑲ', 'qqaa' => 'ᖅᑳ', 00069 'q' => 'ᖅ', 'qi' => 'ᕿ', 'qii' => 'ᖀ', 'qu' => 'ᖁ', 'quu' => 'ᖂ', 'qa' => 'ᖃ', 'qaa' => 'ᖄ', 00070 'ng' => 'ᖕ', 'ngi' => 'ᖏ', 'ngii' => 'ᖐ', 'ngu' => 'ᖑ', 'nguu' => 'ᖒ', 'nga' => 'ᖓ', 'ngaa' => 'ᖔ', 00071 'nng' => 'ᖖ', 'nngi' => 'ᙱ', 'nngii' => 'ᙲ', 'nngu' => 'ᙳ', 'nnguu' => 'ᙴ', 'nnga' => 'ᙵ', 'nngaa' => 'ᙶ', 00072 'ɫ' => 'ᖦ', 'ɫi' => 'ᖠ', 'ɫii' => 'ᖡ', 'ɫu' => 'ᖢ', 'ɫuu' => 'ᖣ', 'ɫa' => 'ᖤ', 'ɫaa' => 'ᖥ', 00073 ); 00074 00075 function loadDefaultTables() { 00076 $this->mTables = array( 00077 'lowercase' => new ReplacementArray( $this->mUpperToLowerCaseLatin ), 00078 'ike-cans' => new ReplacementArray( $this->mToSyllabics ), 00079 'ike-latn' => new ReplacementArray( $this->mToLatin ), 00080 'iu' => new ReplacementArray() 00081 ); 00082 } 00083 00094 function parseManualRule( $rule, $flags = array() ) { 00095 if ( in_array( 'T', $flags ) ) { 00096 return parent::parseManualRule( $rule, $flags ); 00097 } 00098 00099 $carray = array(); 00100 // otherwise ignore all formatting 00101 foreach ( $this->mVariants as $v ) { 00102 $carray[$v] = $rule; 00103 } 00104 00105 return $carray; 00106 } 00107 00115 function parserConvert( $text, &$parser ) { 00116 $this->mDoContentConvert = !( is_object( $parser->getTitle() ) && $parser->getTitle()->isTalkPage() ); 00117 00118 return parent::parserConvert( $text, $parser ); 00119 } 00120 00131 function findVariantLink( &$link, &$nt, $ignoreOtherCond = false ) { 00132 // check for user namespace 00133 if ( is_object( $nt ) ) { 00134 $ns = $nt->getNamespace(); 00135 if ( $ns == NS_USER || $ns == NS_USER_TALK ) 00136 return; 00137 } 00138 00139 $oldlink = $link; 00140 parent::findVariantLink( $link, $nt, $ignoreOtherCond ); 00141 if ( $this->getPreferredVariant() == $this->mMainLanguageCode ) 00142 $link = $oldlink; 00143 } 00144 00154 function markNoConversion( $text, $noParse = false ) { 00155 if ( $noParse || preg_match( "/^https?:\/\/|ftp:\/\/|irc:\/\//", $text ) ) 00156 return parent::markNoConversion( $text ); 00157 return $text; 00158 } 00159 00169 function autoConvert( $text, $toVariant = false ) { 00170 global $wgTitle; 00171 if ( is_object( $wgTitle ) && $wgTitle->getNameSpace() == NS_FILE ) { 00172 $imagename = $wgTitle->getNsText(); 00173 if ( preg_match( "/^$imagename:/", $text ) ) return $text; 00174 } 00175 return parent::autoConvert( $text, $toVariant ); 00176 } 00177 00186 function translate( $text, $toVariant ) { 00187 // If $text is empty or only includes spaces, do nothing 00188 // Otherwise translate it 00189 if ( trim( $text ) ) { 00190 $this->loadTables(); 00191 // To syllabics, first translate uppercase to lowercase Latin 00192 if($toVariant == 'ike-cans') { 00193 $text = $this->mTables['lowercase']->replace( $text ); 00194 } 00195 $text = $this->mTables[$toVariant]->replace( $text ); 00196 } 00197 return $text; 00198 } 00199 } 00200 00206 class LanguageIu extends Language { 00207 function __construct() { 00208 global $wgHooks; 00209 00210 parent::__construct(); 00211 00212 $variants = array( 'iu', 'ike-cans', 'ike-latn' ); 00213 $variantfallbacks = array( 00214 'iu' => 'ike-cans', 00215 'ike-cans' => 'iu', 00216 'ike-latn' => 'iu', 00217 ); 00218 00219 $flags = array(); 00220 $this->mConverter = new IuConverter( $this, 'iu', $variants, $variantfallbacks, $flags ); 00221 $wgHooks['ArticleSaveComplete'][] = $this->mConverter; 00222 } 00223 }