MediaWiki  REL1_22
LanguageKu.php
Go to the documentation of this file.
00001 <?php
00024 require_once __DIR__ . '/../LanguageConverter.php';
00025 require_once __DIR__ . '/LanguageKu_ku.php';
00026 
00032 class KuConverter extends LanguageConverter {
00033     public $mArabicToLatin = array(
00034         'ب' => 'b', 'ج' => 'c', 'چ' => 'ç', 'د' => 'd', 'ف' => 'f', 'گ' => 'g', 'ھ' => 'h',
00035         'ہ' => 'h', 'ه' => 'h', 'ح' => 'h', 'ژ' => 'j', 'ك' => 'k', 'ک' => 'k', 'ل' => 'l',
00036         'م' => 'm', 'ن' => 'n', 'پ' => 'p', 'ق' => 'q', 'ر' => 'r', 'س' => 's', 'ش' => 'ş',
00037         'ت' => 't', 'ڤ' => 'v', 'خ' => 'x', 'غ' => 'x', 'ز' => 'z',
00038 
00039 // ک و => ku -- ist richtig
00040 //  و ك=> ku -- ist auch richtig
00041 
00042         /* Doppel- und Halbvokale */
00043         'ڵ' => 'll', # ll
00044         'ڕ' => 'rr', # rr
00045         'ا' => 'a',
00046         # 'ئێ' => 'ê', # initial e
00047         'ە' => 'e',
00048         'ه‌' => 'e', # with one non-joiner
00049         'ه‌‌' => 'e', # with two non-joiner
00050         'ة' => 'e',
00051         'ێ' => 'ê',
00052         'ي' => 'î',
00053         'ی' => 'î', # U+06CC  db 8c  ARABIC LETTER FARSI YEH
00054         'ى' => 'î', # U+0649  d9 89  ARABIC LETTER ALEF MAKSURA
00055         'ۆ' => 'o',
00056         'و' => 'w',
00057         'ئ' => '', # initial hemze should not be shown
00058         '،' => ',',
00059         'ع' => '\'', # ayn
00060         '؟' => '?',
00061 
00062         # digits
00063         '٠' => '0', # &#x0660;
00064         '١' => '1', # &#x0661;
00065         '٢' => '2', # &#x0662;
00066         '٣' => '3', # &#x0663;
00067         '٤' => '4', # &#x0664;
00068         '٥' => '5', # &#x0665;
00069         '٦' => '6', # &#x0666;
00070         '٧' => '7', # &#x0667;
00071         '٨' => '8', # &#x0668;
00072         '٩' => '9', # &#x0669;
00073     );
00074 
00075     public $mLatinToArabic = array(
00076         'b' => 'ب', 'c' => 'ج', 'ç' => 'چ', 'd' => 'د', 'f' => 'ف', 'g' => 'گ',
00077         'h' => 'ه', 'j' => 'ژ', 'k' => 'ک', 'l' => 'ل',
00078         'm' => 'م', 'n' => 'ن', 'p' => 'پ', 'q' => 'ق', 'r' => 'ر', 's' => 'س', 'ş' => 'ش',
00079         't' => 'ت', 'v' => 'ڤ',
00080         'x' => 'خ', 'y' => 'ی', 'z' => 'ز',
00081 
00082         'B' => 'ب', 'C' => 'ج', 'Ç' => 'چ', 'D' => 'د', 'F' => 'ف', 'G' => 'گ', 'H' => 'ھ',
00083         'H' => 'ہ', 'H' => 'ه', 'H' => 'ح', 'J' => 'ژ', 'K' => 'ك', 'K' => 'ک', 'L' => 'ل',
00084         'M' => 'م', 'N' => 'ن', 'P' => 'پ', 'Q' => 'ق', 'R' => 'ر', 'S' => 'س', 'Ş' => 'ش',
00085         'T' => 'ت', 'V' => 'ڤ', 'W' => 'و', 'X' => 'خ',
00086         'Y' => 'ی', 'Z' => 'ز',
00087 
00088         /* Doppelkonsonanten */
00089         # 'll' => 'ڵ', # wenn es geht, doppel-l und l getrennt zu behandeln
00090         # 'rr' => 'ڕ', # selbiges für doppel-r
00091 
00092         /* Einzelne Großbuchstaben */
00093         // ' C' => 'ج',
00094 
00095         /* Vowels */
00096         'a' => 'ا',
00097         'e' => 'ە',
00098         'ê' => 'ێ',
00099         'i' => '',
00100         'î' => 'ی',
00101         'o' => 'ۆ',
00102         'u' => 'و',
00103         'û' => 'وو',
00104         'w' => 'و',
00105         ',' => '،',
00106         '?' => '؟',
00107 
00108         # Try to replace the leading vowel
00109         ' a' => 'ئا ',
00110         ' e' => 'ئە ',
00111         ' ê' => 'ئێ ',
00112         ' î' => 'ئی ',
00113         ' o' => 'ئۆ ',
00114         ' u' => 'ئو ',
00115         ' û' => 'ئوو ',
00116         'A' => 'ئا',
00117         'E' => 'ئە',
00118         'Ê' => 'ئێ',
00119         'Î' => 'ئی',
00120         'O' => 'ئۆ',
00121         'U' => 'ئو',
00122         'Û' => 'ئوو',
00123         ' A' => 'ئا ',
00124         ' E' => 'ئە ',
00125         ' Ê' => 'ئێ ',
00126         ' Î' => 'ئی ',
00127         ' O' => 'ئۆ ',
00128         ' U' => 'ئو ',
00129         ' Û' => 'ئوو ',
00130         # eyn erstmal deaktivieren, einfache Anführungsstriche sind einfach zu häufig, um sie als eyn zu interpretieren
00131         # '\'' => 'ع',
00132 
00133 /*      # deactivated for now, breaks links i.e. in header of Special:Recentchanges :-(
00134         # digits
00135         '0' => '٠', # &#x0660;
00136         '1' => '١', # &#x0661;
00137         '2' => '٢', # &#x0662;
00138         '3' => '٣', # &#x0663;
00139         '4' => '٤', # &#x0664;
00140         '5' => '٥', # &#x0665;
00141         '6' => '٦', # &#x0666;
00142         '7' => '٧', # &#x0667;
00143         '8' => '٨', # &#x0668;
00144         '9' => '٩', # &#x0669;
00145 */
00146         );
00147 
00148     function loadDefaultTables() {
00149         $this->mTables = array(
00150             'ku-latn' => new ReplacementArray( $this->mArabicToLatin ),
00151             'ku-arab' => new ReplacementArray( $this->mLatinToArabic ),
00152             'ku' => new ReplacementArray()
00153         );
00154     }
00155 
00166     function findVariantLink( &$link, &$nt, $ignoreOtherCond = false ) {
00167         // check for user namespace
00168         if ( is_object( $nt ) ) {
00169             $ns = $nt->getNamespace();
00170             if ( $ns == NS_USER || $ns == NS_USER_TALK ) {
00171                 return;
00172             }
00173         }
00174 
00175         $oldlink = $link;
00176         parent::findVariantLink( $link, $nt, $ignoreOtherCond );
00177         if ( $this->getPreferredVariant() == $this->mMainLanguageCode ) {
00178             $link = $oldlink;
00179         }
00180     }
00181 
00191     function autoConvert( $text, $toVariant = false ) {
00192         global $wgTitle;
00193         if ( is_object( $wgTitle ) && $wgTitle->getNamespace() == NS_FILE ) {
00194             $imagename = $wgTitle->getNsText();
00195             if ( preg_match( "/^$imagename:/", $text ) ) {
00196                 return $text;
00197             }
00198         }
00199         return parent::autoConvert( $text, $toVariant );
00200     }
00201 
00212     function translate( $text, $toVariant ) {
00213         $this->loadTables();
00214         /* From Kazakh interface, maybe we need it later
00215         $breaks = '[^\w\x80-\xff]';
00216         // regexp for roman numbers
00217         $roman = 'M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})';
00218         $roman = '';
00219 
00220         $reg = '/^'.$roman.'$|^'.$roman.$breaks.'|'.$breaks.$roman.'$|'.$breaks.$roman.$breaks.'/';
00221 
00222         $matches = preg_split($reg, $text, -1, PREG_SPLIT_OFFSET_CAPTURE);
00223 
00224         $m = array_shift($matches);
00225         if( !isset( $this->mTables[$toVariant] ) ) {
00226             throw new MWException( "Broken variant table: " . implode( ',', array_keys( $this->mTables ) ) );
00227         }
00228         $ret = $this->mTables[$toVariant]->replace( $m[0] );
00229         $mstart = $m[1]+strlen($m[0]);
00230         foreach($matches as $m) {
00231             $ret .= substr($text, $mstart, $m[1]-$mstart);
00232             $ret .= parent::translate($m[0], $toVariant);
00233             $mstart = $m[1] + strlen($m[0]);
00234         }
00235 
00236         return $ret;
00237         */
00238 
00239         if ( !isset( $this->mTables[$toVariant] ) ) {
00240             throw new MWException( "Broken variant table: " . implode( ',', array_keys( $this->mTables ) ) );
00241         }
00242 
00243         return parent::translate( $text, $toVariant );
00244     }
00245 }
00246 
00252 class LanguageKu extends LanguageKu_ku {
00253 
00254     function __construct() {
00255         global $wgHooks;
00256         parent::__construct();
00257 
00258         $variants = array( 'ku', 'ku-arab', 'ku-latn' );
00259         $variantfallbacks = array(
00260             'ku' => 'ku-latn',
00261             'ku-arab' => 'ku-latn',
00262             'ku-latn' => 'ku-arab',
00263         );
00264 
00265         $this->mConverter = new KuConverter( $this, 'ku', $variants, $variantfallbacks );
00266         $wgHooks['PageContentSaveComplete'][] = $this->mConverter;
00267     }
00268 }