/**
     * @param  string $name        The element name
     * @param  string $value       The date displayed in this widget
     * @param  array  $attributes  An array of HTML attributes to be merged with the default HTML attributes
     * @param  array  $errors      An array of errors for the field
     *
     * @return string An HTML tag string
     *
     * @see sfWidgetForm
     */
    public function render($name, $value = null, $attributes = array(), $errors = array())
    {
        $id = $this->generateId($name);

        $return = parent::render($name, $value, $attributes, $errors);

        $return .= sprintf(<<<EOF
<script type="text/javascript">
function formatResult(item)
{
    return item.text;
}

jQuery("#%s").select2(
{
    width:              '%s',
    allowClear:         %s,
});
</script>
EOF
            ,
            $id,
            $this->getOption('width'),
            $this->getOption('add_empty') == true ? 'true' : 'false'
        );

        return $return;
    }
// ->configure()
$t->diag('->configure()');
try {
    new sfWidgetFormI18nChoiceCountry(array('culture' => 'en', 'countries' => array('EN')));
    $t->fail('->configure() throws an InvalidArgumentException if a country does not exist');
} catch (InvalidArgumentException $e) {
    $t->pass('->configure() throws an InvalidArgumentException if a country does not exist');
}
$v = new sfWidgetFormI18nChoiceCountry(array('culture' => 'en', 'countries' => array('FR', 'GB')));
$t->is(array_keys($v->getOption('choices')), array('FR', 'GB'), '->configure() can restrict the number of countries with the countries option');
// ->render()
$t->diag('->render()');
$w = new sfWidgetFormI18nChoiceCountry(array('culture' => 'fr'));
$dom->loadHTML($w->render('country', 'FR'));
$css = new sfDomCssSelector($dom);
$t->is($css->matchSingle('#country option[value="FR"]')->getValue(), 'France', '->render() renders all countries as option tags');
$t->is(count($css->matchAll('#country option[value="FR"][selected="selected"]')->getNodes()), 1, '->render() renders all countries as option tags');
// Test for ICU Upgrade and Ticket #7988
// should be 0. Tests will break after ICU Update, which is fine. change count to 0
$t->is(count($css->matchAll('#country option[value="ZZ"]')), 1, '->render() does not contain dummy data');
$t->is(count($css->matchAll('#country option[value="419"]')), 0, '->render() does not contain region data');
// add_empty
$t->diag('add_empty');
$w = new sfWidgetFormI18nChoiceCountry(array('culture' => 'fr', 'add_empty' => true));
$dom->loadHTML($w->render('country', 'FR'));
$css = new sfDomCssSelector($dom);
$t->is($css->matchSingle('#country option[value=""]')->getValue(), '', '->render() renders an empty option if add_empty is true');
$w = new sfWidgetFormI18nChoiceCountry(array('culture' => 'fr', 'add_empty' => 'foo'));
$dom->loadHTML($w->render('country', 'FR'));
$css = new sfDomCssSelector($dom);
$t->is($css->matchSingle('#country option[value=""]')->getValue(), 'foo', '->render() renders an empty option if add_empty is true');
<span class="label">
  <label for="country"><?php 
echo __('Choose your country');
?>
</label>
</span>
<span class="field">
  <?php 
$country_selector = new sfWidgetFormI18nChoiceCountry(array('culture' => $lang, 'countries' => CultureTools::getCountriesForLanguage($lang)));
echo $country_selector->render('country', $sf_user->getAttribute('country', $preferred_country));
?>
</span>