Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 137
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
LanguageTyv
0.00% covered (danger)
0.00%
0 / 137
0.00% covered (danger)
0.00%
0 / 1
4422
0.00% covered (danger)
0.00%
0 / 1
 convertGrammar
0.00% covered (danger)
0.00%
0 / 137
0.00% covered (danger)
0.00%
0 / 1
4422
1<?php
2/**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21use MediaWiki\MainConfigNames;
22use MediaWiki\MediaWikiServices;
23
24/**
25 * Tyvan localization (Тыва дыл)
26 *
27 * From friends at tyvawiki.org
28 *
29 * @ingroup Languages
30 */
31class LanguageTyv extends Language {
32
33    public function convertGrammar( $word, $case ) {
34        $grammarForms =
35            MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::GrammarForms );
36        if ( isset( $grammarForms['tyv'][$case][$word] ) ) {
37            return $grammarForms['tyv'][$case][$word];
38        }
39
40        // Set up some constants...
41        $allVowels = [ "е", "и", "э", "ө", "ү", "а", "ё", "о", "у", "ы", "ю", "я" ];
42        $frontVowels = [ "е", "и", "э", "ө", "ү" ];
43        $backVowels = [ "а", "ё", "о", "у", "ы", "ю", "я" ];
44        $unroundFrontVowels = [ "е", "и", "э" ];
45        $roundFrontVowels = [ "ө", "ү" ];
46        $unroundBackVowels = [ "а", "ы", "я" ];
47        $roundBackVowels = [ "ё", "о", "у", "ю" ];
48        $unvoicedPhonemes = [ "т", "п", "с", "ш", "к", "ч", "х" ];
49        $directiveUnvoicedStems = [ "т", "п", "с", "ш", "к", "ч", "х", "л", "м", "н", "ң" ];
50        $directiveVoicedStems = [ "д", "б", "з", "ж", "г", "р", "й" ];
51
52        // Put the word in a form we can play with since we're using UTF-8
53        $ar = mb_str_split( $word, 1 );
54
55        // Here's the last letter in the word
56        $wordEnding = end( $ar );
57
58        // Find the last vowel in the word
59        $wordLastVowel = null;
60        for ( $i = count( $ar ); $i--; ) {
61            if ( in_array( $ar[$i], $allVowels, true ) ) {
62                $wordLastVowel = $ar[$i];
63                break;
64            }
65        }
66
67        // Now convert the word
68        switch ( $case ) {
69            case "genitive":
70                if ( in_array( $wordEnding, $unvoicedPhonemes ) ) {
71                    if ( in_array( $wordLastVowel, $roundFrontVowels ) ) {
72                        $word .= "түң";
73                    } elseif ( in_array( $wordLastVowel, $unroundFrontVowels ) ) {
74                        $word .= "тиң";
75                    } elseif ( in_array( $wordLastVowel, $roundBackVowels ) ) {
76                        $word .= "туң";
77                    } elseif ( in_array( $wordLastVowel, $unroundBackVowels ) ) {
78                        $word .= "тың";
79                    }
80                } elseif ( $wordEnding === "л" ) {
81                    if ( in_array( $wordLastVowel, $roundFrontVowels ) ) {
82                        $word .= "дүң";
83                    } elseif ( in_array( $wordLastVowel, $unroundFrontVowels ) ) {
84                        $word .= "диң";
85                    } elseif ( in_array( $wordLastVowel, $roundBackVowels ) ) {
86                        $word .= "дуң";
87                    } elseif ( in_array( $wordLastVowel, $unroundBackVowels ) ) {
88                        $word .= "дың";
89                    }
90                } else {
91                    if ( in_array( $wordLastVowel, $roundFrontVowels ) ) {
92                        $word .= "нүң";
93                    } elseif ( in_array( $wordLastVowel, $unroundFrontVowels ) ) {
94                        $word .= "ниң";
95                    } elseif ( in_array( $wordLastVowel, $roundBackVowels ) ) {
96                        $word .= "нуң";
97                    } elseif ( in_array( $wordLastVowel, $unroundBackVowels ) ) {
98                        $word .= "ның";
99                    }
100                }
101                break;
102
103            case "dative":
104                if ( in_array( $wordEnding, $unvoicedPhonemes ) ) {
105                    if ( in_array( $wordLastVowel, $frontVowels ) ) {
106                        $word .= "ке";
107                    } elseif ( in_array( $wordLastVowel, $backVowels ) ) {
108                        $word .= "ка";
109                    }
110                } else {
111                    if ( in_array( $wordLastVowel, $frontVowels ) ) {
112                        $word .= "ге";
113                    } elseif ( in_array( $wordLastVowel, $backVowels ) ) {
114                        $word .= "га";
115                    }
116                }
117                break;
118
119            case "accusative":
120                if ( in_array( $wordEnding, $unvoicedPhonemes ) ) {
121                    if ( in_array( $wordLastVowel, $roundFrontVowels ) ) {
122                        $word .= "тү";
123                    } elseif ( in_array( $wordLastVowel, $unroundFrontVowels ) ) {
124                        $word .= "ти";
125                    } elseif ( in_array( $wordLastVowel, $roundBackVowels ) ) {
126                        $word .= "ту";
127                    } elseif ( in_array( $wordLastVowel, $unroundBackVowels ) ) {
128                        $word .= "ты";
129                    }
130                } elseif ( $wordEnding === "л" ) {
131                    if ( in_array( $wordLastVowel, $roundFrontVowels ) ) {
132                        $word .= "дү";
133                    } elseif ( in_array( $wordLastVowel, $unroundFrontVowels ) ) {
134                        $word .= "ди";
135                    } elseif ( in_array( $wordLastVowel, $roundBackVowels ) ) {
136                        $word .= "ду";
137                    } elseif ( in_array( $wordLastVowel, $unroundBackVowels ) ) {
138                        $word .= "ды";
139                    }
140                } else {
141                    if ( in_array( $wordLastVowel, $roundFrontVowels ) ) {
142                        $word .= "нү";
143                    } elseif ( in_array( $wordLastVowel, $unroundFrontVowels ) ) {
144                        $word .= "ни";
145                    } elseif ( in_array( $wordLastVowel, $roundBackVowels ) ) {
146                        $word .= "ну";
147                    } elseif ( in_array( $wordLastVowel, $unroundBackVowels ) ) {
148                        $word .= "ны";
149                    }
150                }
151                break;
152
153            case "locative":
154                if ( in_array( $wordEnding, $unvoicedPhonemes ) ) {
155                    if ( in_array( $wordLastVowel, $frontVowels ) ) {
156                        $word .= "те";
157                    } elseif ( in_array( $wordLastVowel, $backVowels ) ) {
158                        $word .= "та";
159                    }
160                } else {
161                    if ( in_array( $wordLastVowel, $frontVowels ) ) {
162                        $word .= "де";
163                    } elseif ( in_array( $wordLastVowel, $backVowels ) ) {
164                        $word .= "да";
165                    }
166                }
167                break;
168
169            case "ablative":
170                if ( in_array( $wordEnding, $unvoicedPhonemes ) ) {
171                    if ( in_array( $wordLastVowel, $frontVowels ) ) {
172                        $word .= "тен";
173                    } elseif ( in_array( $wordLastVowel, $backVowels ) ) {
174                        $word .= "тан";
175                    }
176                } else {
177                    if ( in_array( $wordLastVowel, $frontVowels ) ) {
178                        $word .= "ден";
179                    } elseif ( in_array( $wordLastVowel, $backVowels ) ) {
180                        $word .= "дан";
181                    }
182                }
183                break;
184
185            case "directive1":
186                if ( in_array( $wordEnding, $directiveVoicedStems ) ) {
187                    $word .= "же";
188                } elseif ( in_array( $wordEnding, $directiveUnvoicedStems ) ) {
189                    $word .= "че";
190                }
191                break;
192
193            case "directive2":
194                if ( in_array( $wordEnding, $unvoicedPhonemes ) ) {
195                    if ( in_array( $wordLastVowel, $roundFrontVowels ) ) {
196                        $word .= "түве";
197                    } elseif ( in_array( $wordLastVowel, $unroundFrontVowels ) ) {
198                        $word .= "тиве";
199                    } elseif ( in_array( $wordLastVowel, $roundBackVowels ) ) {
200                        $word .= "туве";
201                    } elseif ( in_array( $wordLastVowel, $unroundBackVowels ) ) {
202                        $word .= "тыве";
203                    }
204                } else {
205                    if ( in_array( $wordLastVowel, $roundFrontVowels ) ) {
206                        $word .= "дүве";
207                    } elseif ( in_array( $wordLastVowel, $unroundFrontVowels ) ) {
208                        $word .= "диве";
209                    } elseif ( in_array( $wordLastVowel, $roundBackVowels ) ) {
210                        $word .= "дуве";
211                    } elseif ( in_array( $wordLastVowel, $unroundBackVowels ) ) {
212                        $word .= "дыве";
213                    }
214                }
215                break;
216
217            default:
218                break;
219        }
220
221        return $word;
222    }
223}