* Reworked convertPlural so that it accepts variable number of arguments nicely
[lhc/web/wiklou.git] / languages / classes / LanguageHy.php
1 <?php
2 /** Armenian (Հայերեն)
3 *
4 * @addtogroup Language
5 * @author Ruben Vardanyan (Me@RubenVardanyan.com)
6 */
7
8 /* Please, see Language.php for general function comments */
9 class LanguageHy 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['hy'][$case][$word]) ) {
15 return $wgGrammarForms['hy'][$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],-1))=='ա')
28 $word = join('',array_slice($ar[0],0,-1)).'այի';
29 elseif (join('',array_slice($ar[0],-1))=='ո')
30 $word=join('',array_slice($ar[0],0,-1)).'ոյի';
31 elseif (join('',array_slice($ar[0],-4))=='գիրք')
32 $word=join('',array_slice($ar[0],0,-4)).'գրքի';
33 else
34 $word.='ի';
35 break;
36 case 'dative': #Տրական հոլով
37 #stub
38 break;
39 case 'accusative': #Հայցական հոլով
40 #stub
41 break;
42 case 'instrumental': #
43 #stub
44 break;
45 case 'prepositional': #
46 #stub
47 break;
48 }
49 return $word;
50 }
51
52 function convertPlural( $count, $forms ) {
53 if ( !count($forms) ) { return ''; }
54 $forms = $this->preConvertPlural( $forms, 2 );
55
56 return (abs($count) <= 1) ? $forms[0] : $forms[1];
57 }
58
59 /*
60 * Armenian numeric format is "12 345,67" but "1234,56"
61 */
62
63 function commafy($_) {
64 if (!preg_match('/^\d{1,4}$/',$_)) {
65 return strrev((string)preg_replace('/(\d{3})(?=\d)(?!\d*\.)/','$1,',strrev($_)));
66 } else {
67 return $_;
68 }
69 }
70 }
71