cleanup and fixes for secondary data updates
[lhc/web/wiklou.git] / languages / classes / LanguageHy.php
1 <?php
2
3 /** Armenian (Հայերեն)
4 *
5 * @ingroup Language
6 * @author Ruben Vardanyan (Me@RubenVardanyan.com)
7 */
8 class LanguageHy extends Language {
9
10 /**
11 * Convert from the nominative form of a noun to some other case
12 * Invoked with {{grammar:case|word}}
13 *
14 * @param $word string
15 * @param $case string
16 * @return string
17 */
18 function convertGrammar( $word, $case ) {
19 global $wgGrammarForms;
20 if ( isset( $wgGrammarForms['hy'][$case][$word] ) ) {
21 return $wgGrammarForms['hy'][$case][$word];
22 }
23
24 # These rules are not perfect, but they are currently only used for site names so it doesn't
25 # matter if they are wrong sometimes. Just add a special case for your site name if necessary.
26
27 # join and array_slice instead mb_substr
28 $ar = array();
29 preg_match_all( '/./us', $word, $ar );
30 if ( !preg_match( "/[a-zA-Z_]/us", $word ) )
31 switch ( $case ) {
32 case 'genitive': # սեռական հոլով
33 if ( join( '', array_slice( $ar[0], -1 ) ) == 'ա' )
34 $word = join( '', array_slice( $ar[0], 0, -1 ) ) . 'այի';
35 elseif ( join( '', array_slice( $ar[0], -1 ) ) == 'ո' )
36 $word = join( '', array_slice( $ar[0], 0, -1 ) ) . 'ոյի';
37 elseif ( join( '', array_slice( $ar[0], -4 ) ) == 'գիրք' )
38 $word = join( '', array_slice( $ar[0], 0, -4 ) ) . 'գրքի';
39 else
40 $word .= 'ի';
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 * @param $count int
60 * @param $forms array
61 *
62 * @return string
63 */
64 function convertPlural( $count, $forms ) {
65 if ( !count( $forms ) ) { return ''; }
66 $forms = $this->preConvertPlural( $forms, 2 );
67
68 return ( abs( $count ) <= 1 ) ? $forms[0] : $forms[1];
69 }
70
71 /**
72 * Armenian numeric format is "12 345,67" but "1234,56"
73 *
74 * @param $_ string
75 *
76 * @return string
77 */
78 function commafy( $_ ) {
79 if ( !preg_match( '/^\d{1,4}$/', $_ ) ) {
80 return strrev( (string)preg_replace( '/(\d{3})(?=\d)(?!\d*\.)/', '$1,', strrev( $_ ) ) );
81 } else {
82 return $_;
83 }
84 }
85 }