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