MediaWiki  REL1_24
LanguageUk.php
Go to the documentation of this file.
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 ) ) == 'вікі' )
00055                         || ( join( '', array_slice( $ar[0], -4 ) ) == 'Вікі' )
00056                     ) {
00057                     } elseif ( join( '', array_slice( $ar[0], -1 ) ) == 'ь' ) {
00058                         $word = join( '', array_slice( $ar[0], 0, -1 ) ) . 'я';
00059                     } elseif ( join( '', array_slice( $ar[0], -2 ) ) == 'ія' ) {
00060                         $word = join( '', array_slice( $ar[0], 0, -2 ) ) . 'ії';
00061                     } elseif ( join( '', array_slice( $ar[0], -2 ) ) == 'ка' ) {
00062                         $word = join( '', array_slice( $ar[0], 0, -2 ) ) . 'ки';
00063                     } elseif ( join( '', array_slice( $ar[0], -2 ) ) == 'ти' ) {
00064                         $word = join( '', array_slice( $ar[0], 0, -2 ) ) . 'тей';
00065                     } elseif ( join( '', array_slice( $ar[0], -2 ) ) == 'ди' ) {
00066                         $word = join( '', array_slice( $ar[0], 0, -2 ) ) . 'дів';
00067                     } elseif ( join( '', array_slice( $ar[0], -3 ) ) == 'ник' ) {
00068                         $word = join( '', array_slice( $ar[0], 0, -3 ) ) . 'ника';
00069                     }
00070                     break;
00071                 case 'dative':  # давальний відмінок
00072                     # stub
00073                     break;
00074                 case 'accusative': # знахідний відмінок
00075                     if ( ( join( '', array_slice( $ar[0], -4 ) ) == 'вікі' )
00076                         || ( join( '', array_slice( $ar[0], -4 ) ) == 'Вікі' )
00077                     ) {
00078                     } elseif ( join( '', array_slice( $ar[0], -2 ) ) == 'ія' ) {
00079                         $word = join( '', array_slice( $ar[0], 0, -2 ) ) . 'ію';
00080                     }
00081                     break;
00082                 case 'instrumental':  # орудний відмінок
00083                     # stub
00084                     break;
00085                 case 'prepositional': # місцевий відмінок
00086                     # stub
00087                     break;
00088             }
00089         }
00090         return $word;
00091     }
00092 
00100     function commafy( $_ ) {
00101         if ( !preg_match( '/^\-?\d{1,4}(\.\d+)?$/', $_ ) ) {
00102             return strrev( (string)preg_replace( '/(\d{3})(?=\d)(?!\d*\.)/', '$1,', strrev( $_ ) ) );
00103         } else {
00104             return $_;
00105         }
00106     }
00107 }