00001 <?php
00002
00007 class LanguageUk extends Language {
00008 # Convert from the nominative form of a noun to some other case
00009 # Invoked with {{grammar:case|word}}
00010 function convertGrammar( $word, $case ) {
00011 global $wgGrammarForms;
00012 if ( isset($wgGrammarForms['uk'][$case][$word]) ) {
00013 return $wgGrammarForms['uk'][$case][$word];
00014 }
00015
00016 # These rules are not perfect, but they are currently only used for site names so it doesn't
00017 # matter if they are wrong sometimes. Just add a special case for your site name if necessary.
00018
00019 #join and array_slice instead mb_substr
00020 $ar = array();
00021 preg_match_all( '/./us', $word, $ar );
00022 if (!preg_match("/[a-zA-Z_]/us", $word))
00023 switch ( $case ) {
00024 case 'genitive': #родовий відмінок
00025 if ((join('',array_slice($ar[0],-4))=='вікі') || (join('',array_slice($ar[0],-4))=='Вікі'))
00026 {}
00027 elseif (join('',array_slice($ar[0],-1))=='ь')
00028 $word = join('',array_slice($ar[0],0,-1)).'я';
00029 elseif (join('',array_slice($ar[0],-2))=='ія')
00030 $word=join('',array_slice($ar[0],0,-2)).'ії';
00031 elseif (join('',array_slice($ar[0],-2))=='ка')
00032 $word=join('',array_slice($ar[0],0,-2)).'ки';
00033 elseif (join('',array_slice($ar[0],-2))=='ти')
00034 $word=join('',array_slice($ar[0],0,-2)).'тей';
00035 elseif (join('',array_slice($ar[0],-2))=='ди')
00036 $word=join('',array_slice($ar[0],0,-2)).'дів';
00037 elseif (join('',array_slice($ar[0],-3))=='ник')
00038 $word=join('',array_slice($ar[0],0,-3)).'ника';
00039 break;
00040 case 'dative': #давальний відмінок
00041 #stub
00042 break;
00043 case 'accusative': #знахідний відмінок
00044 if ((join('',array_slice($ar[0],-4))=='вікі') || (join('',array_slice($ar[0],-4))=='Вікі'))
00045 {}
00046 elseif (join('',array_slice($ar[0],-2))=='ія')
00047 $word=join('',array_slice($ar[0],0,-2)).'ію';
00048 break;
00049 case 'instrumental': #орудний відмінок
00050 #stub
00051 break;
00052 case 'prepositional': #місцевий відмінок
00053 #stub
00054 break;
00055 }
00056 return $word;
00057 }
00058
00059 function convertPlural( $count, $forms ) {
00060 if ( !count($forms) ) { return ''; }
00061
00062
00063 if( count($forms) === 2 ) return $count == 1 ? $forms[0] : $forms[1];
00064
00065
00066
00067 $forms = $this->preConvertPlural( $forms, 3 );
00068
00069 if ($count > 10 && floor(($count % 100) / 10) == 1) {
00070 return $forms[2];
00071 } else {
00072 switch ($count % 10) {
00073 case 1: return $forms[0];
00074 case 2:
00075 case 3:
00076 case 4: return $forms[1];
00077 default: return $forms[2];
00078 }
00079 }
00080 }
00081
00082
00083
00084
00085
00086 function commafy($_) {
00087 if (!preg_match('/^\d{1,4}$/',$_)) {
00088 return strrev((string)preg_replace('/(\d{3})(?=\d)(?!\d*\.)/','$1,',strrev($_)));
00089 } else {
00090 return $_;
00091 }
00092 }
00093 }