3 /** Russian (русский язык)
5 * You can contact Alexander Sigachov (alexander.sigachov at Googgle Mail)
9 class LanguageRu
extends Language
{
12 * Convert from the nominative form of a noun to some other case
13 * Invoked with {{grammar:case|word}}
19 function convertGrammar( $word, $case ) {
20 global $wgGrammarForms;
21 if ( isset( $wgGrammarForms['ru'][$case][$word] ) ) {
22 return $wgGrammarForms['ru'][$case][$word];
25 # These rules are not perfect, but they are currently only used for site names so it doesn't
26 # matter if they are wrong sometimes. Just add a special case for your site name if necessary.
28 # join and array_slice instead mb_substr
30 preg_match_all( '/./us', $word, $ar );
31 if ( !preg_match( "/[a-zA-Z_]/us", $word ) )
33 case 'genitive': # родительный падеж
34 if ( ( join( '', array_slice( $ar[0], -4 ) ) == 'вики' ) ||
( join( '', array_slice( $ar[0], -4 ) ) == 'Вики' ) )
36 elseif ( join( '', array_slice( $ar[0], -1 ) ) == 'ь' )
37 $word = join( '', array_slice( $ar[0], 0, -1 ) ) . 'я';
38 elseif ( join( '', array_slice( $ar[0], -2 ) ) == 'ия' )
39 $word = join( '', array_slice( $ar[0], 0, -2 ) ) . 'ии';
40 elseif ( join( '', array_slice( $ar[0], -2 ) ) == 'ка' )
41 $word = join( '', array_slice( $ar[0], 0, -2 ) ) . 'ки';
42 elseif ( join( '', array_slice( $ar[0], -2 ) ) == 'ти' )
43 $word = join( '', array_slice( $ar[0], 0, -2 ) ) . 'тей';
44 elseif ( join( '', array_slice( $ar[0], -2 ) ) == 'ды' )
45 $word = join( '', array_slice( $ar[0], 0, -2 ) ) . 'дов';
46 elseif ( join( '', array_slice( $ar[0], -3 ) ) == 'ник' )
47 $word = join( '', array_slice( $ar[0], 0, -3 ) ) . 'ника';
49 case 'dative': # дательный падеж
52 case 'accusative': # винительный падеж
55 case 'instrumental': # творительный падеж
58 case 'prepositional': # предложный падеж
66 * Plural form transformations
68 * $forms[0] - singular form (for 1, 21, 31, 41...)
69 * $forms[1] - paucal form (for 2, 3, 4, 22, 23, 24, 32, 33, 34...)
70 * $forms[2] - plural form (for 0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 25, 26...)
74 * "Сделано $1 {{PLURAL:$1|изменение|изменения|изменений}}"
75 * ("$1 change[s] were made)
76 * message without number
77 * "Действие не может быть выполнено по {{PLURAL:$1|следующей причине|следующим причинам}}:"
78 * ("The action cannot be performed for the following reason[s]")
84 function convertPlural( $count, $forms ) {
85 if ( !count( $forms ) ) { return ''; }
87 // If the actual number is not mentioned in the expression, then just two forms are enough:
88 // singular for $count == 1
89 // plural for $count != 1
90 // For example, "This user belongs to {{PLURAL:$1|one group|several groups}}."
91 if ( count( $forms ) === 2 ) return $count == 1 ?
$forms[0] : $forms[1];
93 // @todo FIXME: CLDR defines 4 plural forms. Form with decimals missing.
94 // See http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html#ru
95 $forms = $this->preConvertPlural( $forms, 3 );
97 if ( $count > 10 && floor( ( $count %
100 ) / 10 ) == 1 ) {
100 switch ( $count %
10 ) {
101 case 1: return $forms[0];
104 case 4: return $forms[1];
105 default: return $forms[2];
111 * Four-digit number should be without group commas (spaces)
112 * See manual of style at http://ru.wikipedia.org/wiki/Википедия:Оформление_статей
113 * So "1 234 567", "12 345" but "1234"
119 function commafy( $_ ) {
120 if ( preg_match( '/^-?\d{1,4}(\.\d*)?$/', $_ ) ) {
123 return strrev( (string)preg_replace( '/(\d{3})(?=\d)(?!\d*\.)/', '$1,', strrev( $_ ) ) );