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