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