MediaWiki  REL1_24
LanguageUz.php
Go to the documentation of this file.
00001 <?php
00024 require_once __DIR__ . '/../LanguageConverter.php';
00025 
00029 class UzConverter extends LanguageConverter {
00030     public $toLatin = array(
00031         'а' => 'a', 'А' => 'A',
00032         'б' => 'b', 'Б' => 'B',
00033         'д' => 'd', 'Д' => 'D',
00034         'е' => 'e', 'Е' => 'E',
00035         'э' => 'e', 'Э' => 'E',
00036         'в' => 'v', 'В' => 'V',
00037         'х' => 'x', 'Х' => 'X',
00038         'ғ' => 'gʻ', 'Ғ' => 'Gʻ',
00039         'г' => 'g', 'Г' => 'G',
00040         'ҳ' => 'h', 'Ҳ' => 'H',
00041         'ж' => 'j', 'Ж' => 'J',
00042         'з' => 'z', 'З' => 'Z',
00043         'и' => 'i', 'И' => 'I',
00044         'к' => 'k', 'К' => 'K',
00045         'л' => 'l', 'Л' => 'L',
00046         'м' => 'm', 'М' => 'M',
00047         'н' => 'n', 'Н' => 'N',
00048         'о' => 'o', 'О' => 'O',
00049         'п' => 'p', 'П' => 'P',
00050         'р' => 'r', 'Р' => 'R',
00051         'с' => 's', 'С' => 'S',
00052         'т' => 't', 'Т' => 'T',
00053         'у' => 'u', 'У' => 'U',
00054         'ф' => 'f', 'Ф' => 'F',
00055         'ц' => 'c', 'Ц' => 'C',
00056         'ў' => 'oʻ', 'Ў' => 'Oʻ',
00057         // note: at the beginning of a word and right after a consonant, only "s" is used
00058         'ц' => 'ts', 'Ц' => 'Ts',
00059         'қ' => 'q', 'Қ' => 'Q',
00060         'ё' => 'yo', 'Ё' => 'Yo',
00061         'ю' => 'yu', 'Ю' => 'Yu',
00062         'ч' => 'ch', 'Ч' => 'Ch',
00063         'ш' => 'sh', 'Ш' => 'Sh',
00064         'й' => 'y', 'Й' => 'Y',
00065         'я' => 'ya', 'Я' => 'Ya',
00066         'ъ' => 'ʼ',
00067     );
00068 
00069     public $toCyrillic = array(
00070         'a' => 'а', 'A' => 'А',
00071         'b' => 'б', 'B' => 'Б',
00072         'd' => 'д', 'D' => 'Д',
00073         // at the beginning of a word and after a vowel, "э" is used instead of "e"
00074         // (see regex below)
00075         'e' => 'э', 'E' => 'Э',
00076         'f' => 'ф', 'F' => 'Ф',
00077         'g' => 'г', 'G' => 'Г',
00078         'g‘' => 'ғ', 'G‘' => 'Ғ', 'gʻ' => 'ғ', 'Gʻ' => 'Ғ',
00079         'h' => 'ҳ', 'H' => 'Ҳ',
00080         'i' => 'и', 'I' => 'И',
00081         'k' => 'к', 'K' => 'К',
00082         'l' => 'л', 'L' => 'Л',
00083         'm' => 'м', 'M' => 'М',
00084         'n' => 'н', 'N' => 'Н',
00085         'o' => 'о', 'O' => 'О',
00086         'p' => 'п', 'P' => 'П',
00087         'r' => 'р', 'R' => 'Р',
00088         's' => 'с', 'S' => 'С',
00089         't' => 'т', 'T' => 'Т',
00090         'u' => 'у', 'U' => 'У',
00091         'v' => 'в', 'V' => 'В',
00092         'x' => 'х', 'X' => 'Х',
00093         'z' => 'з', 'Z' => 'З',
00094         'j' => 'ж', 'J' => 'Ж',
00095         'o‘' => 'ў', 'O‘' => 'Ў', 'oʻ' => 'ў', 'Oʻ' => 'Ў',
00096         'yo‘' => 'йў', 'Yo‘' => 'Йў', 'yoʻ' => 'йў', 'Yoʻ' => 'Йў',
00097         'ts' => 'ц', 'Ts' => 'Ц',
00098         'q' => 'қ', 'Q' => 'Қ',
00099         'yo' => 'ё', 'Yo' => 'Ё',
00100         'yu' => 'ю', 'Yu' => 'Ю',
00101         'ch' => 'ч', 'Ch' => 'Ч',
00102         'sh' => 'ш', 'Sh' => 'Ш',
00103         'y' => 'й', 'Y' => 'Й',
00104         'ya' => 'я', 'Ya' => 'Я',
00105         'ʼ' => 'ъ',
00106     );
00107 
00108     function loadDefaultTables() {
00109         $this->mTables = array(
00110             'uz-cyrl' => new ReplacementArray( $this->toCyrillic ),
00111             'uz-latn' => new ReplacementArray( $this->toLatin ),
00112             'uz' => new ReplacementArray()
00113         );
00114     }
00115 
00116     function translate( $text, $toVariant ) {
00117         if ( $toVariant == 'uz-cyrl' ) {
00118             $text = str_replace( 'ye', 'е', $text );
00119             $text = str_replace( 'Ye', 'Е', $text );
00120             $text = str_replace( 'YE', 'Е', $text );
00121             // "е" after consonants, otherwise "э" (see above)
00122             $text = preg_replace( '/([BVGDJZYKLMNPRSTFXCWQʻ‘H])E/u', '$1Е', $text );
00123             $text = preg_replace( '/([bvgdjzyklmnprstfxcwqʻ‘h])e/ui', '$1е', $text );
00124         }
00125         return parent::translate( $text, $toVariant );
00126     }
00127 
00128 }
00129 
00135 class LanguageUz extends Language {
00136     function __construct() {
00137         global $wgHooks;
00138         parent::__construct();
00139 
00140         $variants = array( 'uz', 'uz-latn', 'uz-cyrl' );
00141         $variantfallbacks = array(
00142             'uz' => 'uz-latn',
00143             'uz-cyrl' => 'uz',
00144             'uz-latn' => 'uz',
00145         );
00146 
00147         $this->mConverter = new UzConverter( $this, 'uz', $variants, $variantfallbacks );
00148         $wgHooks['PageContentSaveComplete'][] = $this->mConverter;
00149     }
00150 }