8 require_once( dirname(__FILE__
).'/../LanguageConverter.php' );
9 require_once( dirname(__FILE__
).'/LanguageKu_ku.php' );
11 class KuConverter
extends LanguageConverter
{
12 var $mArabicToLatin = array(
13 'ب' => 'b', 'ج' => 'c', 'چ' => 'ç', 'د' => 'd', 'ف' => 'f', 'گ' => 'g', 'ھ' => 'h',
14 'ہ' => 'h', 'ه' => 'h', 'ح' => 'h', 'ژ' => 'j', 'ك' => 'k', 'ک' => 'k', 'ل' => 'l',
15 'م' => 'm', 'ن' => 'n', 'پ' => 'p', 'ق' => 'q', 'ر' => 'r', 'س' => 's', 'ش' => 'ş',
16 'ت' => 't', 'ڤ' => 'v', 'خ' => 'x', 'غ' => 'x', 'ز' => 'z',
18 // ک و => ku -- ist richtig
19 // و ك=> ku -- ist auch richtig
21 /* Doppel- und Halbvokale */
25 # 'ئێ' => 'ê', # initial e
27 'ه' => 'e', # with one non-joiner
28 'ه' => 'e', # with two non-joiner
32 'ی' => 'î', # U+06CC db 8c ARABIC LETTER FARSI YEH
33 'ى' => 'î', # U+0649 d9 89 ARABIC LETTER ALEF MAKSURA
36 'ئ' => '', # initial hemze should not be shown
42 '٠' => '0', # ٠
43 '١' => '1', # ١
44 '٢' => '2', # ٢
45 '٣' => '3', # ٣
46 '٤' => '4', # ٤
47 '٥' => '5', # ٥
48 '٦' => '6', # ٦
49 '٧' => '7', # ٧
50 '٨' => '8', # ٨
51 '٩' => '9', # ٩
54 var $mLatinToArabic = array(
55 'b' => 'ب', 'c' => 'ج', 'ç' => 'چ', 'd' => 'د', 'f' => 'ف', 'g' => 'گ',
56 'h' => 'ه', 'j' => 'ژ', 'k' => 'ک', 'l' => 'ل',
57 'm' => 'م', 'n' => 'ن', 'p' => 'پ', 'q' => 'ق', 'r' => 'ر', 's' => 'س', 'ş' => 'ش',
58 't' => 'ت', 'v' => 'ڤ',
59 'x' => 'خ', 'y' => 'ی', 'z' => 'ز',
62 'B' => 'ب', 'C' => 'ج', 'Ç' => 'چ', 'D' => 'د', 'F' => 'ف', 'G' => 'گ', 'H' => 'ھ',
63 'H' => 'ہ', 'H' => 'ه', 'H' => 'ح', 'J' => 'ژ', 'K' => 'ك', 'K' => 'ک', 'L' => 'ل',
64 'M' => 'م', 'N' => 'ن', 'P' => 'پ', 'Q' => 'ق', 'R' => 'ر', 'S' => 'س', 'Ş' => 'ش',
65 'T' => 'ت', 'V' => 'ڤ', 'W' => 'و', 'X' => 'خ',
66 'Y' => 'ی', 'Z' => 'ز',
68 /* Doppelkonsonanten */
69 # 'll' => 'ڵ', # wenn es geht, doppel-l und l getrennt zu behandeln
70 # 'rr' => 'ڕ', # selbiges für doppel-r
72 /* Einzelne Großbuchstaben */
88 # Try to replace the leading vowel
110 # eyn erstmal deaktivieren, einfache Anführungsstriche sind einfach zu häufig, um sie als eyn zu interpretieren
113 /* # deactivated for now, breaks links i.e. in header of Special:Recentchanges :-(
115 '0' => '٠', # ٠
116 '1' => '١', # ١
117 '2' => '٢', # ٢
118 '3' => '٣', # ٣
119 '4' => '٤', # ٤
120 '5' => '٥', # ٥
121 '6' => '٦', # ٦
122 '7' => '٧', # ٧
123 '8' => '٨', # ٨
124 '9' => '٩', # ٩
128 function loadDefaultTables() {
129 $this->mTables
= array(
130 'ku-latn' => new ReplacementArray( $this->mArabicToLatin
),
131 'ku-arab' => new ReplacementArray( $this->mLatinToArabic
),
132 'ku' => new ReplacementArray()
137 // Do not convert content on talk pages
138 function parserConvert( $text, &$parser ){
139 if(is_object($parser->getTitle() ) && $parser->getTitle()->isTalkPage())
140 $this->mDoContentConvert
=false;
142 $this->mDoContentConvert
=true;
144 return parent
::parserConvert($text, $parser );
148 * A function wrapper:
149 * - if there is no selected variant, leave the link
151 * - do not try to find variants for usernames
153 function findVariantLink( &$link, &$nt ) {
154 // check for user namespace
156 $ns = $nt->getNamespace();
157 if($ns==NS_USER ||
$ns==NS_USER_TALK
)
162 parent
::findVariantLink($link,$nt);
163 if($this->getPreferredVariant()==$this->mMainLanguageCode
)
168 * We want our external link captions to be converted in variants,
169 * so we return the original text instead -{$text}-, except for URLs
171 function markNoConversion($text, $noParse=false) {
172 if($noParse ||
preg_match("/^https?:\/\/|ftp:\/\/|irc:\/\//",$text))
173 return parent
::markNoConversion($text);
178 * An ugly function wrapper for parsing Image titles
179 * (to prevent image name conversion)
181 function autoConvert($text, $toVariant=false) {
183 if(is_object($wgTitle) && $wgTitle->getNameSpace()==NS_IMAGE
){
184 $imagename = $wgTitle->getNsText();
185 if(preg_match("/^$imagename:/",$text)) return $text;
187 return parent
::autoConvert($text,$toVariant);
191 * It translates text into variant, specials:
192 * - ommiting roman numbers
194 function translate($text, $toVariant){
195 $breaks = '[^\w\x80-\xff]';
197 /* From Kazakh interface, maybe we need it later
199 // regexp for roman numbers
200 $roman = 'M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})';
203 $reg = '/^'.$roman.'$|^'.$roman.$breaks.'|'.$breaks.$roman.'$|'.$breaks.$roman.$breaks.'/';
205 $matches = preg_split($reg, $text, -1, PREG_SPLIT_OFFSET_CAPTURE);
207 $m = array_shift($matches);
208 if( !isset( $this->mTables[$toVariant] ) ) {
209 throw new MWException( "Broken variant table: " . implode( ',', array_keys( $this->mTables ) ) );
211 $ret = $this->mTables[$toVariant]->replace( $m[0] );
212 $mstart = $m[1]+strlen($m[0]);
213 foreach($matches as $m) {
214 $ret .= substr($text, $mstart, $m[1]-$mstart);
215 $ret .= parent::translate($m[0], $toVariant);
216 $mstart = $m[1] + strlen($m[0]);
222 if( !isset( $this->mTables
[$toVariant] ) ) {
223 throw new MWException( "Broken variant table: " . implode( ',', array_keys( $this->mTables
) ) );
226 return parent
::translate( $text, $toVariant );
230 class LanguageKu
extends LanguageKu_ku
{
232 function __construct() {
234 parent
::__construct();
236 $variants = array( 'ku', 'ku-arab', 'ku-latn' );
237 $variantfallbacks = array(
239 'ku-arab' => 'ku-latn',
240 'ku-latn' => 'ku-arab',
243 $this->mConverter
= new KuConverter( $this, 'ku', $variants, $variantfallbacks );
244 $wgHooks['ArticleSaveComplete'][] = $this->mConverter
;
247 /* From Kazakh interface, not needed for the moment
249 function convertGrammar( $word, $case ) {
250 $fname="LanguageKu::convertGrammar";
251 wfProfileIn( $fname );
253 //always convert to ku-latn before convertGrammar
255 $word = $this->mConverter->autoConvert( $word, 'ku-latn' );
257 $word = parent::convertGrammar( $word, $case );
260 $word = $this->mConverter->translate( $word, 'ku-latn' );
262 wfProfileOut( $fname );