More documentation!
[lhc/web/wiklou.git] / languages / classes / LanguageKsh.php
1 <?php
2
3 /** Ripuarian (Ripoarėsh)
4 *
5 * @ingroup Language
6 *
7 * @author Purodha Blissenbach
8 */
9 class LanguageKsh extends Language {
10 static $familygender = array(
11 // Do not add male wiki families, since that's the default.
12 // No need add neuter wikis having names ending in -wiki.
13 'wikipedia' => 'f',
14 'wikiversity' => 'f',
15 'wiktionary' => 'n',
16 'wikibooks' => 'n',
17 'wikiquote' => 'n',
18 'wikisource' => 'n',
19 'wikitravel' => 'n',
20 'wikia' => 'f',
21 'translatewiki.net' => 'n',
22 );
23
24 /**
25 * Convert from the nominative form of a noun to other cases.
26 * Invoked with {{GRAMMAR:case|word}} inside messages.
27 *
28 * case is a sequence of words, each of which is case insensitive.
29 * Between words, there must be at least one space character.
30 * Only the 1st character of each word is considered.
31 * Word order is irrelevant.
32 *
33 * Possible values specifying the grammatical case are:
34 * 1, Nominative
35 * 2, Genitive
36 * 3, Dative
37 * 4, Accusative, -omitted-
38 *
39 * Possible values specifying the article type are:
40 * Betoont focussed or stressed article
41 * -omitted- unstressed or unfocussed article
42 *
43 * Possible values for the type of genitive are:
44 * Sing, Iehr prepositioned genitive = possessive dative
45 * Vun, Fon, -omitted- postpositioned genitive
46 * = preposition "vun" with dative
47 *
48 * Values of case overrides & prepositions, in the order of preceedence:
49 * Sing, Iehr possessive dative = prepositioned genitive
50 * Vun, Fon preposition "vun" with dative
51 * = postpositioned genitive
52 * En, em preposition "en" with dative
53 *
54 * Values for object gender specifiers of the possessive dative, or
55 * prepositioned genitive, evaluated with "Sing, Iehr" of above only:
56 * Male a singular male object follows
57 * -omitted- a non-male or plural object follows
58 *
59 * We currently handle definite articles of the singular only.
60 * There is a full set of test cases at:
61 * http://translatewiki.net/wiki/Portal:Ksh#GRAMMAR_Pr%C3%B6%C3%B6fe
62 * Contents of the leftmost table column can be copied and pasted as
63 * "case" values.
64 *
65 * @param $word String
66 * @param $case String
67 *
68 * @return string
69 */
70 function convertGrammar( $word, $case ) {
71 $lord = strtolower( $word );
72 $gender = 'm'; // Nuutnaarel // default
73 if ( preg_match ( '/wiki$/', $lord ) ) {
74 $gender = 'n'; // Dat xyz-wiki
75 }
76 if ( isset( self::$familygender[$lord] ) ) {
77 $gender = self::$familygender[$lord];
78 }
79 $case = ' ' . strtolower( $case );
80 if ( preg_match( '/ [is]/', $case ) ) {
81 # däm WikiMaatplaz singe, dä Wikipeedija iere, däm Wikiwööterbooch singe
82 # dem/em WikiMaatplaz singe, de Wikipeedija iere, dem/em Wikiwööterbooch singe
83 # däm WikiMaatplaz sing, dä Wikipeedija ier, däm Wikiwööterbooch sing
84 # dem/em WikiMaatplaz sing, de Wikipeedija ier, dem/em Wikiwööterbooch sing
85 $word = ( preg_match( '/ b/', $case )
86 ? ( $gender=='f' ? 'dä' : 'däm' )
87 : ( $gender=='f' ? 'de' : 'dem' )
88 ) . ' ' . $word . ' ' .
89 ( $gender=='f' ? 'ier' : 'sing' ) .
90 ( preg_match( '/ m/', $case ) ? 'e' : ''
91 );
92 } elseif ( preg_match( '/ e/', $case ) ) {
93 # en dämm WikiMaatPlaz, en dä Wikipeedija, en dämm Wikiwööterbooch
94 # em WikiMaatplaz, en de Wikipeedija, em Wikiwööterbooch
95 if ( preg_match( '/ b/', $case ) ) {
96 $word = 'en '.( $gender == 'f' ? 'dä' : 'däm' ) . ' ' . $word;
97 } else {
98 $word = ( $gender == 'f' ? 'en de' : 'em' ) . ' ' . $word;
99 }
100 } elseif ( preg_match( '/ [fv]/', $case ) || preg_match( '/ [2jg]/', $case ) ) {
101 # vun däm WikiMaatplaz, vun dä Wikipeedija, vun däm Wikiwööterbooch
102 # vum WikiMaatplaz, vun de Wikipeedija, vum Wikiwööterbooch
103 if ( preg_match( '/ b/', $case ) ) {
104 $word = 'vun ' . ( $gender == 'f' ? 'dä' : 'däm' ) . ' ' . $word;
105 } else {
106 $word = ( $gender== 'f' ? 'vun de' : 'vum' ) . ' ' . $word;
107 }
108 } elseif ( preg_match( '/ [3d]/', $case ) ) {
109 # dämm WikiMaatPlaz, dä Wikipeedija, dämm Wikiwööterbooch
110 # dem/em WikiMaatplaz, de Wikipeedija, dem/em Wikiwööterbooch
111 if ( preg_match( '/ b/', $case ) ) {
112 $word = ( $gender == 'f' ? 'dää' : 'dämm' ) .' ' . $word;
113 } else {
114 $word = ( $gender == 'f' ? 'de' : 'dem' ) . ' ' . $word;
115 }
116 } else {
117 # dä WikiMaatPlaz, di Wikipeedija, dat Wikiwööterbooch
118 # der WikiMaatplaz, de Wikipeedija, et Wikiwööterbooch
119 if ( preg_match( '/ b/', $case ) ) {
120 switch ( $gender ) {
121 case 'm':
122 $lord = 'dä';
123 break ;
124 case 'f':
125 $lord = 'di';
126 break;
127 default:
128 $lord = 'dat';
129 }
130 } else {
131 switch ( $gender ) {
132 case 'm':
133 $lord = 'der';
134 break;
135 case 'f':
136 $lord = 'de';
137 break;
138 default:
139 $lord = 'et';
140 }
141 }
142 $word = $lord.' '.$word;
143 }
144 return $word;
145 }
146
147 /**
148 * Avoid grouping whole numbers between 0 to 9999
149 *
150 * @param $_ string
151 *
152 * @return string
153 */
154 public function commafy( $_ ) {
155 if ( !preg_match( '/^\d{1,4}$/', $_ ) ) {
156 return strrev( (string)preg_replace( '/(\d{3})(?=\d)(?!\d*\.)/', '$1,', strrev( $_ ) ) );
157 } else {
158 return $_;
159 }
160 }
161
162 /**
163 * Handle cases of (1, other, 0) or (1, other)
164 *
165 * @param $count int
166 * @param $forms array
167 *
168 * @return string
169 */
170 function convertPlural( $count, $forms ) {
171 if ( !count( $forms ) ) { return ''; }
172 $forms = $this->preConvertPlural( $forms, 3 );
173
174 if ( $count == 1 ) {
175 return $forms[0];
176 } elseif ( $count == 0 ) {
177 return $forms[2];
178 } else {
179 return $forms[1];
180 }
181 }
182 }