1<?php
2/**
3 * Finnish (Suomi) specific code.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @author Niklas Laxström
22 * @ingroup Language
23 */
24
25use MediaWiki\User\UserIdentity;
26
27/**
28 * Finnish (Suomi)
29 *
30 * @ingroup Language
31 */
32class LanguageFi extends Language {
33	/**
34	 * Convert from the nominative form of a noun to some other case
35	 * Invoked with {{grammar:case|word}}
36	 *
37	 * @param string $word
38	 * @param string $case
39	 * @return string
40	 */
41	public function convertGrammar( $word, $case ) {
42		global $wgGrammarForms;
43		if ( isset( $wgGrammarForms['fi'][$case][$word] ) ) {
44			return $wgGrammarForms['fi'][$case][$word];
45		}
46
47		# These rules don't cover the whole language.
48		# They are used only for site names.
49
50		# wovel harmony flag
51		$aou = preg_match( '/[aou][^äöy]*$/i', $word );
52
53		# The flag should be false for compounds where the last word has only neutral vowels (e/i).
54		# The general case cannot be handled without a dictionary, but there's at least one notable
55		# special case we should check for:
56
57		if ( preg_match( '/wiki$/i', $word ) ) {
58			$aou = false;
59		}
60
61		# append i after final consonant
62		if ( preg_match( '/[bcdfghjklmnpqrstvwxz]$/i', $word ) ) {
63			$word .= 'i';
64		}
65
66		switch ( $case ) {
67			case 'genitive':
68				$word .= 'n';
69				break;
70			case 'elative':
71				$word .= ( $aou ? 'sta' : 'stä' );
72				break;
73			case 'partitive':
74				$word .= ( $aou ? 'a' : 'ä' );
75				break;
76			case 'illative':
77				# Double the last letter and add 'n'
78				$word .= mb_substr( $word, -1 ) . 'n';
79				break;
80			case 'inessive':
81				$word .= ( $aou ? 'ssa' : 'ssä' );
82				break;
83		}
84		return $word;
85	}
86
87	/**
88	 * @param string $str
89	 * @param UserIdentity|null $user User object to use timezone from or null, ignored
90	 * @param int $now Current timestamp, for formatting relative block durations
91	 * @return string
92	 */
93	public function translateBlockExpiry( $str, UserIdentity $user = null, $now = 0 ) {
94		/*
95			'ago', 'now', 'today', 'this', 'next',
96			'first', 'third', 'fourth', 'fifth', 'sixth', 'seventh', 'eighth', 'ninth',
97				'tenth', 'eleventh', 'twelfth',
98			'tomorrow', 'yesterday'
99
100			$months = 'january:tammikuu,february:helmikuu,march:maaliskuu,april:huhtikuu,' .
101				'may:toukokuu,june:kesäkuu,july:heinäkuu,august:elokuu,september:syyskuu,' .
102				'october:lokakuu,november:marraskuu,december:joulukuu,' .
103				'jan:tammikuu,feb:helmikuu,mar:maaliskuu,apr:huhtikuu,jun:kesäkuu,' .
104				'jul:heinäkuu,aug:elokuu,sep:syyskuu,oct:lokakuu,nov:marraskuu,' .
105				dec:joulukuu,sept:syyskuu';
106		*/
107		$weekds = [
108			'monday' => 'maanantai',
109			'tuesday' => 'tiistai',
110			'wednesday' => 'keskiviikko',
111			'thursday' => 'torstai',
112			'friday' => 'perjantai',
113			'saturday' => 'lauantai',
114			'sunday' => 'sunnuntai',
115			'mon' => 'ma',
116			'tue' => 'ti',
117			'tues' => 'ti',
118			'wed' => 'ke',
119			'wednes' => 'ke',
120			'thu' => 'to',
121			'thur' => 'to',
122			'thurs' => 'to',
123			'fri' => 'pe',
124			'sat' => 'la',
125			'sun' => 'su',
126			'next' => 'seuraava',
127			'tomorrow' => 'huomenna',
128			'ago' => 'sitten',
129			'seconds' => 'sekuntia',
130			'second' => 'sekunti',
131			'secs' => 's',
132			'sec' => 's',
133			'minutes' => 'minuuttia',
134			'minute' => 'minuutti',
135			'mins' => 'min',
136			'min' => 'min',
137			'days' => 'päivää',
138			'day' => 'päivä',
139			'hours' => 'tuntia',
140			'hour' => 'tunti',
141			'weeks' => 'viikkoa',
142			'week' => 'viikko',
143			'fortnights' => 'tuplaviikkoa',
144			'fortnight' => 'tuplaviikko',
145			'months' => 'kuukautta',
146			'month' => 'kuukausi',
147			'years' => 'vuotta',
148			'year' => 'vuosi',
149			'infinite' => 'ikuinen',
150			'indefinite' => 'ikuinen',
151			'infinity' => 'ikuinen'
152		];
153
154		$final = '';
155		$tokens = explode( ' ', $str );
156		foreach ( $tokens as $item ) {
157			if ( !is_numeric( $item ) ) {
158				if ( count( explode( '-', $item ) ) == 3 && strlen( $item ) == 10 ) {
159					list( $yyyy, $mm, $dd ) = explode( '-', $item );
160					$final .= ' ' . $this->date( "{$yyyy}{$mm}{$dd}000000" );
161					continue;
162				}
163				if ( isset( $weekds[$item] ) ) {
164					$final .= ' ' . $weekds[$item];
165					continue;
166				}
167			}
168
169			$final .= ' ' . $item;
170		}
171
172		return trim( $final );
173	}
174}
175