LanguageKu.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <?php
  2. /**
  3. * Kurdish specific code.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program; if not, write to the Free Software Foundation, Inc.,
  17. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. * http://www.gnu.org/copyleft/gpl.html
  19. *
  20. * @file
  21. * @ingroup Language
  22. */
  23. /**
  24. * Kurdish converter routines
  25. *
  26. * @ingroup Language
  27. */
  28. class KuConverter extends LanguageConverter {
  29. public $mArabicToLatin = [
  30. 'ب' => 'b', 'ج' => 'c', 'چ' => 'ç', 'د' => 'd', 'ف' => 'f', 'گ' => 'g', 'ھ' => 'h',
  31. 'ہ' => 'h', 'ه' => 'h', 'ح' => 'h', 'ژ' => 'j', 'ك' => 'k', 'ک' => 'k', 'ل' => 'l',
  32. 'م' => 'm', 'ن' => 'n', 'پ' => 'p', 'ق' => 'q', 'ر' => 'r', 'س' => 's', 'ش' => 'ş',
  33. 'ت' => 't', 'ڤ' => 'v', 'خ' => 'x', 'غ' => 'x', 'ز' => 'z',
  34. // ک و => ku -- ist richtig
  35. // و ك=> ku -- ist auch richtig
  36. /* Doppel- und Halbvokale */
  37. 'ڵ' => 'll', # ll
  38. 'ڕ' => 'rr', # rr
  39. 'ا' => 'a',
  40. # 'ئێ' => 'ê', # initial e
  41. 'ە' => 'e',
  42. 'ه‌' => 'e', # with one non-joiner
  43. 'ه‌‌' => 'e', # with two non-joiner
  44. 'ة' => 'e',
  45. 'ێ' => 'ê',
  46. 'ي' => 'î',
  47. 'ی' => 'î', # U+06CC db 8c ARABIC LETTER FARSI YEH
  48. 'ى' => 'î', # U+0649 d9 89 ARABIC LETTER ALEF MAKSURA
  49. 'ۆ' => 'o',
  50. 'و' => 'w',
  51. 'ئ' => '', # initial hemze should not be shown
  52. '،' => ',',
  53. 'ع' => '\'', # ayn
  54. '؟' => '?',
  55. # digits
  56. '٠' => '0', # &#x0660;
  57. '١' => '1', # &#x0661;
  58. '٢' => '2', # &#x0662;
  59. '٣' => '3', # &#x0663;
  60. '٤' => '4', # &#x0664;
  61. '٥' => '5', # &#x0665;
  62. '٦' => '6', # &#x0666;
  63. '٧' => '7', # &#x0667;
  64. '٨' => '8', # &#x0668;
  65. '٩' => '9', # &#x0669;
  66. ];
  67. public $mLatinToArabic = [
  68. 'b' => 'ب', 'c' => 'ج', 'ç' => 'چ', 'd' => 'د', 'f' => 'ف', 'g' => 'گ',
  69. 'h' => 'ه', 'j' => 'ژ', 'k' => 'ک', 'l' => 'ل',
  70. 'm' => 'م', 'n' => 'ن', 'p' => 'پ', 'q' => 'ق', 'r' => 'ر', 's' => 'س', 'ş' => 'ش',
  71. 't' => 'ت', 'v' => 'ڤ',
  72. 'x' => 'خ', 'y' => 'ی', 'z' => 'ز',
  73. 'B' => 'ب', 'C' => 'ج', 'Ç' => 'چ', 'D' => 'د', 'F' => 'ف', 'G' => 'گ', 'H' => 'ھ',
  74. 'H' => 'ہ', 'H' => 'ه', 'H' => 'ح', 'J' => 'ژ', 'K' => 'ك', 'K' => 'ک', 'L' => 'ل',
  75. 'M' => 'م', 'N' => 'ن', 'P' => 'پ', 'Q' => 'ق', 'R' => 'ر', 'S' => 'س', 'Ş' => 'ش',
  76. 'T' => 'ت', 'V' => 'ڤ', 'W' => 'و', 'X' => 'خ',
  77. 'Y' => 'ی', 'Z' => 'ز',
  78. /* Doppelkonsonanten */
  79. # 'll' => 'ڵ', # wenn es geht, doppel-l und l getrennt zu behandeln
  80. # 'rr' => 'ڕ', # selbiges für doppel-r
  81. /* Einzelne Großbuchstaben */
  82. // ' C' => 'ج',
  83. /* Vowels */
  84. 'a' => 'ا',
  85. 'e' => 'ە',
  86. 'ê' => 'ێ',
  87. 'i' => '',
  88. 'î' => 'ی',
  89. 'o' => 'ۆ',
  90. 'u' => 'و',
  91. 'û' => 'وو',
  92. 'w' => 'و',
  93. ',' => '،',
  94. '?' => '؟',
  95. # Try to replace the leading vowel
  96. ' a' => 'ئا ',
  97. ' e' => 'ئە ',
  98. ' ê' => 'ئێ ',
  99. ' î' => 'ئی ',
  100. ' o' => 'ئۆ ',
  101. ' u' => 'ئو ',
  102. ' û' => 'ئوو ',
  103. 'A' => 'ئا',
  104. 'E' => 'ئە',
  105. 'Ê' => 'ئێ',
  106. 'Î' => 'ئی',
  107. 'O' => 'ئۆ',
  108. 'U' => 'ئو',
  109. 'Û' => 'ئوو',
  110. ' A' => 'ئا ',
  111. ' E' => 'ئە ',
  112. ' Ê' => 'ئێ ',
  113. ' Î' => 'ئی ',
  114. ' O' => 'ئۆ ',
  115. ' U' => 'ئو ',
  116. ' Û' => 'ئوو ',
  117. # eyn erstmal deaktivieren, einfache Anführungsstriche sind einfach zu
  118. # häufig, um sie als eyn zu interpretieren.
  119. # '\'' => 'ع',
  120. /* # deactivated for now, breaks links i.e. in header of Special:Recentchanges :-(
  121. # digits
  122. '0' => '٠', # &#x0660;
  123. '1' => '١', # &#x0661;
  124. '2' => '٢', # &#x0662;
  125. '3' => '٣', # &#x0663;
  126. '4' => '٤', # &#x0664;
  127. '5' => '٥', # &#x0665;
  128. '6' => '٦', # &#x0666;
  129. '7' => '٧', # &#x0667;
  130. '8' => '٨', # &#x0668;
  131. '9' => '٩', # &#x0669;
  132. */
  133. ];
  134. function loadDefaultTables() {
  135. $this->mTables = [
  136. 'ku-latn' => new ReplacementArray( $this->mArabicToLatin ),
  137. 'ku-arab' => new ReplacementArray( $this->mLatinToArabic ),
  138. 'ku' => new ReplacementArray()
  139. ];
  140. }
  141. /**
  142. * A function wrapper:
  143. * - if there is no selected variant, leave the link
  144. * names as they were
  145. * - do not try to find variants for usernames
  146. *
  147. * @param string &$link
  148. * @param Title &$nt
  149. * @param bool $ignoreOtherCond
  150. */
  151. function findVariantLink( &$link, &$nt, $ignoreOtherCond = false ) {
  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, $ignoreOtherCond );
  161. if ( $this->getPreferredVariant() == $this->mMainLanguageCode ) {
  162. $link = $oldlink;
  163. }
  164. }
  165. /**
  166. * It translates text into variant, specials:
  167. * - ommiting roman numbers
  168. *
  169. * @param string $text
  170. * @param bool $toVariant
  171. *
  172. * @throws MWException
  173. * @return string
  174. */
  175. function translate( $text, $toVariant ) {
  176. $this->loadTables();
  177. /* From Kazakh interface, maybe we need it later
  178. $breaks = '[^\w\x80-\xff]';
  179. // regexp for roman numbers
  180. // Lookahead assertion ensures $roman doesn't match the empty string
  181. $roman = '(?=[MDCLXVI])M{0,4}(C[DM]|D?C{0,3})(X[LC]|L?X{0,3})(I[VX]|V?I{0,3})';
  182. $roman = '';
  183. $reg = '/^'.$roman.'$|^'.$roman.$breaks.'|'.$breaks.$roman.'$|'.$breaks.$roman.$breaks.'/';
  184. $matches = preg_split($reg, $text, -1, PREG_SPLIT_OFFSET_CAPTURE);
  185. $m = array_shift($matches);
  186. if( !isset( $this->mTables[$toVariant] ) ) {
  187. throw new MWException( "Broken variant table: " . implode( ',', array_keys( $this->mTables ) ) );
  188. }
  189. $ret = $this->mTables[$toVariant]->replace( $m[0] );
  190. $mstart = $m[1]+strlen($m[0]);
  191. foreach($matches as $m) {
  192. $ret .= substr($text, $mstart, $m[1]-$mstart);
  193. $ret .= parent::translate($m[0], $toVariant);
  194. $mstart = $m[1] + strlen($m[0]);
  195. }
  196. return $ret;
  197. */
  198. if ( !isset( $this->mTables[$toVariant] ) ) {
  199. throw new MWException( "Broken variant table: " . implode( ',', array_keys( $this->mTables ) ) );
  200. }
  201. return parent::translate( $text, $toVariant );
  202. }
  203. }
  204. /**
  205. * Kurdish (Kurdî / كوردی)
  206. *
  207. * @ingroup Language
  208. */
  209. class LanguageKu extends Language {
  210. function __construct() {
  211. parent::__construct();
  212. $variants = [ 'ku', 'ku-arab', 'ku-latn' ];
  213. $variantfallbacks = [
  214. 'ku' => 'ku-latn',
  215. 'ku-arab' => 'ku-latn',
  216. 'ku-latn' => 'ku-arab',
  217. ];
  218. $this->mConverter = new KuConverter( $this, 'ku', $variants, $variantfallbacks );
  219. }
  220. }