Skip to content

Commit

Permalink
[Form][Locale] Implemented LocaleField and added script for updating …
Browse files Browse the repository at this point in the history
…ICU data
  • Loading branch information
Bernhard Schussek authored and fabpot committed Jan 2, 2011
1 parent d8b8ae0 commit b9c2e98
Show file tree
Hide file tree
Showing 585 changed files with 421 additions and 6 deletions.
23 changes: 23 additions & 0 deletions src/Symfony/Component/Form/LocaleField.php
@@ -0,0 +1,23 @@
<?php

namespace Symfony\Component\Form;

use Symfony\Component\Locale\Locale;

/**
* A field for selecting from a list of locales
*
* @author Bernhard Schussek <bernhard.schussek@symfony-project.com>
*/
class LocaleField extends ChoiceField
{
/**
* @inheritDoc
*/
protected function configure()
{
$this->addOption('choices', Locale::getDisplayLocales($this->locale));

parent::configure();
}
}
48 changes: 48 additions & 0 deletions src/Symfony/Component/Locale/Locale.php
Expand Up @@ -25,6 +25,12 @@ class Locale extends \Locale
*/
protected static $languages = array();

/**
* Caches the different locales
* @var array
*/
protected static $locales = array();

/**
* Returns the country names for a locale
*
Expand Down Expand Up @@ -116,4 +122,46 @@ public static function getLanguages()
{
return array_keys(self::getDisplayLanguages(self::getDefault()));
}

/**
* Returns the locale names for a locale
*
* @param string $locale The locale to use for the locale names
* @return array The locale names with their codes as keys
* @throws RuntimeException When the resource bundles cannot be loaded
*/
public static function getDisplayLocales($locale)
{
if (!isset(self::$locales[$locale])) {
$bundle = new \ResourceBundle($locale, __DIR__.'/Resources/data/names');

if (null === $bundle) {
throw new \RuntimeException('The locale resource bundle could not be loaded');
}

$collator = new \Collator($locale);
$locales = array();

foreach ($bundle->get('Locales') as $code => $name) {
$locales[$code] = $name;
}

$collator->asort($locales);

self::$locales[$locale] = $locales;
}

return self::$locales[$locale];
}

/**
* Returns all available locale codes
*
* @return array The locale codes
* @throws RuntimeException When the resource bundles cannot be loaded
*/
public static function getLocales()
{
return array_keys(self::getDisplayLocales(self::getDefault()));
}
}
8 changes: 2 additions & 6 deletions src/Symfony/Component/Locale/Resources/data/UPDATE.txt
Expand Up @@ -5,13 +5,9 @@ How to update the ICU data

$ svn co http://source.icu-project.org/repos/icu/icu/trunk/source/data icu-data

2. Build the region resource bundles
2. Execute the build script

$ cd icu-data/region
$ mkdir build
$ genrb -d build *.txt

3a. Replace the *.res files bundled with Symfony2 with the new ones.
$ php update-data.php /path/to/icu-data

.dat-package
------------
Expand Down
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 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 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.

0 comments on commit b9c2e98

Please sign in to comment.