Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 59
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
LanguageLa
0.00% covered (danger)
0.00%
0 / 59
0.00% covered (danger)
0.00%
0 / 1
42
0.00% covered (danger)
0.00%
0 / 1
 convertGrammar
0.00% covered (danger)
0.00%
0 / 59
0.00% covered (danger)
0.00%
0 / 1
42
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 * Latin (lingua Latina)
26 *
27 * @ingroup Languages
28 */
29class LanguageLa extends Language {
30    /**
31     * Convert from the nominative form of a noun to some other case
32     *
33     * Just used in a couple places for sitenames; special-case as necessary.
34     * The rules are far from complete.
35     *
36     * Cases: genitive, accusative, ablative
37     *
38     * @param string $word
39     * @param string $case
40     *
41     * @return string
42     */
43    public function convertGrammar( $word, $case ) {
44        $grammarForms =
45            MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::GrammarForms );
46        if ( isset( $grammarForms['la'][$case][$word] ) ) {
47            return $grammarForms['la'][$case][$word];
48        }
49
50        switch ( $case ) {
51            case 'genitive':
52                // only a few declensions, and even for those mostly the singular only
53                $in = [
54                    '/u[ms]$/', # 2nd declension singular
55                    '/ommunia$/', # 3rd declension neuter plural (partly)
56                    '/a$/', # 1st declension singular
57                    '/libri$/', '/nuntii$/', '/datae$/', # 2nd declension plural (partly)
58                    '/tio$/', '/ns$/', '/as$/', # 3rd declension singular (partly)
59                    '/es$/'                              # 5th declension singular
60                ];
61                $out = [
62                    'i',
63                    'ommunium',
64                    'ae',
65                    'librorum', 'nuntiorum', 'datorum',
66                    'tionis', 'ntis', 'atis',
67                    'ei'
68                ];
69                return preg_replace( $in, $out, $word );
70
71            case 'accusative':
72                // only a few declensions, and even for those mostly the singular only
73                $in = [
74                    '/u[ms]$/', # 2nd declension singular
75                    '/a$/', # 1st declension singular
76                    '/ommuniam$/', # 3rd declension neuter plural (partly)
77                    '/libri$/', '/nuntii$/', '/datam$/', # 2nd declension plural (partly)
78                    '/tio$/', '/ns$/', '/as$/', # 3rd declension singular (partly)
79                    '/es$/'                              # 5th declension singular
80                ];
81                $out = [
82                    'um',
83                    'am',
84                    'ommunia',
85                    'libros', 'nuntios', 'data',
86                    'tionem', 'ntem', 'atem',
87                    'em'
88                ];
89                return preg_replace( $in, $out, $word );
90
91            case 'ablative':
92                // only a few declensions, and even for those mostly the singular only
93                $in = [
94                    '/u[ms]$/', # 2nd declension singular
95                    '/ommunia$/', # 3rd declension neuter plural (partly)
96                    '/a$/', # 1st declension singular
97                    '/libri$/', '/nuntii$/', '/data$/', # 2nd declension plural (partly)
98                    '/tio$/', '/ns$/', '/as$/', # 3rd declension singular (partly)
99                    '/es$/'                              # 5th declension singular
100                ];
101                $out = [
102                    'o',
103                    'ommunibus',
104                    'a',
105                    'libris', 'nuntiis', 'datis',
106                    'tione', 'nte', 'ate',
107                    'e'
108                ];
109                return preg_replace( $in, $out, $word );
110
111            default:
112                return $word;
113        }
114    }
115}