Index: trunk/extensions/DonationInterface/gateway_forms/RapidHtml.php |
— | — | @@ -68,6 +68,7 @@ |
69 | 69 | // @appeal -> name of the appeal text to load |
70 | 70 | // @appeal_title -> name of the appeal title to load |
71 | 71 | // @verisign_logo -> placeholder to load the secure verisign logo |
| 72 | + // @select_country -> generates a select containing all country names |
72 | 73 | ); |
73 | 74 | |
74 | 75 | /** |
— | — | @@ -217,6 +218,9 @@ |
218 | 219 | // handle script path |
219 | 220 | $form = str_replace( "@verisign_logo", $this->getSmallSecureLogo(), $form ); |
220 | 221 | |
| 222 | + // handle country drop-down |
| 223 | + $form = str_replace( "@select_country", $this->getCountryDropdown(), $form ); |
| 224 | + |
221 | 225 | $form = $this->fix_dropdowns( $form ); |
222 | 226 | |
223 | 227 | return $this->add_messages( $form ); |
— | — | @@ -256,9 +260,11 @@ |
257 | 261 | $params[ $k ] .= "language=" . $this->getEscapedValue( 'language' ) . "&country=" . $this->getEscapedValue( 'country' ); |
258 | 262 | } |
259 | 263 | } |
| 264 | + // TODO: add support for message variations here as well |
260 | 265 | $html = str_replace( $matches[ 0 ][ $i ], wfMsg( $msg_key, $params ), $html ); |
261 | 266 | } else { |
262 | | - $html = str_replace( '%' . $msg_key . '%', wfMsg( $msg_key ), $html ); |
| 267 | + // look for a country variant of the message and use that if found |
| 268 | + $html = str_replace( '%' . $msg_key . '%', $this->get_message_variation( $msg_key ), $html ); |
263 | 269 | } |
264 | 270 | } |
265 | 271 | |
— | — | @@ -435,4 +441,73 @@ |
436 | 442 | } |
437 | 443 | return $default; |
438 | 444 | } |
| 445 | + |
| 446 | + /** |
| 447 | + * This function looks for a country variant of the specified message and |
| 448 | + * returns the variant if found for the current language. If the variant |
| 449 | + * does not have a message for the current language, the original message |
| 450 | + * is used (checking first the current language and then falling back as |
| 451 | + * is normal for wfMessage). |
| 452 | + * |
| 453 | + * @param $key The original message key to be evaluated |
| 454 | + * @return string A string representing the message requested |
| 455 | + */ |
| 456 | + function get_message_variation( $key ) { |
| 457 | + $langCode = strtolower( $this->getEscapedValue( 'language' ) ); |
| 458 | + $countryCode = strtolower( $this->getEscapedValue( 'country' ) ); |
| 459 | + |
| 460 | + # construct the country-specific message key |
| 461 | + $msg_alt_key = $key . '-' . $countryCode; |
| 462 | + $msg_alt = wfMessage( $msg_alt_key ); |
| 463 | + |
| 464 | + # load the default |
| 465 | + $to_return = wfMessage( $key )->inLanguage( $langCode )->text(); |
| 466 | + |
| 467 | + # check to see if an alternate exists |
| 468 | + if ( $msg_alt->exists() ){ |
| 469 | + # get the English version of the alternate message |
| 470 | + $msg_alt_en = $msg_alt->inLanguage( 'en' )->text(); |
| 471 | + # get the alternate message in the current language |
| 472 | + $msg_alt_lang = $msg_alt->inLanguage( $langCode )->text(); |
| 473 | + |
| 474 | + # if we are looking for English, we're good |
| 475 | + if ( $langCode == 'en' ){ |
| 476 | + $to_return = $msg_alt_en; |
| 477 | + } |
| 478 | + # check make sure we didn't fallback to English |
| 479 | + elseif ( strcmp( $msg_alt_en, $msg_alt_lang ) != 0 ){ |
| 480 | + $to_return = $msg_alt_lang; |
| 481 | + } |
| 482 | + else { |
| 483 | + # do nothing and return the original message |
| 484 | + } |
| 485 | + } |
| 486 | + |
| 487 | + # strip the damned colons off of the right end |
| 488 | + $to_return = rtrim( $to_return, ':' ); |
| 489 | + |
| 490 | + return $to_return; |
| 491 | + } |
| 492 | + |
| 493 | + /** |
| 494 | + * Gets a list of the supported countries from the parent class |
| 495 | + * and returns an option list representing all of those countries |
| 496 | + * in a translatable fashion. |
| 497 | + * |
| 498 | + * @return string An option list containing all supported countries |
| 499 | + */ |
| 500 | + function getCountryDropdown() { |
| 501 | + # get the list of supported countries |
| 502 | + $countries = GatewayForm::getCountries(); |
| 503 | + |
| 504 | + $output = ""; |
| 505 | + |
| 506 | + # iterate through the countris, ignoring the value since we |
| 507 | + # will generate a message key to replace later |
| 508 | + foreach( $countries as $c => $v ) { |
| 509 | + $output .= "<option value=\"" . $c . "\">%donate_interface-country-dropdown-" . $c . "%</option>\n"; |
| 510 | + } |
| 511 | + |
| 512 | + return $output; |
| 513 | + } |
439 | 514 | } |