LanguageFi.php 4.7 KB

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