LanguageKu.php 6.8 KB

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