(bug 21911) Per Tim Starling's comment #10: Remove hard coded limit for long page...
[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 * Convert from the nominative form of a noun to other cases.
25 * Invoked with {{GRAMMAR:case|word}} inside messages.
26 *
27 * case is a sequence of words, each of which is case insensitive.
28 * Between words, there must be at least one space character.
29 * Only the 1st character of each word is considered.
30 * Word order is irrelevant.
31 *
32 * Possible values specifying the grammatical case are:
33 * 1, Nominative
34 * 2, Genitive
35 * 3, Dative
36 * 4, Accusative, -omitted-
37 *
38 * Possible values specifying the article type are:
39 * Betoont focussed or stressed article
40 * -omitted- unstressed or unfocussed article
41 *
42 * Possible values for for the type of genitive are:
43 * Sing, Iehr prepositioned genitive = possessive dative
44 * Vun, Fon, -omitted- postpositioned genitive
45 * = preposition "vun" with dative
46 *
47 * Values of case overrides & prepositions, in the order of preceedence:
48 * Sing, Iehr possessive dative = prepositioned genitive
49 * Vun, Fon preposition "vun" with dative
50 * = postpositioned genitive
51 * En, em preposition "en" with dative
52 *
53 * Values for object gender specifiers of the possessive dative, or
54 * prepositioned genitive, evaluated with "Sing, Iehr" of above only:
55 * Male a singular male object follows
56 * -omitted- a non-male or plural object follows
57 *
58 * We currently handle definite articles of the singular only.
59 * There is a full set of test cases at:
60 * http://translatewiki.net/wiki/Portal:Ksh#GRAMMAR_Pr%C3%B6%C3%B6fe
61 * Contents of the leftmost table column can be copied and pasted as
62 * "case" values.
63 *
64 */
65 function convertGrammar( $word, $case )
66 {
67 $lord = strtolower($word);
68 $gender = 'm'; // Nuutnaarel // default
69 if ( preg_match ( '/wiki$/', $lord ) )
70 {
71 $gender = 'n'; // Dat xyz-wiki
72 }
73 if ( isset( self::$familygender[$lord] ) )
74 {
75 $gender = (self::$familygender[$lord]);
76 }
77 $case = (' '.strtolower($case));
78 if ( preg_match( '/ [is]/', $case ) )
79 {
80 # däm WikiMaatplaz singe, dä Wikipeedija iere, däm Wikiwööterbooch singe
81 # dem/em WikiMaatplaz singe, de Wikipeedija iere, dem/em Wikiwööterbooch singe
82 # däm WikiMaatplaz sing, dä Wikipeedija ier, däm Wikiwööterbooch sing
83 # dem/em WikiMaatplaz sing, de Wikipeedija ier, dem/em Wikiwööterbooch sing
84 $word = ( preg_match( '/ b/', $case )
85 ? ($gender=='f'
86 ? 'dä'
87 : 'däm'
88 )
89 : ($gender=='f'
90 ? 'de'
91 : 'dem'
92 )
93 ).
94 ' '.$word.' '.
95 ( $gender=='f'
96 ? 'ier'
97 : 'sing'
98 ).
99 ( preg_match( '/ m/', $case )
100 ? 'e'
101 : ''
102 );
103 }
104 elseif ( preg_match( '/ e/', $case ) )
105 {
106 # en dämm WikiMaatPlaz, en dä Wikipeedija, en dämm Wikiwööterbooch
107 # em WikiMaatplaz, en de Wikipeedija, em Wikiwööterbooch
108 if ( preg_match( '/ b/', $case ) )
109 {
110 $word = ('en '.($gender=='f'?'dä':'däm').' '.$word);
111 }
112 else
113 {
114 $word = (($gender=='f'?'en de':'em').' '.$word);
115 }
116 }
117 elseif ( preg_match( '/ [fv]/', $case ) || preg_match( '/ [2jg]/', $case ) )
118 {
119 # vun däm WikiMaatplaz, vun dä Wikipeedija, vun däm Wikiwööterbooch
120 # vum WikiMaatplaz, vun de Wikipeedija, vum Wikiwööterbooch
121 if ( preg_match( '/ b/', $case ) )
122 {
123 $word = ('vun '.($gender=='f'?'dä':'däm').' '.$word);
124 }
125 else
126 {
127 $word = (($gender=='f'?'vun de':'vum').' '.$word);
128 }
129 }
130 elseif ( preg_match( '/ [3d]/', $case ) )
131 {
132 # dämm WikiMaatPlaz, dä Wikipeedija, dämm Wikiwööterbooch
133 # dem/em WikiMaatplaz, de Wikipeedija, dem/em Wikiwööterbooch
134 if ( preg_match( '/ b/', $case ) )
135 {
136 $word = (($gender=='f'?'dää':'dämm').' '.$word);
137 }
138 else
139 {
140 $word = (($gender=='f'?'de':'dem').' '.$word);
141 }
142 }
143 else
144 {
145 # dä WikiMaatPlaz, di Wikipeedija, dat Wikiwööterbooch
146 # der WikiMaatplaz, de Wikipeedija, et Wikiwööterbooch
147 if ( preg_match( '/ b/', $case ) )
148 {
149 switch ( $gender )
150 {
151 case 'm' : $lord = 'dä' ; break ;
152 case 'f' : $lord = 'di' ; break ;
153 default : $lord = 'dat' ; break ;
154 }
155 }
156 else
157 {
158 switch ( $gender )
159 {
160 case 'm' : $lord = 'der' ; break ;
161 case 'f' : $lord = 'de' ; break ;
162 default : $lord = 'et' ; break ;
163 }
164 }
165 $word = ($lord.' '.$word);
166 }
167 return($word);
168 }
169
170 /**
171 * Avoid grouping whole numbers between 0 to 9999
172 */
173 public function commafy( $_ ) {
174 if ( !preg_match( '/^\d{1,4}$/', $_ ) ) {
175 return strrev( (string)preg_replace( '/(\d{3})(?=\d)(?!\d*\.)/', '$1,', strrev( $_ ) ) );
176 } else {
177 return $_;
178 }
179 }
180
181 /**
182 * Handle cases of (1, other, 0) or (1, other)
183 */
184 function convertPlural( $count, $forms ) {
185 if ( !count( $forms ) ) { return ''; }
186 $forms = $this->preConvertPlural( $forms, 3 );
187
188 if ( $count == 1 ) {
189 return $forms[0];
190 } elseif ( $count == 0 ) {
191 return $forms[2];
192 } else {
193 return $forms[1];
194 }
195 }
196 }