]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - languages/classes/LanguageUk.php
MediaWiki 1.14.0
[autoinstallsdev/mediawiki.git] / languages / classes / LanguageUk.php
1 <?php
2
3 /** Ukrainian (українська мова)
4  *
5  * @ingroup Language
6  */
7 class LanguageUk extends Language {
8         # Convert from the nominative form of a noun to some other case
9         # Invoked with {{grammar:case|word}}
10         function convertGrammar( $word, $case ) {
11                 global $wgGrammarForms;
12                 if ( isset($wgGrammarForms['uk'][$case][$word]) ) {
13                         return $wgGrammarForms['uk'][$case][$word];
14                 }
15
16                 # These rules are not perfect, but they are currently only used for site names so it doesn't
17                 # matter if they are wrong sometimes. Just add a special case for your site name if necessary.
18
19                 #join and array_slice instead mb_substr
20                 $ar = array();
21                 preg_match_all( '/./us', $word, $ar );
22                 if (!preg_match("/[a-zA-Z_]/us", $word))
23                         switch ( $case ) {
24                                 case 'genitive': #родовий відмінок
25                                         if ((join('',array_slice($ar[0],-4))=='вікі') || (join('',array_slice($ar[0],-4))=='Вікі'))
26                                                 {}
27                                         elseif (join('',array_slice($ar[0],-1))=='ь')
28                                                 $word = join('',array_slice($ar[0],0,-1)).'я';
29                                         elseif (join('',array_slice($ar[0],-2))=='ія')
30                                                 $word=join('',array_slice($ar[0],0,-2)).'ії';
31                                         elseif (join('',array_slice($ar[0],-2))=='ка')
32                                                 $word=join('',array_slice($ar[0],0,-2)).'ки';
33                                         elseif (join('',array_slice($ar[0],-2))=='ти')
34                                                 $word=join('',array_slice($ar[0],0,-2)).'тей';
35                                         elseif (join('',array_slice($ar[0],-2))=='ди')
36                                                 $word=join('',array_slice($ar[0],0,-2)).'дів';
37                                         elseif (join('',array_slice($ar[0],-3))=='ник')
38                                                 $word=join('',array_slice($ar[0],0,-3)).'ника';
39                                         break;
40                                 case 'dative':  #давальний відмінок
41                                         #stub
42                                         break;
43                                 case 'accusative': #знахідний відмінок
44                                         if ((join('',array_slice($ar[0],-4))=='вікі') || (join('',array_slice($ar[0],-4))=='Вікі'))
45                                                 {}
46                                         elseif (join('',array_slice($ar[0],-2))=='ія')
47                                                 $word=join('',array_slice($ar[0],0,-2)).'ію';
48                                         break;
49                                 case 'instrumental':  #орудний відмінок
50                                         #stub
51                                         break;
52                                 case 'prepositional': #місцевий відмінок
53                                         #stub
54                                         break;
55                         }
56                 return $word;
57         }
58
59         function convertPlural( $count, $forms ) {
60                 if ( !count($forms) ) { return ''; }
61
62                 //if no number with word, then use $form[0] for singular and $form[1] for plural or zero
63                 if( count($forms) === 2 ) return $count == 1 ? $forms[0] : $forms[1];
64
65                 $forms = $this->preConvertPlural( $forms, 3 );
66
67                 if ($count > 10 && floor(($count % 100) / 10) == 1) {
68                         return $forms[2];
69                 } else {
70                         switch ($count % 10) {
71                                 case 1:  return $forms[0];
72                                 case 2:
73                                 case 3:
74                                 case 4:  return $forms[1];
75                                 default: return $forms[2];
76                         }
77                 }
78         }
79
80         /*
81          * Ukrainian numeric format is "12 345,67" but "1234,56"
82          */
83
84         function commafy($_) {
85                 if (!preg_match('/^\d{1,4}$/',$_)) {
86                         return strrev((string)preg_replace('/(\d{3})(?=\d)(?!\d*\.)/','$1,',strrev($_)));
87                 } else {
88                         return $_;
89                 }
90         }
91 }