MediaWiki  REL1_22
LanguageRu.php
Go to the documentation of this file.
00001 <?php
00031 class LanguageRu extends Language {
00032 
00041     function convertGrammar( $word, $case ) {
00042         global $wgGrammarForms;
00043         if ( isset( $wgGrammarForms['ru'][$case][$word] ) ) {
00044             return $wgGrammarForms['ru'][$case][$word];
00045         }
00046 
00047         # These rules are not perfect, but they are currently only used for Wikimedia
00048         # site names so it doesn't matter if they are wrong sometimes.
00049         # Just add a special case for your site name if necessary.
00050 
00051         # substr doesn't support Unicode and mb_substr has issues,
00052         # so break it to characters using preg_match_all and then use array_slice and join
00053         $chars = array();
00054         preg_match_all( '/./us', $word, $chars );
00055         if ( !preg_match( "/[a-zA-Z_]/us", $word ) ) {
00056             switch ( $case ) {
00057                 case 'genitive': # родительный падеж
00058                     if ( join( '', array_slice( $chars[0], -1 ) ) === 'ь' ) {
00059                         $word = join( '', array_slice( $chars[0], 0, -1 ) ) . 'я';
00060                     } elseif ( join( '', array_slice( $chars[0], -2 ) ) === 'ия' ) {
00061                         $word = join( '', array_slice( $chars[0], 0, -2 ) ) . 'ии';
00062                     } elseif ( join( '', array_slice( $chars[0], -2 ) ) === 'ка' ) {
00063                         $word = join( '', array_slice( $chars[0], 0, -2 ) ) . 'ки';
00064                     } elseif ( join( '', array_slice( $chars[0], -2 ) ) === 'ти' ) {
00065                         $word = join( '', array_slice( $chars[0], 0, -2 ) ) . 'тей';
00066                     } elseif ( join( '', array_slice( $chars[0], -2 ) ) === 'ды' ) {
00067                         $word = join( '', array_slice( $chars[0], 0, -2 ) ) . 'дов';
00068                     } elseif ( join( '', array_slice( $chars[0], -3 ) ) === 'ник' ) {
00069                         $word = join( '', array_slice( $chars[0], 0, -3 ) ) . 'ника';
00070                     } elseif ( join( '', array_slice( $chars[0], -3 ) ) === 'ные' ) {
00071                         $word = join( '', array_slice( $chars[0], 0, -3 ) ) . 'ных';
00072                     }
00073                     break;
00074                 case 'dative': # дательный падеж
00075                     # stub
00076                     break;
00077                 case 'accusative': # винительный падеж
00078                     # stub
00079                     break;
00080                 case 'instrumental': # творительный падеж
00081                     # stub
00082                     break;
00083                 case 'prepositional': # предложный падеж
00084                     if ( join( '', array_slice( $chars[0], -1 ) ) === 'ь' ) {
00085                         $word = join( '', array_slice( $chars[0], 0, -1 ) ) . 'е';
00086                     } elseif ( join( '', array_slice( $chars[0], -2 ) ) === 'ия' ) {
00087                         $word = join( '', array_slice( $chars[0], 0, -2 ) ) . 'ии';
00088                     } elseif ( join( '', array_slice( $chars[0], -2 ) ) === 'ка' ) {
00089                         $word = join( '', array_slice( $chars[0], 0, -2 ) ) . 'ке';
00090                     } elseif ( join( '', array_slice( $chars[0], -2 ) ) === 'ти' ) {
00091                         $word = join( '', array_slice( $chars[0], 0, -2 ) ) . 'тях';
00092                     } elseif ( join( '', array_slice( $chars[0], -2 ) ) === 'ды' ) {
00093                         $word = join( '', array_slice( $chars[0], 0, -2 ) ) . 'дах';
00094                     } elseif ( join( '', array_slice( $chars[0], -3 ) ) === 'ник' ) {
00095                         $word = join( '', array_slice( $chars[0], 0, -3 ) ) . 'нике';
00096                     } elseif ( join( '', array_slice( $chars[0], -3 ) ) === 'ные' ) {
00097                         $word = join( '', array_slice( $chars[0], 0, -3 ) ) . 'ных';
00098                     }
00099                     break;
00100             }
00101         }
00102 
00103         return $word;
00104     }
00105 
00115     function commafy( $_ ) {
00116         if ( preg_match( '/^-?\d{1,4}(\.\d*)?$/', $_ ) ) {
00117             return $_;
00118         } else {
00119             return strrev( (string)preg_replace( '/(\d{3})(?=\d)(?!\d*\.)/', '$1,', strrev( $_ ) ) );
00120         }
00121     }
00122 }