]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - languages/classes/LanguageRu.php
MediaWiki 1.16.0
[autoinstallsdev/mediawiki.git] / languages / classes / LanguageRu.php
1 <?php
2
3 /** Russian (русский язык)
4   *
5   * You can contact Alexander Sigachov (alexander.sigachov at Googgle Mail)
6   *
7   * @ingroup Language
8   */
9 class LanguageRu extends Language {
10         # Convert from the nominative form of a noun to some other case
11         # Invoked with {{grammar:case|word}}
12         function convertGrammar( $word, $case ) {
13                 global $wgGrammarForms;
14                 if ( isset($wgGrammarForms['ru'][$case][$word]) ) {
15                         return $wgGrammarForms['ru'][$case][$word];
16                 }
17
18                 # These rules are not perfect, but they are currently only used for site names so it doesn't
19                 # matter if they are wrong sometimes. Just add a special case for your site name if necessary.
20
21                 #join and array_slice instead mb_substr
22                 $ar = array();
23                 preg_match_all( '/./us', $word, $ar );
24                 if (!preg_match("/[a-zA-Z_]/us", $word))
25                         switch ( $case ) {
26                                 case 'genitive': #родительный падеж
27                                         if ((join('',array_slice($ar[0],-4))=='вики') || (join('',array_slice($ar[0],-4))=='Вики'))
28                                                 {}
29                                         elseif (join('',array_slice($ar[0],-1))=='ь')
30                                                 $word = join('',array_slice($ar[0],0,-1)).'я';
31                                         elseif (join('',array_slice($ar[0],-2))=='ия')
32                                                 $word=join('',array_slice($ar[0],0,-2)).'ии';
33                                         elseif (join('',array_slice($ar[0],-2))=='ка')
34                                                 $word=join('',array_slice($ar[0],0,-2)).'ки';
35                                         elseif (join('',array_slice($ar[0],-2))=='ти')
36                                                 $word=join('',array_slice($ar[0],0,-2)).'тей';
37                                         elseif (join('',array_slice($ar[0],-2))=='ды')
38                                                 $word=join('',array_slice($ar[0],0,-2)).'дов';
39                                         elseif (join('',array_slice($ar[0],-3))=='ник')
40                                                 $word=join('',array_slice($ar[0],0,-3)).'ника';
41                                         break;
42                                 case 'dative':  #дательный падеж
43                                         #stub
44                                         break;
45                                 case 'accusative': #винительный падеж
46                                         #stub
47                                         break;
48                                 case 'instrumental':  #творительный падеж
49                                         #stub
50                                         break;
51                                 case 'prepositional': #предложный падеж
52                                         #stub
53                                         break;
54                         }
55                 return $word;
56         }
57
58         /**
59          * Plural form transformations
60          *
61          * $forms[0] - singular form (for 1, 21, 31, 41...)
62          * $forms[1] - paucal form (for 2, 3, 4, 22, 23, 24, 32, 33, 34...)
63          * $forms[2] - plural form (for 0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 25, 26...)
64          *
65          * Examples:
66          *   message with number
67          *     "Сделано $1 {{PLURAL:$1|изменение|изменения|изменений}}"
68          *   message without number
69          *     "Действие не может быть выполнено по {{PLURAL:$1|следующей причине|следующим причинам}}:"
70          *
71          */
72
73         function convertPlural( $count, $forms ) {
74                 if ( !count($forms) ) { return ''; }
75
76                 //if no number with word, then use $form[0] for singular and $form[1] for plural or zero
77                 if( count($forms) === 2 ) return $count == 1 ? $forms[0] : $forms[1];
78
79                 // FIXME: CLDR defines 4 plural forms. Form with decimals missing.
80                 // See http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/language_plural_rules.html#ru
81                 $forms = $this->preConvertPlural( $forms, 3 );
82
83                 if ($count > 10 && floor(($count % 100) / 10) == 1) {
84                         return $forms[2];
85                 } else {
86                         switch ($count % 10) {
87                                 case 1:  return $forms[0];
88                                 case 2:
89                                 case 3:
90                                 case 4:  return $forms[1];
91                                 default: return $forms[2];
92                         }
93                 }
94         }
95
96         /*
97          * Four-digit number should be without group commas (spaces)
98          * See manual of style at http://ru.wikipedia.org/wiki/Википедия:Оформление_статей
99          * So "1 234 567", "12 345" but "1234"
100          */
101         function commafy($_) {
102                 if (preg_match('/^-?\d{1,4}(\.\d*)?$/',$_)) {
103                         return $_;
104                 } else {
105                         return strrev((string)preg_replace('/(\d{3})(?=\d)(?!\d*\.)/','$1,',strrev($_)));
106                 }
107         }
108 }