[Form] Implemented CountryField
This commit is contained in:
parent
78b69876d4
commit
9db7db4439
62
src/Symfony/Component/Form/CountryField.php
Normal file
62
src/Symfony/Component/Form/CountryField.php
Normal file
@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Form;
|
||||
|
||||
/**
|
||||
* A field for selecting from a list of countries
|
||||
*
|
||||
* @author Bernhard Schussek <bernhard.schussek@symfony-project.com>
|
||||
*/
|
||||
class CountryField extends ChoiceField
|
||||
{
|
||||
/**
|
||||
* Caches the country choices in different locales
|
||||
* @var array
|
||||
*/
|
||||
protected static $countries;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this->addOption('choices', self::getCountryChoices($this->locale));
|
||||
|
||||
parent::configure();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of countries for a locale
|
||||
*
|
||||
* @param string $locale The locale to use for the country names
|
||||
* @throws RuntimeException When the resource bundles cannot be loaded
|
||||
*/
|
||||
protected static function getCountryChoices($locale)
|
||||
{
|
||||
if (!isset(self::$countries[$locale])) {
|
||||
$bundle = new \ResourceBundle($locale, __DIR__.'/Resources/data/region');
|
||||
|
||||
if ($bundle === null) {
|
||||
throw new RuntimeException('The region resource bundle could not be loaded');
|
||||
}
|
||||
|
||||
$collator = new \Collator($locale);
|
||||
$countries = array();
|
||||
|
||||
foreach ($bundle->get('Countries') as $code => $name) {
|
||||
// Global regions (f.i. "America") have numeric codes
|
||||
// Countries have alphabetic codes
|
||||
// "ZZ" is the code for unknown region
|
||||
if (ctype_alpha($code) && $code !== 'ZZ') {
|
||||
$countries[$code] = $name;
|
||||
}
|
||||
}
|
||||
|
||||
$collator->asort($countries);
|
||||
|
||||
self::$countries[$locale] = $countries;
|
||||
}
|
||||
|
||||
return self::$countries[$locale];
|
||||
}
|
||||
}
|
34
src/Symfony/Component/Form/Resources/data/UPDATE.txt
Normal file
34
src/Symfony/Component/Form/Resources/data/UPDATE.txt
Normal file
@ -0,0 +1,34 @@
|
||||
How to update the ICU data
|
||||
==========================
|
||||
|
||||
1. Checkout the current version of the ICU data files
|
||||
|
||||
$ svn co http://source.icu-project.org/repos/icu/icu/trunk/source/data icu-data
|
||||
|
||||
2. Build the region resource bundles
|
||||
|
||||
$ cd icu-data/region
|
||||
$ mkdir build
|
||||
$ genrb -d build *.txt
|
||||
|
||||
3a. Replace the *.res files bundled with Symfony2 with the new ones.
|
||||
|
||||
.dat-package
|
||||
------------
|
||||
|
||||
The individual *.res files can be combined into a single .dat-file.
|
||||
Unfortunately, PHP's `ResourceBundle` class is currently not able to handle
|
||||
.dat-files.
|
||||
|
||||
Once it is, the following steps have to be followed to build the .dat-file:
|
||||
|
||||
3b. Package the resource bundles into a single file
|
||||
|
||||
$ find . -name *.res | sed -e "s/\.\///g" > packagelist.txt
|
||||
$ pkgdata -p region -T build -d . packagelist.txt
|
||||
|
||||
4. Clean up
|
||||
|
||||
$ rm -rf build packagelist.txt
|
||||
|
||||
5. You can now move region.dat to replace the version bundled with Symfony2.
|
BIN
src/Symfony/Component/Form/Resources/data/region/af.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/af.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/ak.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/ak.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/am.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/am.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/ar.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/ar.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/as.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/as.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/asa.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/asa.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/az.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/az.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/az_AZ.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/az_AZ.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/az_Cyrl.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/az_Cyrl.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/az_Latn.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/az_Latn.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/az_Latn_AZ.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/az_Latn_AZ.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/be.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/be.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/bem.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/bem.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/bez.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/bez.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/bg.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/bg.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/bm.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/bm.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/bn.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/bn.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/bo.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/bo.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/bs.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/bs.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/ca.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/ca.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/cgg.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/cgg.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/chr.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/chr.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/cs.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/cs.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/cy.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/cy.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/da.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/da.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/dav.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/dav.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/de.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/de.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/de_CH.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/de_CH.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/ebu.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/ebu.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/ee.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/ee.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/el.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/el.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/en.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/en.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/en_RH.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/en_RH.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/en_ZW.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/en_ZW.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/eo.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/eo.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/es.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/es.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/es_CL.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/es_CL.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/et.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/et.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/eu.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/eu.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/fa.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/fa.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/fa_AF.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/fa_AF.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/ff.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/ff.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/fi.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/fi.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/fil.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/fil.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/fil_PH.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/fil_PH.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/fo.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/fo.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/fr.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/fr.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/ga.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/ga.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/gl.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/gl.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/gsw.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/gsw.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/gu.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/gu.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/guz.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/guz.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/gv.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/gv.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/ha.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/ha.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/ha_GH.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/ha_GH.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/ha_Latn.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/ha_Latn.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/ha_Latn_GH.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/ha_Latn_GH.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/ha_Latn_NE.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/ha_Latn_NE.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/ha_Latn_NG.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/ha_Latn_NG.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/ha_NE.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/ha_NE.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/ha_NG.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/ha_NG.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/haw.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/haw.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/he.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/he.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/he_IL.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/he_IL.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/hi.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/hi.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/hr.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/hr.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/hu.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/hu.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/hy.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/hy.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/id.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/id.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/id_ID.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/id_ID.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/ig.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/ig.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/ii.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/ii.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/in.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/in.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/in_ID.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/in_ID.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/is.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/is.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/it.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/it.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/iw.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/iw.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/iw_IL.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/iw_IL.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/ja.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/ja.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/ja_JP.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/ja_JP.res
Normal file
Binary file not shown.
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/jmc.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/jmc.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/ka.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/ka.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/kab.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/kab.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/kam.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/kam.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/kde.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/kde.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/kea.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/kea.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/khq.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/khq.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/ki.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/ki.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/kk.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/kk.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/kk_Cyrl.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/kk_Cyrl.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/kk_Cyrl_KZ.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/kk_Cyrl_KZ.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/kk_KZ.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/kk_KZ.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/kl.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/kl.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/kln.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/kln.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/km.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/km.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/kn.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/kn.res
Normal file
Binary file not shown.
BIN
src/Symfony/Component/Form/Resources/data/region/ko.res
Normal file
BIN
src/Symfony/Component/Form/Resources/data/region/ko.res
Normal file
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user