MediaWiki  master
LanguageTyv.php
Go to the documentation of this file.
1 <?php
23 
31 class LanguageTyv extends Language {
40  public function convertGrammar( $word, $case ) {
41  $grammarForms =
42  MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::GrammarForms );
43  if ( isset( $grammarForms['tyv'][$case][$word] ) ) {
44  return $grammarForms['tyv'][$case][$word];
45  }
46 
47  // Set up some constants...
48  $allVowels = [ "е", "и", "э", "ө", "ү", "а", "ё", "о", "у", "ы", "ю", "я" ];
49  $frontVowels = [ "е", "и", "э", "ө", "ү" ];
50  $backVowels = [ "а", "ё", "о", "у", "ы", "ю", "я" ];
51  $unroundFrontVowels = [ "е", "и", "э" ];
52  $roundFrontVowels = [ "ө", "ү" ];
53  $unroundBackVowels = [ "а", "ы", "я" ];
54  $roundBackVowels = [ "ё", "о", "у", "ю" ];
55  $unvoicedPhonemes = [ "т", "п", "с", "ш", "к", "ч", "х" ];
56  $directiveUnvoicedStems = [ "т", "п", "с", "ш", "к", "ч", "х", "л", "м", "н", "ң" ];
57  $directiveVoicedStems = [ "д", "б", "з", "ж", "г", "р", "й" ];
58 
59  // Put the word in a form we can play with since we're using UTF-8
60  $ar = mb_str_split( $word, 1 );
61 
62  // Here's the last letter in the word
63  $wordEnding = end( $ar );
64 
65  // Find the last vowel in the word
66  $wordLastVowel = null;
67  for ( $i = count( $ar ); $i--; ) {
68  if ( in_array( $ar[$i], $allVowels, true ) ) {
69  $wordLastVowel = $ar[$i];
70  break;
71  }
72  }
73 
74  // Now convert the word
75  switch ( $case ) {
76  case "genitive":
77  if ( in_array( $wordEnding, $unvoicedPhonemes ) ) {
78  if ( in_array( $wordLastVowel, $roundFrontVowels ) ) {
79  $word = $word . "түң";
80  } elseif ( in_array( $wordLastVowel, $unroundFrontVowels ) ) {
81  $word = $word . "тиң";
82  } elseif ( in_array( $wordLastVowel, $roundBackVowels ) ) {
83  $word = $word . "туң";
84  } elseif ( in_array( $wordLastVowel, $unroundBackVowels ) ) {
85  $word = $word . "тың";
86  }
87  } elseif ( $wordEnding === "л" ) {
88  if ( in_array( $wordLastVowel, $roundFrontVowels ) ) {
89  $word = $word . "дүң";
90  } elseif ( in_array( $wordLastVowel, $unroundFrontVowels ) ) {
91  $word = $word . "диң";
92  } elseif ( in_array( $wordLastVowel, $roundBackVowels ) ) {
93  $word = $word . "дуң";
94  } elseif ( in_array( $wordLastVowel, $unroundBackVowels ) ) {
95  $word = $word . "дың";
96  }
97  } else {
98  if ( in_array( $wordLastVowel, $roundFrontVowels ) ) {
99  $word = $word . "нүң";
100  } elseif ( in_array( $wordLastVowel, $unroundFrontVowels ) ) {
101  $word = $word . "ниң";
102  } elseif ( in_array( $wordLastVowel, $roundBackVowels ) ) {
103  $word = $word . "нуң";
104  } elseif ( in_array( $wordLastVowel, $unroundBackVowels ) ) {
105  $word = $word . "ның";
106  }
107  }
108  break;
109  case "dative":
110  if ( in_array( $wordEnding, $unvoicedPhonemes ) ) {
111  if ( in_array( $wordLastVowel, $frontVowels ) ) {
112  $word = $word . "ке";
113  } elseif ( in_array( $wordLastVowel, $backVowels ) ) {
114  $word = $word . "ка";
115  }
116  } else {
117  if ( in_array( $wordLastVowel, $frontVowels ) ) {
118  $word = $word . "ге";
119  } elseif ( in_array( $wordLastVowel, $backVowels ) ) {
120  $word = $word . "га";
121  }
122  }
123  break;
124  case "accusative":
125  if ( in_array( $wordEnding, $unvoicedPhonemes ) ) {
126  if ( in_array( $wordLastVowel, $roundFrontVowels ) ) {
127  $word = $word . "тү";
128  } elseif ( in_array( $wordLastVowel, $unroundFrontVowels ) ) {
129  $word = $word . "ти";
130  } elseif ( in_array( $wordLastVowel, $roundBackVowels ) ) {
131  $word = $word . "ту";
132  } elseif ( in_array( $wordLastVowel, $unroundBackVowels ) ) {
133  $word = $word . "ты";
134  }
135  } elseif ( $wordEnding === "л" ) {
136  if ( in_array( $wordLastVowel, $roundFrontVowels ) ) {
137  $word = $word . "дү";
138  } elseif ( in_array( $wordLastVowel, $unroundFrontVowels ) ) {
139  $word = $word . "ди";
140  } elseif ( in_array( $wordLastVowel, $roundBackVowels ) ) {
141  $word = $word . "ду";
142  } elseif ( in_array( $wordLastVowel, $unroundBackVowels ) ) {
143  $word = $word . "ды";
144  }
145  } else {
146  if ( in_array( $wordLastVowel, $roundFrontVowels ) ) {
147  $word = $word . "нү";
148  } elseif ( in_array( $wordLastVowel, $unroundFrontVowels ) ) {
149  $word = $word . "ни";
150  } elseif ( in_array( $wordLastVowel, $roundBackVowels ) ) {
151  $word = $word . "ну";
152  } elseif ( in_array( $wordLastVowel, $unroundBackVowels ) ) {
153  $word = $word . "ны";
154  }
155  }
156  break;
157  case "locative":
158  if ( in_array( $wordEnding, $unvoicedPhonemes ) ) {
159  if ( in_array( $wordLastVowel, $frontVowels ) ) {
160  $word = $word . "те";
161  } elseif ( in_array( $wordLastVowel, $backVowels ) ) {
162  $word = $word . "та";
163  }
164  } else {
165  if ( in_array( $wordLastVowel, $frontVowels ) ) {
166  $word = $word . "де";
167  } elseif ( in_array( $wordLastVowel, $backVowels ) ) {
168  $word = $word . "да";
169  }
170  }
171  break;
172  case "ablative":
173  if ( in_array( $wordEnding, $unvoicedPhonemes ) ) {
174  if ( in_array( $wordLastVowel, $frontVowels ) ) {
175  $word = $word . "тен";
176  } elseif ( in_array( $wordLastVowel, $backVowels ) ) {
177  $word = $word . "тан";
178  }
179  } else {
180  if ( in_array( $wordLastVowel, $frontVowels ) ) {
181  $word = $word . "ден";
182  } elseif ( in_array( $wordLastVowel, $backVowels ) ) {
183  $word = $word . "дан";
184  }
185  }
186  break;
187  case "directive1":
188  if ( in_array( $wordEnding, $directiveVoicedStems ) ) {
189  $word = $word . "же";
190  } elseif ( in_array( $wordEnding, $directiveUnvoicedStems ) ) {
191  $word = $word . "че";
192  }
193  break;
194  case "directive2":
195  if ( in_array( $wordEnding, $unvoicedPhonemes ) ) {
196  if ( in_array( $wordLastVowel, $roundFrontVowels ) ) {
197  $word = $word . "түве";
198  } elseif ( in_array( $wordLastVowel, $unroundFrontVowels ) ) {
199  $word = $word . "тиве";
200  } elseif ( in_array( $wordLastVowel, $roundBackVowels ) ) {
201  $word = $word . "туве";
202  } elseif ( in_array( $wordLastVowel, $unroundBackVowels ) ) {
203  $word = $word . "тыве";
204  }
205  } else {
206  if ( in_array( $wordLastVowel, $roundFrontVowels ) ) {
207  $word = $word . "дүве";
208  } elseif ( in_array( $wordLastVowel, $unroundFrontVowels ) ) {
209  $word = $word . "диве";
210  } elseif ( in_array( $wordLastVowel, $roundBackVowels ) ) {
211  $word = $word . "дуве";
212  } elseif ( in_array( $wordLastVowel, $unroundBackVowels ) ) {
213  $word = $word . "дыве";
214  }
215  }
216  break;
217  default:
218  break;
219  }
220 
221  return $word;
222  }
223 }
Tyvan localization (Тыва дыл)
Definition: LanguageTyv.php:31
convertGrammar( $word, $case)
Grammatical transformations, needed for inflected languages Invoked by putting {{grammar:case|word}} ...
Definition: LanguageTyv.php:40
Base class for language-specific code.
Definition: Language.php:61
A class containing constants representing the names of configuration variables.
Service locator for MediaWiki core services.