} catch (sfException $e) {
    $t->pass('->__construct() throws an exception if the culture is not valid');
}
$c_en = new sfCultureInfo();
$c_fr = new sfCultureInfo('fr');
// ->getLanguages()
$t->diag('->getLanguages()');
$languages_en = $c_en->getLanguages();
$languages_fr = $c_fr->getLanguages();
$t->is($languages_en['fr'], 'French', '->getLanguages() returns a list of languages in the language of the localized version');
$t->is($languages_fr['fr'], 'français', '->getLanguages() returns a list of languages in the language of the localized version');
$t->is($languages_en, $c_en->Languages, '->getLanguages() is equivalent to ->Languages');
// ->getCurrencies()
$t->diag('->getCurrencies()');
$currencies_en = $c_en->getCurrencies();
$currencies_fr = $c_fr->getCurrencies();
$t->is($currencies_en['EUR'][1], 'Euro', '->getCurrencies() returns a list of currencies in the language of the localized version');
$t->is($currencies_fr['EUR'][1], 'euro', '->getCurrencies() returns a list of currencies in the language of the localized version');
$t->is($currencies_en, $c_en->Currencies, '->getCurrencies() is equivalent to ->Currencies');
// ->getCountries()
$t->diag('->getCountries()');
$countries_en = $c_en->getCountries();
$countries_fr = $c_fr->getCountries();
$t->is($countries_en['ES'], 'Spain', '->getCountries() returns a list of countries in the language of the localized version');
$t->is($countries_fr['ES'], 'Espagne', '->getCountries() returns a list of countries in the language of the localized version');
$t->is($countries_en, $c_en->Countries, '->getCountries() is equivalent to ->Countries');
// ->getScripts()
$t->diag('->getScripts()');
$scripts_en = $c_en->getScripts();
$scripts_fr = $c_fr->getScripts();
$t->is($scripts_en['Arab'], 'Arabic', '->getScripts() returns a list of scripts in the language of the localized version');
Ejemplo n.º 2
0
/**
 * Returns a <select> tag populated with all the currencies in the world (or almost).
 *
 * The select_currency_tag builds off the traditional select_tag function, and is conveniently populated with 
 * all the currencies in the world (sorted alphabetically). Each option in the list has a three character 
 * currency code for its value and the currency's name as its display title.  The currency data is 
 * retrieved via the sfCultureInfo class, which stores a wide variety of i18n and i10n settings for various 
 * countries and cultures throughout the world. Here's an example of an <option> tag generated by the select_currency_tag:
 *
 * <samp>
 *  <option value="EUR">Euro</option>
 * </samp>
 *
 * <b>Examples:</b>
 * <code>
 *  echo select_currency_tag('currency', 'EUR');
 * </code>
 * <code>
 *  echo select_currency_tag('currency', 'EUR', array('currencies' => array('EUR', 'USD'), 'display' => 'symbol'));
 * </code>
 *
 * @param  string $name      field name 
 * @param  string $selected  selected field value (threecharacter currency code)
 * @param  array  $options   additional HTML compliant <select> tag parameters
 *
 * @return string <select> tag populated with all the currencies in the world.
 * @see select_tag, options_for_select, sfCultureInfo
 */
function select_currency_tag($name, $selected = null, $options = array())
{
    $c = new sfCultureInfo(sfContext::getInstance()->getUser()->getCulture());
    $currencies = $c->getCurrencies();
    $currency_option = _get_option($options, 'currencies');
    $display_option = _get_option($options, 'display');
    foreach ($currencies as $key => $value) {
        if ($currency_option && !in_array($key, $currency_option)) {
            unset($currencies[$key]);
        } else {
            switch ($display_option) {
                case 'symbol':
                    $currencies[$key] = $value[0];
                    break;
                case 'code':
                    $currencies[$key] = $key;
                    break;
                default:
                    $currencies[$key] = ucfirst($value[1]);
                    break;
            }
        }
    }
    asort($currencies);
    $option_tags = options_for_select($currencies, $selected, $options);
    unset($options['include_blank'], $options['include_custom']);
    return select_tag($name, $option_tags, $options);
}