Integer comparison in Hebrew plural forms.
[lhc/web/wiklou.git] / languages / classes / LanguageHe.php
1 <?php
2
3 /**
4 * Hebrew (עברית)
5 *
6 * @ingroup Language
7 *
8 * @author Rotem Liss
9 */
10 class LanguageHe extends Language {
11
12 /**
13 * Convert grammar forms of words.
14 *
15 * Available cases:
16 * "prefixed" (or "תחילית") - when the word has a prefix
17 *
18 * @param $word String: the word to convert
19 * @param $case String: the case
20 *
21 * @return string
22 */
23 public function convertGrammar( $word, $case ) {
24 global $wgGrammarForms;
25 if ( isset( $wgGrammarForms['he'][$case][$word] ) ) {
26 return $wgGrammarForms['he'][$case][$word];
27 }
28
29 switch ( $case ) {
30 case 'prefixed':
31 case 'תחילית':
32 # Duplicate the "Waw" if prefixed
33 if ( substr( $word, 0, 2 ) == "ו" && substr( $word, 0, 4 ) != "וו" ) {
34 $word = "ו" . $word;
35 }
36
37 # Remove the "He" if prefixed
38 if ( substr( $word, 0, 2 ) == "ה" ) {
39 $word = substr( $word, 2 );
40 }
41
42 # Add a hyphen (maqaf) if non-Hebrew letters
43 if ( substr( $word, 0, 2 ) < "א" || substr( $word, 0, 2 ) > "ת" ) {
44 $word = "־" . $word;
45 }
46 }
47
48 return $word;
49 }
50
51 /**
52 * Gets a number and uses the suited form of the word.
53 *
54 * @param $count Integer: the number of items
55 * @param $forms Array with 3 items: the three plural forms
56 * @return String: the suited form of word
57 */
58 function convertPlural( $count, $forms ) {
59 if ( !count( $forms ) ) { return ''; }
60 $forms = $this->preConvertPlural( $forms, 3 );
61
62 if ( $count === '1' ) {
63 return $forms[0]; // Singular
64 } elseif ( $count === '2' ) {
65 return $forms[2]; // Dual or plural if dual is not provided (filled in preConvertPlural)
66 } else {
67 return $forms[1]; // Plural
68 }
69 }
70 }