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