MediaWiki  REL1_19
LanguageRu.php
Go to the documentation of this file.
00001 <?php
00002 
00009 class LanguageRu extends Language {
00010 
00019         function convertGrammar( $word, $case ) {
00020                 global $wgGrammarForms;
00021                 if ( isset( $wgGrammarForms['ru'][$case][$word] ) ) {
00022                         return $wgGrammarForms['ru'][$case][$word];
00023                 }
00024 
00025                 # These rules are not perfect, but they are currently only used for site names so it doesn't
00026                 # matter if they are wrong sometimes. Just add a special case for your site name if necessary.
00027 
00028                 # join and array_slice instead mb_substr
00029                 $ar = array();
00030                 preg_match_all( '/./us', $word, $ar );
00031                 if ( !preg_match( "/[a-zA-Z_]/us", $word ) )
00032                         switch ( $case ) {
00033                                 case 'genitive': # родительный падеж
00034                                         if ( ( join( '', array_slice( $ar[0], -4 ) ) == 'вики' ) || ( join( '', array_slice( $ar[0], -4 ) ) == 'Вики' ) )
00035                                                 { }
00036                                         elseif ( join( '', array_slice( $ar[0], -1 ) ) == 'ь' )
00037                                                 $word = join( '', array_slice( $ar[0], 0, -1 ) ) . 'я';
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], -2 ) ) == 'ды' )
00045                                                 $word = join( '', array_slice( $ar[0], 0, -2 ) ) . 'дов';
00046                                         elseif ( join( '', array_slice( $ar[0], -3 ) ) == 'ник' )
00047                                                 $word = join( '', array_slice( $ar[0], 0, -3 ) ) . 'ника';
00048                                         break;
00049                                 case 'dative':  # дательный падеж
00050                                         # stub
00051                                         break;
00052                                 case 'accusative': # винительный падеж
00053                                         # stub
00054                                         break;
00055                                 case 'instrumental':  # творительный падеж
00056                                         # stub
00057                                         break;
00058                                 case 'prepositional': # предложный падеж
00059                                         # stub
00060                                         break;
00061                         }
00062                 return $word;
00063         }
00064 
00084         function convertPlural( $count, $forms ) {
00085                 if ( !count( $forms ) ) { return ''; }
00086 
00087                 // If the actual number is not mentioned in the expression, then just two forms are enough:
00088                 // singular for $count == 1
00089                 // plural   for $count != 1
00090                 // For example, "This user belongs to {{PLURAL:$1|one group|several groups}}."
00091                 if ( count( $forms ) === 2 ) return $count == 1 ? $forms[0] : $forms[1];
00092 
00093                 // @todo FIXME: CLDR defines 4 plural forms. Form with decimals missing.
00094                 // See http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html#ru
00095                 $forms = $this->preConvertPlural( $forms, 3 );
00096 
00097                 if ( $count > 10 && floor( ( $count % 100 ) / 10 ) == 1 ) {
00098                         return $forms[2];
00099                 } else {
00100                         switch ( $count % 10 ) {
00101                                 case 1:  return $forms[0];
00102                                 case 2:
00103                                 case 3:
00104                                 case 4:  return $forms[1];
00105                                 default: return $forms[2];
00106                         }
00107                 }
00108         }
00109 
00119         function commafy( $_ ) {
00120                 if ( preg_match( '/^-?\d{1,4}(\.\d*)?$/', $_ ) ) {
00121                         return $_;
00122                 } else {
00123                         return strrev( (string)preg_replace( '/(\d{3})(?=\d)(?!\d*\.)/', '$1,', strrev( $_ ) ) );
00124                 }
00125         }
00126 }