Index: trunk/extensions/DonationInterface/gateway_common/DataValidator.php |
— | — | @@ -238,10 +238,59 @@ |
239 | 239 | * @return boolean - true if message exists, otherwise false. |
240 | 240 | */ |
241 | 241 | public static function wmfMessageExists( $msg_key, $language ){ |
242 | | - return wfMessage( $msg_key )->inLanguage( $language )->exists(); |
| 242 | + if ( wfMessage( $msg_key )->inLanguage( $language )->exists() ){ |
| 243 | + # if we are looking for English, we already know the answer |
| 244 | + if ( $language == 'en' ){ |
| 245 | + return true; |
| 246 | + } |
| 247 | + |
| 248 | + # get the english version of the message |
| 249 | + $msg_en = wfMessage( $msg_key )->inLanguage( 'en' )->text(); |
| 250 | + # attempt to get the message in the specified language |
| 251 | + $msg_lang = wfMessage( $msg_key )->inLanguage( $language )->text(); |
| 252 | + |
| 253 | + # if the messages are the same, the message fellback to English, return false |
| 254 | + return strcmp( $msg_en, $msg_lang ) != 0; |
| 255 | + } |
| 256 | + return false; |
243 | 257 | } |
244 | 258 | |
| 259 | + /** |
| 260 | + * wfLangSpecificFallback - returns the text of the first existant message |
| 261 | + * in the requested language. If no messages are found in that language, the |
| 262 | + * function returns the first existant fallback message. |
| 263 | + * |
| 264 | + * @param $language the requested language |
| 265 | + * @return String the text of the first existant message |
| 266 | + * @throws MWException if no message keys are specified |
| 267 | + */ |
| 268 | + public static function wfLangSpecificFallback( $language /*...*/ ){ |
| 269 | + $msg_keys = func_get_args(); |
| 270 | + array_shift( $msg_keys ); |
245 | 271 | |
| 272 | + if ( count( $msg_keys ) < 1 ){ |
| 273 | + throw new MWException( __FUNCTION__ . " BAD PROGRAMMER. No message keys given." ); |
| 274 | + } |
| 275 | + |
| 276 | + # look for the first message that exists |
| 277 | + foreach ( $msg_keys as $m ){ |
| 278 | + if ( self::wmfMessageExists( $m, $language) ){ |
| 279 | + return wfMessage( $m )->inLanguage( $language )->text(); |
| 280 | + } |
| 281 | + } |
| 282 | + |
| 283 | + # we found nothing in the requested language, return the first fallback message that exists |
| 284 | + foreach ( $msg_keys as $m ){ |
| 285 | + if ( wfMessage( $m )->inLanguage( $language )->exists() ){ |
| 286 | + return wfMessage( $m )->inLanguage( $language )->text(); |
| 287 | + } |
| 288 | + } |
| 289 | + |
| 290 | + # somehow we still don't have a message, return a default error message |
| 291 | + return wfMessage( $msg_keys[0] )->text(); |
| 292 | + } |
| 293 | + |
| 294 | + |
246 | 295 | /** |
247 | 296 | * validate |
248 | 297 | * Run all the validation rules we have defined against a (hopefully |