Merge "LocalFileTest does not require database access"
[lhc/web/wiklou.git] / languages / classes / LanguageOs.php
1 <?php
2 /**
3 * Ossetian (Ирон) 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 * @author Soslan Khubulov
22 * @ingroup Language
23 */
24
25 /**
26 * Ossetian (Ирон)
27 *
28 * @ingroup Language
29 */
30 class LanguageOs extends Language {
31
32 /**
33 * Convert from the nominative form of a noun to other cases
34 * Invoked with {{grammar:case|word}}
35 *
36 * Depending on word there are four different ways of converting to other cases.
37 * 1) Word consist of not cyrillic letters or is an abbreviation.
38 * Then result word is: word + hyphen + case ending.
39 *
40 * 2) Word consist of cyrillic letters.
41 * 2.1) Word is in plural.
42 * Then result word is: word - last letter + case ending. Ending of allative case here is 'æм'.
43 *
44 * 2.2) Word is in singular.
45 * 2.2.1) Word ends on consonant.
46 * Then result word is: word + case ending.
47 *
48 * 2.2.2) Word ends on vowel.
49 * Then result word is: word + 'й' + case ending for cases != allative or comitative
50 * and word + case ending for allative or comitative. Ending of allative case here is 'æ'.
51 *
52 * @param string $word
53 * @param string $case
54 * @return string
55 */
56 function convertGrammar( $word, $case ) {
57 global $wgGrammarForms;
58 if ( isset( $wgGrammarForms['os'][$case][$word] ) ) {
59 return $wgGrammarForms['os'][$case][$word];
60 }
61 # Ending for allative case
62 $end_allative = 'мæ';
63 # Variable for 'j' beetwen vowels
64 $jot = '';
65 # Variable for "-" for not Ossetic words
66 $hyphen = '';
67 # Variable for ending
68 $ending = '';
69
70 # CHecking if the $word is in plural form
71 if ( preg_match( '/тæ$/u', $word ) ) {
72 $word = mb_substr( $word, 0, -1 );
73 $end_allative = 'æм';
74 }
75 # Works if $word is in singular form.
76 # Checking if $word ends on one of the vowels: е, ё, и, о, ы, э, ю, я.
77 elseif ( preg_match( "/[аæеёиоыэюя]$/u", $word ) ) {
78 $jot = 'й';
79 }
80 # Checking if $word ends on 'у'. 'У' can be either consonant 'W' or vowel 'U' in cyrillic Ossetic.
81 # Examples: {{grammar:genitive|аунеу}} = аунеуы, {{grammar:genitive|лæппу}} = лæппуйы.
82 elseif ( preg_match( "/у$/u", $word ) ) {
83 if ( !preg_match( "/[аæеёиоыэюя]$/u", mb_substr( $word, -2, 1 ) ) ) {
84 $jot = 'й';
85 }
86 } elseif ( !preg_match( "/[бвгджзйклмнопрстфхцчшщьъ]$/u", $word ) ) {
87 $hyphen = '-';
88 }
89
90 switch ( $case ) {
91 case 'genitive':
92 $ending = $hyphen . $jot . 'ы';
93 break;
94 case 'dative':
95 $ending = $hyphen . $jot . 'æн';
96 break;
97 case 'allative':
98 $ending = $hyphen . $end_allative;
99 break;
100 case 'ablative':
101 if ( $jot == 'й' ) {
102 $ending = $hyphen . $jot . 'æ';
103 } else {
104 $ending = $hyphen . $jot . 'æй';
105 }
106 break;
107 case 'inessive':
108 break;
109 case 'superessive':
110 $ending = $hyphen . $jot . 'ыл';
111 break;
112 case 'equative':
113 $ending = $hyphen . $jot . 'ау';
114 break;
115 case 'comitative':
116 $ending = $hyphen . 'имæ';
117 break;
118 }
119 return $word . $ending;
120 }
121 }