Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 84
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
LanguageFi
0.00% covered (danger)
0.00%
0 / 84
0.00% covered (danger)
0.00%
0 / 2
342
0.00% covered (danger)
0.00%
0 / 1
 convertGrammar
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 1
156
 translateBlockExpiry
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 * @author Niklas Laxström
20 */
21
22use MediaWiki\Language\Language;
23use MediaWiki\MainConfigNames;
24use MediaWiki\MediaWikiServices;
25use MediaWiki\User\UserIdentity;
26
27/**
28 * Finnish (Suomi)
29 *
30 * @ingroup Languages
31 */
32class LanguageFi extends Language {
33    public function convertGrammar( $word, $case ) {
34        $grammarForms =
35            MediaWikiServices::getInstance()->getMainConfig()->get( MainConfigNames::GrammarForms );
36        if ( isset( $grammarForms['fi'][$case][$word] ) ) {
37            return $grammarForms['fi'][$case][$word];
38        }
39
40        # These rules don't cover the whole language.
41        # They are used only for site names.
42
43        # vowel harmony flag
44        $aou = preg_match( '/[aou][^äöy]*$/i', $word );
45
46        # The flag should be false for compounds where the last word has only neutral vowels (e/i).
47        # The general case cannot be handled without a dictionary, but there's at least one notable
48        # special case we should check for:
49
50        if ( preg_match( '/wiki$/i', $word ) ) {
51            $aou = false;
52        }
53
54        # append i after final consonant
55        if ( preg_match( '/[bcdfghjklmnpqrstvwxz]$/i', $word ) ) {
56            $word .= 'i';
57        }
58
59        switch ( $case ) {
60            case 'genitive':
61                $word .= 'n';
62                break;
63            case 'elative':
64                $word .= ( $aou ? 'sta' : 'stä' );
65                break;
66            case 'partitive':
67                $word .= ( $aou ? 'a' : 'ä' );
68                break;
69            case 'illative':
70                # Double the last letter and add 'n'
71                $word .= mb_substr( $word, -1 ) . 'n';
72                break;
73            case 'inessive':
74                $word .= ( $aou ? 'ssa' : 'ssä' );
75                break;
76        }
77        return $word;
78    }
79
80    /**
81     * @param string $str
82     * @param UserIdentity|null $user User object to use timezone from or null, ignored
83     * @param int $now Current timestamp, for formatting relative block durations
84     * @return string
85     */
86    public function translateBlockExpiry( $str, ?UserIdentity $user = null, $now = 0 ) {
87        /*
88            'ago', 'now', 'today', 'this', 'next',
89            'first', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth',
90                'tenth', 'eleventh', 'twelfth',
91            'tomorrow', 'yesterday'
92
93            $months = 'january:tammikuu,february:helmikuu,march:maaliskuu,april:huhtikuu,' .
94                'may:toukokuu,june:kesäkuu,july:heinäkuu,august:elokuu,september:syyskuu,' .
95                'october:lokakuu,november:marraskuu,december:joulukuu,' .
96                'jan:tammikuu,feb:helmikuu,mar:maaliskuu,apr:huhtikuu,jun:kesäkuu,' .
97                'jul:heinäkuu,aug:elokuu,sep:syyskuu,oct:lokakuu,nov:marraskuu,' .
98                dec:joulukuu,sept:syyskuu';
99        */
100        $weekds = [
101            'monday' => 'maanantai',
102            'tuesday' => 'tiistai',
103            'wednesday' => 'keskiviikko',
104            'thursday' => 'torstai',
105            'friday' => 'perjantai',
106            'saturday' => 'lauantai',
107            'sunday' => 'sunnuntai',
108            'mon' => 'ma',
109            'tue' => 'ti',
110            'tues' => 'ti',
111            'wed' => 'ke',
112            'wednes' => 'ke',
113            'thu' => 'to',
114            'thur' => 'to',
115            'thurs' => 'to',
116            'fri' => 'pe',
117            'sat' => 'la',
118            'sun' => 'su',
119            'next' => 'seuraava',
120            'tomorrow' => 'huomenna',
121            'ago' => 'sitten',
122            'seconds' => 'sekuntia',
123            'second' => 'sekunti',
124            'secs' => 's',
125            'sec' => 's',
126            'minutes' => 'minuuttia',
127            'minute' => 'minuutti',
128            'mins' => 'min',
129            'min' => 'min',
130            'days' => 'päivää',
131            'day' => 'päivä',
132            'hours' => 'tuntia',
133            'hour' => 'tunti',
134            'weeks' => 'viikkoa',
135            'week' => 'viikko',
136            'fortnights' => 'tuplaviikkoa',
137            'fortnight' => 'tuplaviikko',
138            'months' => 'kuukautta',
139            'month' => 'kuukausi',
140            'years' => 'vuotta',
141            'year' => 'vuosi',
142            'infinite' => 'ikuinen',
143            'indefinite' => 'ikuinen',
144            'infinity' => 'ikuinen'
145        ];
146
147        $final = '';
148        $tokens = explode( ' ', $str );
149        foreach ( $tokens as $item ) {
150            if ( !is_numeric( $item ) ) {
151                if ( count( explode( '-', $item ) ) == 3 && strlen( $item ) == 10 ) {
152                    [ $yyyy, $mm, $dd ] = explode( '-', $item );
153                    $final .= ' ' . $this->date( "{$yyyy}{$mm}{$dd}000000" );
154                    continue;
155                }
156                if ( isset( $weekds[$item] ) ) {
157                    $final .= ' ' . $weekds[$item];
158                    continue;
159                }
160            }
161
162            $final .= ' ' . $item;
163        }
164
165        return trim( $final );
166    }
167}