Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
236 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+120 Bytes
src/Symfony/Component/Form/Resources/data/region/ja_JP_TRADITIONAL.res
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+120 Bytes
src/Symfony/Component/Form/Resources/data/region/th_TH_TRADITIONAL.res
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Symfony\Tests\Component\Form; | ||
|
||
use Symfony\Component\Form\CountryField; | ||
use Symfony\Component\Form\FormConfiguration; | ||
|
||
class CountryFieldTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testCountriesAreSelectable() | ||
{ | ||
FormConfiguration::setDefaultLocale('de_AT'); | ||
|
||
$field = new CountryField('country'); | ||
$choices = $field->getOtherChoices(); | ||
|
||
$this->assertArrayHasKey('DE', $choices); | ||
$this->assertEquals('Deutschland', $choices['DE']); | ||
$this->assertArrayHasKey('GB', $choices); | ||
$this->assertEquals('Vereinigtes Königreich', $choices['GB']); | ||
$this->assertArrayHasKey('US', $choices); | ||
$this->assertEquals('Vereinigte Staaten', $choices['US']); | ||
$this->assertArrayHasKey('FR', $choices); | ||
$this->assertEquals('Frankreich', $choices['FR']); | ||
$this->assertArrayHasKey('MY', $choices); | ||
$this->assertEquals('Malaysia', $choices['MY']); | ||
} | ||
|
||
public function testUnknownCountryIsNotIncluded() | ||
{ | ||
$field = new CountryField('country'); | ||
$choices = $field->getOtherChoices(); | ||
|
||
$this->assertArrayNotHasKey('ZZ', $choices); | ||
} | ||
} |