Strip commented out convertGrammar()
[lhc/web/wiklou.git] / languages / classes / LanguageKu.php
1 <?php
2 require_once( dirname(__FILE__).'/../LanguageConverter.php' );
3 require_once( dirname(__FILE__).'/LanguageKu_ku.php' );
4
5 /** Kurdish
6 * converter routines
7 *
8 * @ingroup Language
9 */
10 class KuConverter extends LanguageConverter {
11 var $mArabicToLatin = array(
12 'ب' => 'b', 'ج' => 'c', 'چ' => 'ç', 'د' => 'd', 'ف' => 'f', 'گ' => 'g', 'ھ' => 'h',
13 'ہ' => 'h', 'ه' => 'h', 'ح' => 'h', 'ژ' => 'j', 'ك' => 'k', 'ک' => 'k', 'ل' => 'l',
14 'م' => 'm', 'ن' => 'n', 'پ' => 'p', 'ق' => 'q', 'ر' => 'r', 'س' => 's', 'ش' => 'ş',
15 'ت' => 't', 'ڤ' => 'v', 'خ' => 'x', 'غ' => 'x', 'ز' => 'z',
16
17 // ک و => ku -- ist richtig
18 // و ك=> ku -- ist auch richtig
19
20 /* Doppel- und Halbvokale */
21 'ڵ' => 'll', #ll
22 'ڕ' => 'rr', #rr
23 'ا' => 'a',
24 # 'ئێ' => 'ê', # initial e
25 'ە' => 'e',
26 'ه‌' => 'e', # with one non-joiner
27 'ه‌‌' => 'e', # with two non-joiner
28 'ة' => 'e',
29 'ێ' => 'ê',
30 'ي' => 'î',
31 'ی' => 'î', # U+06CC db 8c ARABIC LETTER FARSI YEH
32 'ى' => 'î', # U+0649 d9 89 ARABIC LETTER ALEF MAKSURA
33 'ۆ' => 'o',
34 'و' => 'w',
35 'ئ' => '', # initial hemze should not be shown
36 '،' => ',',
37 'ع' => '\'', # ayn
38 '؟' => '?',
39
40 # digits
41 '٠' => '0', # &#x0660;
42 '١' => '1', # &#x0661;
43 '٢' => '2', # &#x0662;
44 '٣' => '3', # &#x0663;
45 '٤' => '4', # &#x0664;
46 '٥' => '5', # &#x0665;
47 '٦' => '6', # &#x0666;
48 '٧' => '7', # &#x0667;
49 '٨' => '8', # &#x0668;
50 '٩' => '9', # &#x0669;
51 );
52
53 var $mLatinToArabic = array(
54 'b' => 'ب', 'c' => 'ج', 'ç' => 'چ', 'd' => 'د', 'f' => 'ف', 'g' => 'گ',
55 'h' => 'ه', 'j' => 'ژ', 'k' => 'ک', 'l' => 'ل',
56 'm' => 'م', 'n' => 'ن', 'p' => 'پ', 'q' => 'ق', 'r' => 'ر', 's' => 'س', 'ş' => 'ش',
57 't' => 'ت', 'v' => 'ڤ',
58 'x' => 'خ', 'y' => 'ی', 'z' => 'ز',
59
60
61 'B' => 'ب', 'C' => 'ج', 'Ç' => 'چ', 'D' => 'د', 'F' => 'ف', 'G' => 'گ', 'H' => 'ھ',
62 'H' => 'ہ', 'H' => 'ه', 'H' => 'ح', 'J' => 'ژ', 'K' => 'ك', 'K' => 'ک', 'L' => 'ل',
63 'M' => 'م', 'N' => 'ن', 'P' => 'پ', 'Q' => 'ق', 'R' => 'ر', 'S' => 'س', 'Ş' => 'ش',
64 'T' => 'ت', 'V' => 'ڤ', 'W' => 'و', 'X' => 'خ',
65 'Y' => 'ی', 'Z' => 'ز',
66
67 /* Doppelkonsonanten */
68 # 'll' => 'ڵ', # wenn es geht, doppel-l und l getrennt zu behandeln
69 # 'rr' => 'ڕ', # selbiges für doppel-r
70
71 /* Einzelne Großbuchstaben */
72 //' C' => 'ج',
73
74 /* Vowels */
75 'a' => 'ا',
76 'e' => 'ە',
77 'ê' => 'ێ',
78 'i' => '',
79 'î' => 'ی',
80 'o' => 'ۆ',
81 'u' => 'و',
82 'û' => 'وو',
83 'w' => 'و',
84 ',' => '،',
85 '?' => '؟',
86
87 # Try to replace the leading vowel
88 ' a' => 'ئا ',
89 ' e' => 'ئە ',
90 ' ê' => 'ئێ ',
91 ' î' => 'ئی ',
92 ' o' => 'ئۆ ',
93 ' u' => 'ئو ',
94 ' û' => 'ئوو ',
95 'A' => 'ئا',
96 'E' => 'ئە',
97 'Ê' => 'ئێ',
98 'Î' => 'ئی',
99 'O' => 'ئۆ',
100 'U' => 'ئو',
101 'Û' => 'ئوو',
102 ' A' => 'ئا ',
103 ' E' => 'ئە ',
104 ' Ê' => 'ئێ ',
105 ' Î' => 'ئی ',
106 ' O' => 'ئۆ ',
107 ' U' => 'ئو ',
108 ' Û' => 'ئوو ',
109 # eyn erstmal deaktivieren, einfache Anführungsstriche sind einfach zu häufig, um sie als eyn zu interpretieren
110 # '\'' => 'ع',
111
112 /* # deactivated for now, breaks links i.e. in header of Special:Recentchanges :-(
113 # digits
114 '0' => '٠', # &#x0660;
115 '1' => '١', # &#x0661;
116 '2' => '٢', # &#x0662;
117 '3' => '٣', # &#x0663;
118 '4' => '٤', # &#x0664;
119 '5' => '٥', # &#x0665;
120 '6' => '٦', # &#x0666;
121 '7' => '٧', # &#x0667;
122 '8' => '٨', # &#x0668;
123 '9' => '٩', # &#x0669;
124 */
125 );
126
127 function loadDefaultTables() {
128 $this->mTables = array(
129 'ku-latn' => new ReplacementArray( $this->mArabicToLatin ),
130 'ku-arab' => new ReplacementArray( $this->mLatinToArabic ),
131 'ku' => new ReplacementArray()
132 );
133 }
134
135 // Do not convert content on talk pages
136 function parserConvert( $text, &$parser ){
137 if(is_object($parser->getTitle() ) && $parser->getTitle()->isTalkPage())
138 $this->mDoContentConvert=false;
139 else
140 $this->mDoContentConvert=true;
141
142 return parent::parserConvert($text, $parser );
143 }
144
145 /*
146 * A function wrapper:
147 * - if there is no selected variant, leave the link
148 * names as they were
149 * - do not try to find variants for usernames
150 */
151 function findVariantLink( &$link, &$nt ) {
152 // check for user namespace
153 if(is_object($nt)){
154 $ns = $nt->getNamespace();
155 if($ns==NS_USER || $ns==NS_USER_TALK)
156 return;
157 }
158
159 $oldlink=$link;
160 parent::findVariantLink($link,$nt);
161 if($this->getPreferredVariant()==$this->mMainLanguageCode)
162 $link=$oldlink;
163 }
164
165 /*
166 * We want our external link captions to be converted in variants,
167 * so we return the original text instead -{$text}-, except for URLs
168 */
169 function markNoConversion($text, $noParse=false) {
170 if($noParse || preg_match("/^https?:\/\/|ftp:\/\/|irc:\/\//",$text))
171 return parent::markNoConversion($text);
172 return $text;
173 }
174
175 /*
176 * An ugly function wrapper for parsing Image titles
177 * (to prevent image name conversion)
178 */
179 function autoConvert($text, $toVariant=false) {
180 global $wgTitle;
181 if(is_object($wgTitle) && $wgTitle->getNameSpace()==NS_IMAGE){
182 $imagename = $wgTitle->getNsText();
183 if(preg_match("/^$imagename:/",$text)) return $text;
184 }
185 return parent::autoConvert($text,$toVariant);
186 }
187
188 /**
189 * It translates text into variant, specials:
190 * - ommiting roman numbers
191 */
192 function translate($text, $toVariant){
193 $breaks = '[^\w\x80-\xff]';
194
195 /* From Kazakh interface, maybe we need it later
196 *
197 // regexp for roman numbers
198 $roman = 'M{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})';
199 $roman = '';
200
201 $reg = '/^'.$roman.'$|^'.$roman.$breaks.'|'.$breaks.$roman.'$|'.$breaks.$roman.$breaks.'/';
202
203 $matches = preg_split($reg, $text, -1, PREG_SPLIT_OFFSET_CAPTURE);
204
205 $m = array_shift($matches);
206 if( !isset( $this->mTables[$toVariant] ) ) {
207 throw new MWException( "Broken variant table: " . implode( ',', array_keys( $this->mTables ) ) );
208 }
209 $ret = $this->mTables[$toVariant]->replace( $m[0] );
210 $mstart = $m[1]+strlen($m[0]);
211 foreach($matches as $m) {
212 $ret .= substr($text, $mstart, $m[1]-$mstart);
213 $ret .= parent::translate($m[0], $toVariant);
214 $mstart = $m[1] + strlen($m[0]);
215 }
216
217 return $ret;
218 */
219
220 if( !isset( $this->mTables[$toVariant] ) ) {
221 throw new MWException( "Broken variant table: " . implode( ',', array_keys( $this->mTables ) ) );
222 }
223
224 return parent::translate( $text, $toVariant );
225 }
226 }
227
228 /**
229 * @ingroup Language
230 */
231 class LanguageKu extends LanguageKu_ku {
232
233 function __construct() {
234 global $wgHooks;
235 parent::__construct();
236
237 $variants = array( 'ku', 'ku-arab', 'ku-latn' );
238 $variantfallbacks = array(
239 'ku' => 'ku-latn',
240 'ku-arab' => 'ku-latn',
241 'ku-latn' => 'ku-arab',
242 );
243
244 $this->mConverter = new KuConverter( $this, 'ku', $variants, $variantfallbacks );
245 $wgHooks['ArticleSaveComplete'][] = $this->mConverter;
246 }
247 }