| 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 Purodha Blissenbach |
| 20 | */ |
| 21 | |
| 22 | use MediaWiki\Language\Language; |
| 23 | |
| 24 | /** |
| 25 | * Ripuarian (Ripoarėsh) |
| 26 | * |
| 27 | * @ingroup Languages |
| 28 | */ |
| 29 | class LanguageKsh extends Language { |
| 30 | /** |
| 31 | * Do not add male wiki families, since that's the default. |
| 32 | * No need to add neuter to wikis having names ending in "-wiki". |
| 33 | */ |
| 34 | private const FAMILYGENDER = [ |
| 35 | 'wikipedia' => 'f', |
| 36 | 'wikiversity' => 'f', |
| 37 | 'wiktionary' => 'n', |
| 38 | 'wikibooks' => 'n', |
| 39 | 'wikiquote' => 'n', |
| 40 | 'wikisource' => 'n', |
| 41 | 'wikitravel' => 'n', |
| 42 | 'wikia' => 'f', |
| 43 | 'translatewiki.net' => 'n', |
| 44 | ]; |
| 45 | |
| 46 | /** |
| 47 | * @inheritDoc |
| 48 | * |
| 49 | * $case is a sequence of words, each of which is case insensitive. |
| 50 | * There must be at least one space character between words. |
| 51 | * Only the 1st character of each word is considered. |
| 52 | * Word order is irrelevant. |
| 53 | * |
| 54 | * Possible values specifying the grammatical case are: |
| 55 | * 1, Nominative |
| 56 | * 2, Genitive |
| 57 | * 3, Dative |
| 58 | * 4, Accusative, -omitted- |
| 59 | * |
| 60 | * Possible values specifying the article type are: |
| 61 | * Betoont focussed or stressed article |
| 62 | * -omitted- unstressed or unfocused article |
| 63 | * |
| 64 | * Possible values for the type of genitive are: |
| 65 | * Sing, Iehr prepositioned genitive = possessive dative |
| 66 | * Vun, Fon, -omitted- postpositioned genitive = preposition "vun" with dative |
| 67 | * |
| 68 | * Values of case overrides & prepositions, in the order of precedence: |
| 69 | * Sing, Iehr possessive dative = prepositioned genitive |
| 70 | * Vun, Fon preposition "vun" with dative = post positioned genitive |
| 71 | * En, em preposition "en" with dative |
| 72 | * |
| 73 | * Values for object gender specifiers of the possessive dative, or |
| 74 | * prepositioned genitive, evaluated with "Sing, Iehr" of above only: |
| 75 | * Male a singular male object follows |
| 76 | * -omitted- a non-male or plural object follows |
| 77 | * |
| 78 | * We currently handle definite articles of the singular only. |
| 79 | * There is a full set of test cases at: |
| 80 | * http://translatewiki.net/wiki/Portal:Ksh#GRAMMAR_Pr%C3%B6%C3%B6fe |
| 81 | * Contents of the leftmost table column can be copied and pasted as |
| 82 | * "case" values. |
| 83 | */ |
| 84 | public function convertGrammar( $word, $case ) { |
| 85 | $lord = strtolower( $word ); |
| 86 | $gender = 'm'; // Nuutnaarel // default |
| 87 | if ( preg_match( '/wiki$/', $lord ) ) { |
| 88 | $gender = 'n'; // Dat xyz-wiki |
| 89 | } |
| 90 | if ( isset( self::FAMILYGENDER[$lord] ) ) { |
| 91 | $gender = self::FAMILYGENDER[$lord]; |
| 92 | } |
| 93 | |
| 94 | $isGenderFemale = $gender === 'f'; |
| 95 | |
| 96 | $case = ' ' . strtolower( $case ); |
| 97 | if ( preg_match( '/ [is]/', $case ) ) { |
| 98 | # däm WikiMaatplaz singe, dä Wikipeedija iere, däm Wikiwööterbooch singe |
| 99 | # dem/em WikiMaatplaz singe, de Wikipeedija iere, dem/em Wikiwööterbooch singe |
| 100 | # däm WikiMaatplaz sing, dä Wikipeedija ier, däm Wikiwööterbooch sing |
| 101 | # dem/em WikiMaatplaz sing, de Wikipeedija ier, dem/em Wikiwööterbooch sing |
| 102 | $word = ( preg_match( '/ b/', $case ) |
| 103 | ? ( $isGenderFemale ? 'dä' : 'däm' ) |
| 104 | : ( $isGenderFemale ? 'de' : 'dem' ) |
| 105 | ) . ' ' . $word . ' ' . |
| 106 | ( $isGenderFemale ? 'ier' : 'sing' ) . |
| 107 | ( preg_match( '/ m/', $case ) ? 'e' : '' ); |
| 108 | } elseif ( preg_match( '/ e/', $case ) ) { |
| 109 | # en dämm WikiMaatPlaz, en dä Wikipeedija, en dämm Wikiwööterbooch |
| 110 | # em WikiMaatplaz, en de Wikipeedija, em Wikiwööterbooch |
| 111 | if ( preg_match( '/ b/', $case ) ) { |
| 112 | $word = 'en ' . ( $isGenderFemale ? 'dä' : 'däm' ) . ' ' . $word; |
| 113 | } else { |
| 114 | $word = ( $isGenderFemale ? 'en de' : 'em' ) . ' ' . $word; |
| 115 | } |
| 116 | } elseif ( preg_match( '/ [fv]/', $case ) || preg_match( '/ [2jg]/', $case ) ) { |
| 117 | # vun däm WikiMaatplaz, vun dä Wikipeedija, vun däm Wikiwööterbooch |
| 118 | # vum WikiMaatplaz, vun de Wikipeedija, vum Wikiwööterbooch |
| 119 | if ( preg_match( '/ b/', $case ) ) { |
| 120 | $word = 'vun ' . ( $isGenderFemale ? 'dä' : 'däm' ) . ' ' . $word; |
| 121 | } else { |
| 122 | $word = ( $isGenderFemale ? 'vun de' : 'vum' ) . ' ' . $word; |
| 123 | } |
| 124 | } elseif ( preg_match( '/ [3d]/', $case ) ) { |
| 125 | # dämm WikiMaatPlaz, dä Wikipeedija, dämm Wikiwööterbooch |
| 126 | # dem/em WikiMaatplaz, de Wikipeedija, dem/em Wikiwööterbooch |
| 127 | if ( preg_match( '/ b/', $case ) ) { |
| 128 | $word = ( $isGenderFemale ? 'dää' : 'dämm' ) . ' ' . $word; |
| 129 | } else { |
| 130 | $word = ( $isGenderFemale ? 'de' : 'dem' ) . ' ' . $word; |
| 131 | } |
| 132 | } else { |
| 133 | # dä WikiMaatPlaz, di Wikipeedija, dat Wikiwööterbooch |
| 134 | # der WikiMaatplaz, de Wikipeedija, et Wikiwööterbooch |
| 135 | if ( preg_match( '/ b/', $case ) ) { |
| 136 | switch ( $gender ) { |
| 137 | case 'm': |
| 138 | $lord = 'dä'; |
| 139 | break; |
| 140 | case 'f': |
| 141 | $lord = 'di'; |
| 142 | break; |
| 143 | default: |
| 144 | $lord = 'dat'; |
| 145 | } |
| 146 | } else { |
| 147 | switch ( $gender ) { |
| 148 | case 'm': |
| 149 | $lord = 'der'; |
| 150 | break; |
| 151 | case 'f': |
| 152 | $lord = 'de'; |
| 153 | break; |
| 154 | default: |
| 155 | $lord = 'et'; |
| 156 | } |
| 157 | } |
| 158 | $word = $lord . ' ' . $word; |
| 159 | } |
| 160 | return $word; |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * Handle cases of (1, other, 0) or (1, other) |
| 165 | * |
| 166 | * @param int $count |
| 167 | * @param array $forms |
| 168 | * |
| 169 | * @return string |
| 170 | */ |
| 171 | public function convertPlural( $count, $forms ) { |
| 172 | $forms = $this->handleExplicitPluralForms( $count, $forms ); |
| 173 | if ( is_string( $forms ) ) { |
| 174 | return $forms; |
| 175 | } |
| 176 | if ( !count( $forms ) ) { |
| 177 | return ''; |
| 178 | } |
| 179 | $forms = $this->preConvertPlural( $forms, 3 ); |
| 180 | |
| 181 | if ( $count === 1 ) { |
| 182 | return $forms[0]; |
| 183 | } |
| 184 | |
| 185 | if ( $count === 0 ) { |
| 186 | return $forms[2]; |
| 187 | } |
| 188 | |
| 189 | return $forms[1]; |
| 190 | } |
| 191 | } |