LanguageTyv.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <?php
  2. /** Tyvan localization (Тыва дыл)
  3. * From friends at tyvawiki.org
  4. *
  5. * @ingroup Language
  6. */
  7. class LanguageTyv extends Language {
  8. /**
  9. * Grammatical transformations, needed for inflected languages
  10. * Invoked by putting {{grammar:case|word}} in a message
  11. *
  12. * @param $word string
  13. * @param $case string
  14. * @return string
  15. */
  16. function convertGrammar( $word, $case ) {
  17. global $wgGrammarForms;
  18. if ( isset($wgGrammarForms['tyv'][$case][$word]) ) {
  19. return $wgGrammarForms['tyv'][$case][$word];
  20. }
  21. // Set up some constants...
  22. $allVowels = array("е", "и", "э", "ө", "ү", "а", "ё", "о", "у", "ы", "ю", "я", "a", "e", "i", "o", "ö", "u", "ü", "y");
  23. $frontVowels = array("е", "и", "э", "ө", "ү", "e", "i", "ö", "ü");
  24. $backVowels = array("а", "ё", "о", "у", "ы", "ю", "я", "a", "o", "u", "y");
  25. $unroundFrontVowels = array("е", "и", "э", "e", "i");
  26. $roundFrontVowels = array("ө", "ү", "ö", "ü");
  27. $unroundBackVowels = array("а", "ы", "я", "a", "y");
  28. $roundBackVowels = array("ё", "о", "у", "ю", "o", "u");
  29. $voicedPhonemes = array("д", "б", "з", "ж", "г", "d", "b", "z", "g");
  30. $unvoicedPhonemes = array("т", "п", "с", "ш", "к", "ч", "х", "t", "p", "s", "k", "x");
  31. $directiveUnvoicedStems = array("т", "п", "с", "ш", "к", "ч", "х", "л", "м", "н", "ң", "t", "p", "s", "k", "x", "l", "m", "n", "ŋ");
  32. $directiveVoicedStems = array("д", "б", "з", "ж", "г", "р", "й", "d", "b", "z", "g", "r", "j");
  33. // $allSonants = array("л", "м", "н", "ң", "р", "й");
  34. // $allNasals = array("м", "н", "ң");
  35. // Put the word in a form we can play with since we're using UTF-8
  36. preg_match_all( '/./us', $word, $ar );
  37. $wordEnding = $ar[0][count($ar[0]) - 1]; //Here's the last letter in the word
  38. $wordReversed = array_reverse($ar[0]); //Here's an array with the order of the letters in the word reversed so we can find a match quicker *shrug*
  39. // Find the last vowel in the word
  40. $wordLastVowel = NULL;
  41. foreach ( $wordReversed as $xvalue ) {
  42. foreach ( $allVowels as $yvalue ) {
  43. if ( strcmp($xvalue, $yvalue) == 0 ) {
  44. $wordLastVowel = $xvalue;
  45. break;
  46. } else {
  47. continue;
  48. }
  49. }
  50. if ( $wordLastVowel !== NULL ) {
  51. break;
  52. } else {
  53. continue;
  54. }
  55. }
  56. // Now convert the word
  57. switch ( $case ) {
  58. case "genitive":
  59. if ( in_array($wordEnding, $unvoicedPhonemes) ) {
  60. if ( in_array($wordLastVowel, $roundFrontVowels) ) {
  61. $word = implode("",$ar[0]) . "түң";
  62. } elseif ( in_array($wordLastVowel, $unroundFrontVowels) ) {
  63. $word = implode("",$ar[0]) . "тиң";
  64. } elseif ( in_array($wordLastVowel, $roundBackVowels) ) {
  65. $word = implode("",$ar[0]) . "туң";
  66. } elseif ( in_array($wordLastVowel, $unroundBackVowels) ) {
  67. $word = implode("",$ar[0]) . "тың";
  68. } else {
  69. }
  70. } elseif ( $wordEnding === "л" || $wordEnding === "l") {
  71. if ( in_array($wordLastVowel, $roundFrontVowels) ) {
  72. $word = implode("",$ar[0]) . "дүң";
  73. } elseif ( in_array($wordLastVowel, $unroundFrontVowels) ) {
  74. $word = implode("",$ar[0]) . "диң";
  75. } elseif ( in_array($wordLastVowel, $roundBackVowels) ) {
  76. $word = implode("",$ar[0]) . "дуң";
  77. } elseif ( in_array($wordLastVowel, $unroundBackVowels) ) {
  78. $word = implode("",$ar[0]) . "дың";
  79. } else {
  80. }
  81. } else {
  82. if ( in_array($wordLastVowel, $roundFrontVowels) ) {
  83. $word = implode("",$ar[0]) . "нүң";
  84. } elseif ( in_array($wordLastVowel, $unroundFrontVowels) ) {
  85. $word = implode("",$ar[0]) . "ниң";
  86. } elseif ( in_array($wordLastVowel, $roundBackVowels) ) {
  87. $word = implode("",$ar[0]) . "нуң";
  88. } elseif ( in_array($wordLastVowel, $unroundBackVowels) ) {
  89. $word = implode("",$ar[0]) . "ның";
  90. } else {
  91. }
  92. }
  93. break;
  94. case "dative":
  95. if ( in_array($wordEnding, $unvoicedPhonemes) ) {
  96. if ( in_array($wordLastVowel, $frontVowels) ) {
  97. $word = implode("",$ar[0]) . "ке";
  98. } elseif ( in_array($wordLastVowel, $backVowels) ) {
  99. $word = implode("",$ar[0]) . "ка";
  100. } else {
  101. }
  102. } else {
  103. if ( in_array($wordLastVowel, $frontVowels) ) {
  104. $word = implode("",$ar[0]) . "ге";
  105. } elseif ( in_array($wordLastVowel, $backVowels) ) {
  106. $word = implode("",$ar[0]) . "га";
  107. } else {
  108. }
  109. }
  110. break;
  111. case "accusative":
  112. if ( in_array($wordEnding, $unvoicedPhonemes) ) {
  113. if ( in_array($wordLastVowel, $roundFrontVowels) ) {
  114. $word = implode("",$ar[0]) . "тү";
  115. } elseif ( in_array($wordLastVowel, $unroundFrontVowels) ) {
  116. $word = implode("",$ar[0]) . "ти";
  117. } elseif ( in_array($wordLastVowel, $roundBackVowels) ) {
  118. $word = implode("",$ar[0]) . "ту";
  119. } elseif ( in_array($wordLastVowel, $unroundBackVowels) ) {
  120. $word = implode("",$ar[0]) . "ты";
  121. } else {
  122. }
  123. } elseif ( $wordEnding === "л" || $wordEnding === "l") {
  124. if ( in_array($wordLastVowel, $roundFrontVowels) ) {
  125. $word = implode("",$ar[0]) . "дү";
  126. } elseif ( in_array($wordLastVowel, $unroundFrontVowels) ) {
  127. $word = implode("",$ar[0]) . "ди";
  128. } elseif ( in_array($wordLastVowel, $roundBackVowels) ) {
  129. $word = implode("",$ar[0]) . "ду";
  130. } elseif ( in_array($wordLastVowel, $unroundBackVowels) ) {
  131. $word = implode("",$ar[0]) . "ды";
  132. } else {
  133. }
  134. } else {
  135. if ( in_array($wordLastVowel, $roundFrontVowels) ) {
  136. $word = implode("",$ar[0]) . "нү";
  137. } elseif ( in_array($wordLastVowel, $unroundFrontVowels) ) {
  138. $word = implode("",$ar[0]) . "ни";
  139. } elseif ( in_array($wordLastVowel, $roundBackVowels) ) {
  140. $word = implode("",$ar[0]) . "ну";
  141. } elseif ( in_array($wordLastVowel, $unroundBackVowels) ) {
  142. $word = implode("",$ar[0]) . "ны";
  143. } else {
  144. }
  145. }
  146. break;
  147. case "locative":
  148. if ( in_array($wordEnding, $unvoicedPhonemes) ) {
  149. if ( in_array($wordLastVowel, $frontVowels) ) {
  150. $word = implode("",$ar[0]) . "те";
  151. } elseif ( in_array($wordLastVowel, $backVowels) ) {
  152. $word = implode("",$ar[0]) . "та";
  153. } else {
  154. }
  155. } else {
  156. if ( in_array($wordLastVowel, $frontVowels) ) {
  157. $word = implode("",$ar[0]) . "де";
  158. } elseif ( in_array($wordLastVowel, $backVowels) ) {
  159. $word = implode("",$ar[0]) . "да";
  160. } else {
  161. }
  162. }
  163. break;
  164. case "ablative":
  165. if ( in_array($wordEnding, $unvoicedPhonemes) ) {
  166. if ( in_array($wordLastVowel, $frontVowels) ) {
  167. $word = implode("",$ar[0]) . "тен";
  168. } elseif ( in_array($wordLastVowel, $backVowels) ) {
  169. $word = implode("",$ar[0]) . "тан";
  170. } else {
  171. }
  172. } else {
  173. if ( in_array($wordLastVowel, $frontVowels) ) {
  174. $word = implode("",$ar[0]) . "ден";
  175. } elseif ( in_array($wordLastVowel, $backVowels) ) {
  176. $word = implode("",$ar[0]) . "дан";
  177. } else {
  178. }
  179. }
  180. break;
  181. case "directive1":
  182. if ( in_array($wordEnding, $directiveVoicedStems) ) {
  183. $word = implode("",$ar[0]) . "же";
  184. } elseif ( in_array($wordEnding, $directiveUnvoicedStems) ) {
  185. $word = implode("",$ar[0]) . "че";
  186. } else {
  187. }
  188. break;
  189. case "directive2":
  190. if ( in_array($wordEnding, $unvoicedPhonemes) ) {
  191. if ( in_array($wordLastVowel, $roundFrontVowels) ) {
  192. $word = implode("",$ar[0]) . "түве";
  193. } elseif ( in_array($wordLastVowel, $unroundFrontVowels) ) {
  194. $word = implode("",$ar[0]) . "тиве";
  195. } elseif ( in_array($wordLastVowel, $roundBackVowels) ) {
  196. $word = implode("",$ar[0]) . "туве";
  197. } elseif ( in_array($wordLastVowel, $unroundBackVowels) ) {
  198. $word = implode("",$ar[0]) . "тыве";
  199. } else {
  200. }
  201. } else {
  202. if ( in_array($wordLastVowel, $roundFrontVowels) ) {
  203. $word = implode("",$ar[0]) . "дүве";
  204. } elseif ( in_array($wordLastVowel, $unroundFrontVowels) ) {
  205. $word = implode("",$ar[0]) . "диве";
  206. } elseif ( in_array($wordLastVowel, $roundBackVowels) ) {
  207. $word = implode("",$ar[0]) . "дуве";
  208. } elseif ( in_array($wordLastVowel, $unroundBackVowels) ) {
  209. $word = implode("",$ar[0]) . "дыве";
  210. } else {
  211. }
  212. }
  213. break;
  214. default:
  215. break;
  216. }
  217. return $word;
  218. }
  219. }