MediaWiki
REL1_19
|
00001 <?php 00002 00007 class LanguageUk extends Language { 00008 00017 function convertGrammar( $word, $case ) { 00018 global $wgGrammarForms; 00019 if ( isset( $wgGrammarForms['uk'][$case][$word] ) ) { 00020 return $wgGrammarForms['uk'][$case][$word]; 00021 } 00022 00023 # These rules are not perfect, but they are currently only used for site names so it doesn't 00024 # matter if they are wrong sometimes. Just add a special case for your site name if necessary. 00025 00026 # join and array_slice instead mb_substr 00027 $ar = array(); 00028 preg_match_all( '/./us', $word, $ar ); 00029 if ( !preg_match( "/[a-zA-Z_]/us", $word ) ) 00030 switch ( $case ) { 00031 case 'genitive': # родовий відмінок 00032 if ( ( join( '', array_slice( $ar[0], -4 ) ) == 'вікі' ) || ( join( '', array_slice( $ar[0], -4 ) ) == 'Вікі' ) ) 00033 { } 00034 elseif ( join( '', array_slice( $ar[0], -1 ) ) == 'ь' ) 00035 $word = join( '', array_slice( $ar[0], 0, -1 ) ) . 'я'; 00036 elseif ( join( '', array_slice( $ar[0], -2 ) ) == 'ія' ) 00037 $word = join( '', array_slice( $ar[0], 0, -2 ) ) . 'ії'; 00038 elseif ( join( '', array_slice( $ar[0], -2 ) ) == 'ка' ) 00039 $word = join( '', array_slice( $ar[0], 0, -2 ) ) . 'ки'; 00040 elseif ( join( '', array_slice( $ar[0], -2 ) ) == 'ти' ) 00041 $word = join( '', array_slice( $ar[0], 0, -2 ) ) . 'тей'; 00042 elseif ( join( '', array_slice( $ar[0], -2 ) ) == 'ди' ) 00043 $word = join( '', array_slice( $ar[0], 0, -2 ) ) . 'дів'; 00044 elseif ( join( '', array_slice( $ar[0], -3 ) ) == 'ник' ) 00045 $word = join( '', array_slice( $ar[0], 0, -3 ) ) . 'ника'; 00046 break; 00047 case 'dative': # давальний відмінок 00048 # stub 00049 break; 00050 case 'accusative': # знахідний відмінок 00051 if ( ( join( '', array_slice( $ar[0], -4 ) ) == 'вікі' ) || ( join( '', array_slice( $ar[0], -4 ) ) == 'Вікі' ) ) 00052 { } 00053 elseif ( join( '', array_slice( $ar[0], -2 ) ) == 'ія' ) 00054 $word = join( '', array_slice( $ar[0], 0, -2 ) ) . 'ію'; 00055 break; 00056 case 'instrumental': # орудний відмінок 00057 # stub 00058 break; 00059 case 'prepositional': # місцевий відмінок 00060 # stub 00061 break; 00062 } 00063 return $word; 00064 } 00065 00071 function convertPlural( $count, $forms ) { 00072 if ( !count( $forms ) ) { return ''; } 00073 00074 // If the actual number is not mentioned in the expression, then just two forms are enough: 00075 // singular for $count == 1 00076 // plural for $count != 1 00077 // For example, "This user belongs to {{PLURAL:$1|one group|several groups}}." 00078 if ( count( $forms ) === 2 ) return $count == 1 ? $forms[0] : $forms[1]; 00079 00080 // @todo FIXME: CLDR defines 4 plural forms. Form for decimals is missing/ 00081 // See http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html#uk 00082 $forms = $this->preConvertPlural( $forms, 3 ); 00083 00084 if ( $count > 10 && floor( ( $count % 100 ) / 10 ) == 1 ) { 00085 return $forms[2]; 00086 } else { 00087 switch ( $count % 10 ) { 00088 case 1: return $forms[0]; 00089 case 2: 00090 case 3: 00091 case 4: return $forms[1]; 00092 default: return $forms[2]; 00093 } 00094 } 00095 } 00096 00104 function commafy( $_ ) { 00105 if ( !preg_match( '/^\-?\d{1,4}(\.\d+)?$/', $_ ) ) { 00106 return strrev( (string)preg_replace( '/(\d{3})(?=\d)(?!\d*\.)/', '$1,', strrev( $_ ) ) ); 00107 } else { 00108 return $_; 00109 } 00110 } 00111 }