* Reworked convertPlural so that it accepts variable number of arguments nicely
[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 * $wordform1 - singular form (for 1, 21, 31, 41...)
63 * $wordform2 - paucal form (for 2, 3, 4, 22, 23, 24, 32, 33, 34...)
64 * $wordform3 - plural form (for 0, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 25, 26...)
65 * $wordform4 - plural form for messages without number
66 * $wordform5 - not used
67 *
68 * Examples:
69 * message with number
70 * "Сделано $1 {{PLURAL:$1|изменение|изменения|изменений}}"
71 * message without number
72 * "Действие не может быть выполнено по {{PLURAL:$1|следующей причине|||следующим причинам}}:"
73 *
74 */
75
76 function convertPlural( $count, $forms ) {
77 if ( !count($forms) ) { return ''; }
78 $forms = $this->preConvertPlural( $forms, 3 );
79
80 $count = abs( $count );
81 if ( isset($forms[3]) && $count != 1 )
82 return $forms[3];
83
84 if ($count > 10 && floor(($count % 100) / 10) == 1) {
85 return $forms[2];
86 } else {
87 switch ($count % 10) {
88 case 1: return $forms[0];
89 case 2:
90 case 3:
91 case 4: return $forms[1];
92 default: return $forms[2];
93 }
94 }
95 }
96
97 /*
98 * Russian numeric format is "12 345,67" but "1234,56"
99 */
100
101 function commafy($_) {
102 if (!preg_match('/^\d{1,4}$/',$_)) {
103 return strrev((string)preg_replace('/(\d{3})(?=\d)(?!\d*\.)/','$1,',strrev($_)));
104 } else {
105 return $_;
106 }
107 }
108 }
109
110