]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - languages/classes/LanguageUk.php
MediaWiki 1.17.4
[autoinstalls/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                 // FIXME: CLDR defines 4 plural forms. Form for decimals is missing/
66                 // See http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html#uk
67                 $forms = $this->preConvertPlural( $forms, 3 );
68
69                 if ( $count > 10 && floor( ( $count % 100 ) / 10 ) == 1 ) {
70                         return $forms[2];
71                 } else {
72                         switch ( $count % 10 ) {
73                                 case 1:  return $forms[0];
74                                 case 2:
75                                 case 3:
76                                 case 4:  return $forms[1];
77                                 default: return $forms[2];
78                         }
79                 }
80         }
81
82         /*
83          * Ukrainian numeric format is "12 345,67" but "1234,56"
84          */
85         function commafy( $_ ) {
86                 if ( !preg_match( '/^\-?\d{1,4}(\.\d+)?$/', $_ ) ) {
87                         return strrev( (string)preg_replace( '/(\d{3})(?=\d)(?!\d*\.)/', '$1,', strrev( $_ ) ) );
88                 } else {
89                         return $_;
90                 }
91         }
92 }