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