3 /** Ukrainian (українська мова)
7 class LanguageUk
extends Language
{
10 * Convert from the nominative form of a noun to some other case
11 * Invoked with {{grammar:case|word}}
17 function convertGrammar( $word, $case ) {
18 global $wgGrammarForms;
19 if ( isset( $wgGrammarForms['uk'][$case][$word] ) ) {
20 return $wgGrammarForms['uk'][$case][$word];
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.
26 # join and array_slice instead mb_substr
28 preg_match_all( '/./us', $word, $ar );
29 if ( !preg_match( "/[a-zA-Z_]/us", $word ) )
31 case 'genitive': # родовий відмінок
32 if ( ( join( '', array_slice( $ar[0], -4 ) ) == 'вікі' ) ||
( join( '', array_slice( $ar[0], -4 ) ) == 'Вікі' ) )
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 ) ) . 'ника';
47 case 'dative': # давальний відмінок
50 case 'accusative': # знахідний відмінок
51 if ( ( join( '', array_slice( $ar[0], -4 ) ) == 'вікі' ) ||
( join( '', array_slice( $ar[0], -4 ) ) == 'Вікі' ) )
53 elseif ( join( '', array_slice( $ar[0], -2 ) ) == 'ія' )
54 $word = join( '', array_slice( $ar[0], 0, -2 ) ) . 'ію';
56 case 'instrumental': # орудний відмінок
59 case 'prepositional': # місцевий відмінок
71 function convertPlural( $count, $forms ) {
72 if ( !count( $forms ) ) { return ''; }
74 // If the actual number is not mentioned in the expression, then just two forms are enough:
75 // singular for $count == 1
76 // plural for $count != 1
77 // For example, "This user belongs to {{PLURAL:$1|one group|several groups}}."
78 if ( count( $forms ) === 2 ) return $count == 1 ?
$forms[0] : $forms[1];
80 // @todo FIXME: CLDR defines 4 plural forms. Form for decimals is missing/
81 // See http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html#uk
82 $forms = $this->preConvertPlural( $forms, 3 );
84 if ( $count > 10 && floor( ( $count %
100 ) / 10 ) == 1 ) {
87 switch ( $count %
10 ) {
88 case 1: return $forms[0];
91 case 4: return $forms[1];
92 default: return $forms[2];
98 * Ukrainian numeric format is "12 345,67" but "1234,56"
104 function commafy( $_ ) {
105 if ( !preg_match( '/^\-?\d{1,4}(\.\d+)?$/', $_ ) ) {
106 return strrev( (string)preg_replace( '/(\d{3})(?=\d)(?!\d*\.)/', '$1,', strrev( $_ ) ) );