Add digit transformation for Kurdish - Arabic script (Sorani)
[lhc/web/wiklou.git] / languages / classes / LanguageKu.php
1 <?php
2 /** Kurdish
3 * converter routines
4 *
5 * @addtogroup Language
6 */
7
8 require_once( dirname(__FILE__).'/../LanguageConverter.php' );
9 require_once( dirname(__FILE__).'/LanguageKu_ku.php' );
10
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',
17
18 // ک و => ku -- ist richtig
19 // و ك=> ku -- ist auch richtig
20
21 /* Doppel- und Halbvokale */
22 'ڵ' => 'll', #ll
23 'ڕ' => 'rr', #rr
24 'ا' => 'a',
25 # 'ئێ' => 'ê', # initial e
26 'ە' => 'e',
27 'ه‌' => 'e', # with one non-joiner
28 'ه‌‌' => 'e', # with two non-joiner
29 'ة' => 'e',
30 'ێ' => 'ê',
31 'ي' => 'î',
32 'ی' => 'î', # U+06CC db 8c ARABIC LETTER FARSI YEH
33 'ى' => 'î', # U+0649 d9 89 ARABIC LETTER ALEF MAKSURA
34 'ۆ' => 'o',
35 'و' => 'w',
36 'ئ' => '', # initial hemze should not be shown
37 '،' => ',',
38 'ع' => '\'', # ayn
39 '؟' => '?',
40
41 # digits
42 '٠' => '0', # &#x0660;
43 '١' => '1', # &#x0661;
44 '٢' => '2', # &#x0662;
45 '٣' => '3', # &#x0663;
46 '٤' => '4', # &#x0664;
47 '٥' => '5', # &#x0665;
48 '٦' => '6', # &#x0666;
49 '٧' => '7', # &#x0667;
50 '٨' => '8', # &#x0668;
51 '٩' => '9', # &#x0669;
52 );
53
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' => 'ز',
60
61
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' => 'ز',
67
68 /* Doppelkonsonanten */
69 # 'll' => 'ڵ', # wenn es geht, doppel-l und l getrennt zu behandeln
70 # 'rr' => 'ڕ', # selbiges für doppel-r
71
72 /* Einzelne Großbuchstaben */
73 //' C' => 'ج',
74
75 /* Vowels */
76 'a' => 'ا',
77 'e' => 'ە',
78 'ê' => 'ێ',
79 'i' => '',
80 'î' => 'ی',
81 'o' => 'ۆ',
82 'u' => 'و',
83 'û' => 'وو',
84 'w' => 'و',
85 ',' => '،',
86 '?' => '؟',
87
88 # Try to replace the leading vowel
89 ' a' => 'ئا ',
90 ' e' => 'ئە ',
91 ' ê' => 'ئێ ',
92 ' î' => 'ئی ',
93 ' o' => 'ئۆ ',
94 ' u' => 'ئو ',
95 ' û' => 'ئوو ',
96 'A' => 'ئا',
97 'E' => 'ئە',
98 'Ê' => 'ئێ',
99 'Î' => 'ئی',
100 'O' => 'ئۆ',
101 'U' => 'ئو',
102 'Û' => 'ئوو',
103 ' A' => 'ئا ',
104 ' E' => 'ئە ',
105 ' Ê' => 'ئێ ',
106 ' Î' => 'ئی ',
107 ' O' => 'ئۆ ',
108 ' U' => 'ئو ',
109 ' Û' => 'ئوو ',
110 # eyn erstmal deaktivieren, einfache Anführungsstriche sind einfach zu häufig, um sie als eyn zu interpretieren
111 # '\'' => 'ع',
112
113 /* # deactivated for now, breaks links i.e. in header of Special:Recentchanges :-(
114 # digits
115 '0' => '٠', # &#x0660;
116 '1' => '١', # &#x0661;
117 '2' => '٢', # &#x0662;
118 '3' => '٣', # &#x0663;
119 '4' => '٤', # &#x0664;
120 '5' => '٥', # &#x0665;
121 '6' => '٦', # &#x0666;
122 '7' => '٧', # &#x0667;
123 '8' => '٨', # &#x0668;
124 '9' => '٩', # &#x0669;
125 */
126 );
127
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()
133 );
134 }
135
136
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;
141 else
142 $this->mDoContentConvert=true;
143
144 return parent::parserConvert($text, $parser );
145 }
146
147 /*
148 * A function wrapper:
149 * - if there is no selected variant, leave the link
150 * names as they were
151 * - do not try to find variants for usernames
152 */
153 function findVariantLink( &$link, &$nt ) {
154 // check for user namespace
155 if(is_object($nt)){
156 $ns = $nt->getNamespace();
157 if($ns==NS_USER || $ns==NS_USER_TALK)
158 return;
159 }
160
161 $oldlink=$link;
162 parent::findVariantLink($link,$nt);
163 if($this->getPreferredVariant()==$this->mMainLanguageCode)
164 $link=$oldlink;
165 }
166
167 /*
168 * We want our external link captions to be converted in variants,
169 * so we return the original text instead -{$text}-, except for URLs
170 */
171 function markNoConversion($text, $noParse=false) {
172 if($noParse || preg_match("/^https?:\/\/|ftp:\/\/|irc:\/\//",$text))
173 return parent::markNoConversion($text);
174 return $text;
175 }
176
177 /*
178 * An ugly function wrapper for parsing Image titles
179 * (to prevent image name conversion)
180 */
181 function autoConvert($text, $toVariant=false) {
182 global $wgTitle;
183 if(is_object($wgTitle) && $wgTitle->getNameSpace()==NS_IMAGE){
184 $imagename = $wgTitle->getNsText();
185 if(preg_match("/^$imagename:/",$text)) return $text;
186 }
187 return parent::autoConvert($text,$toVariant);
188 }
189
190 /**
191 * It translates text into variant, specials:
192 * - ommiting roman numbers
193 */
194 function translate($text, $toVariant){
195 $breaks = '[^\w\x80-\xff]';
196
197 /* From Kazakh interface, maybe we need it later
198 *
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})';
201 $roman = '';
202
203 $reg = '/^'.$roman.'$|^'.$roman.$breaks.'|'.$breaks.$roman.'$|'.$breaks.$roman.$breaks.'/';
204
205 $matches = preg_split($reg, $text, -1, PREG_SPLIT_OFFSET_CAPTURE);
206
207 $m = array_shift($matches);
208 if( !isset( $this->mTables[$toVariant] ) ) {
209 throw new MWException( "Broken variant table: " . implode( ',', array_keys( $this->mTables ) ) );
210 }
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]);
217 }
218
219 return $ret;
220 */
221
222 if( !isset( $this->mTables[$toVariant] ) ) {
223 throw new MWException( "Broken variant table: " . implode( ',', array_keys( $this->mTables ) ) );
224 }
225
226 return parent::translate( $text, $toVariant );
227 }
228 }
229
230 class LanguageKu extends LanguageKu_ku {
231
232 function __construct() {
233 global $wgHooks;
234 parent::__construct();
235
236 $variants = array( 'ku', 'ku-arab', 'ku-latn' );
237 $variantfallbacks = array(
238 'ku' => 'ku-latn',
239 'ku-arab' => 'ku-latn',
240 'ku-latn' => 'ku-arab',
241 );
242
243 $this->mConverter = new KuConverter( $this, 'ku', $variants, $variantfallbacks );
244 $wgHooks['ArticleSaveComplete'][] = $this->mConverter;
245 }
246
247 /* From Kazakh interface, not needed for the moment
248
249 function convertGrammar( $word, $case ) {
250 $fname="LanguageKu::convertGrammar";
251 wfProfileIn( $fname );
252
253 //always convert to ku-latn before convertGrammar
254 $w1 = $word;
255 $word = $this->mConverter->autoConvert( $word, 'ku-latn' );
256 $w2 = $word;
257 $word = parent::convertGrammar( $word, $case );
258 //restore encoding
259 if( $w1 != $w2 ) {
260 $word = $this->mConverter->translate( $word, 'ku-latn' );
261 }
262 wfProfileOut( $fname );
263 return $word;
264 }
265 */
266 }