[Form] Implemented LanguageField

This commit is contained in:
Bernhard Schussek 2010-12-15 18:29:20 +01:00 committed by Fabien Potencier
parent 9db7db4439
commit 93d3716a84
238 changed files with 96 additions and 0 deletions

View File

@ -0,0 +1,60 @@
<?php
namespace Symfony\Component\Form;
/**
* A field for selecting from a list of languages
*
* @author Bernhard Schussek <bernhard.schussek@symfony-project.com>
*/
class LanguageField extends ChoiceField
{
/**
* Caches the language choices in different locales
* @var array
*/
protected static $languages;
/**
* @inheritDoc
*/
protected function configure()
{
$this->addOption('choices', self::getLanguageChoices($this->locale));
parent::configure();
}
/**
* Returns the list of languages for a locale
*
* @param string $locale The locale to use for the language names
* @throws RuntimeException When the resource bundles cannot be loaded
*/
protected static function getLanguageChoices($locale)
{
if (!isset(self::$languages[$locale])) {
$bundle = new \ResourceBundle($locale, __DIR__.'/Resources/data/lang');
if ($bundle === null) {
throw new RuntimeException('The language resource bundle could not be loaded');
}
$collator = new \Collator($locale);
$languages = array();
foreach ($bundle->get('Languages') as $code => $name) {
// "mul" is the code for multiple languages
if ($code !== 'mul') {
$languages[$code] = $name;
}
}
$collator->asort($languages);
self::$languages[$locale] = $languages;
}
return self::$languages[$locale];
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Some files were not shown because too many files have changed in this diff Show More