renamed culture to locale (patch from henrikbjorn)

This commit is contained in:
Fabien Potencier 2010-06-07 10:10:00 +02:00
parent aa050e2f08
commit 28f4bccb33
6 changed files with 26 additions and 26 deletions

View File

@ -489,25 +489,25 @@ class Request
/**
* Returns the preferred language.
*
* @param array $cultures An array of ordered available cultures
* @param array $locales An array of ordered available locales
*
* @return string The preferred culture
* @return string The preferred locale
*/
public function getPreferredLanguage(array $cultures = null)
public function getPreferredLanguage(array $locales = null)
{
$preferredLanguages = $this->getLanguages();
if (null === $cultures) {
if (null === $locales) {
return isset($preferredLanguages[0]) ? $preferredLanguages[0] : null;
}
if (!$preferredLanguages) {
return $cultures[0];
return $locales[0];
}
$preferredLanguages = array_values(array_intersect($preferredLanguages, $cultures));
$preferredLanguages = array_values(array_intersect($preferredLanguages, $locales));
return isset($preferredLanguages[0]) ? $preferredLanguages[0] : $cultures[0];
return isset($preferredLanguages[0]) ? $preferredLanguages[0] : $locales[0];
}
/**

View File

@ -68,8 +68,8 @@ class WebExtension extends LoaderExtension
$configuration->merge($loader->load($this->resources['user']));
}
if (isset($config['default_culture'])) {
$configuration->setParameter('user.default_culture', $config['default_culture']);
if (isset($config['default_locale'])) {
$configuration->setParameter('user.default_locale', $config['default_locale']);
}
if (isset($config['class'])) {

View File

@ -49,13 +49,13 @@ class UserHelper extends Helper
}
/**
* Returns the user culture
* Returns the user locale
*
* @return string
*/
public function getCulture()
public function getLocale()
{
return $this->user->getCulture();
return $this->user->getLocale();
}
public function getFlash($name, $default = null)

View File

@ -15,7 +15,7 @@
</xsd:sequence>
<xsd:attribute name="class" type="xsd:string" />
<xsd:attribute name="default_culture" type="xsd:string" />
<xsd:attribute name="default_locale" type="xsd:string" />
</xsd:complexType>
<xsd:complexType name="session">

View File

@ -6,7 +6,7 @@
<parameters>
<parameter key="user.class">Symfony\Framework\WebBundle\User</parameter>
<parameter key="user.default_culture">en</parameter>
<parameter key="user.default_locale">en</parameter>
<parameter key="user.session.class">Symfony\Framework\WebBundle\Session\NativeSession</parameter>
<parameter key="user.session.pdo.class">Symfony\Framework\WebBundle\Session\PdoSession</parameter>
<parameter key="session.options.name">SYMFONY_SESSION</parameter>
@ -25,7 +25,7 @@
<argument type="service" id="event_dispatcher" />
<argument type="service" id="user.session" />
<argument type="collection">
<argument key="default_culture">%user.default_culture%</argument>
<argument key="default_locale">%user.default_locale%</argument>
</argument>
</service>

View File

@ -25,7 +25,7 @@ use Symfony\Framework\WebBundle\Session\SessionInterface;
class User
{
protected $session;
protected $culture;
protected $locale;
protected $attributes;
protected $oldFlashes;
@ -43,7 +43,7 @@ class User
$this->setAttributes($session->read('_user', array(
'_flash' => array(),
'_culture' => isset($options['default_culture']) ? $options['default_culture'] : 'en',
'_locale' => isset($options['default_locale']) ? $options['default_locale'] : 'en',
)));
// flag current flash to be removed at shutdown
@ -95,26 +95,26 @@ class User
}
/**
* Returns the user culture
* Returns the user locale
*
* @return string
*/
public function getCulture()
public function getLocale()
{
return $this->getAttribute('_culture');
return $this->getAttribute('_locale');
}
/**
* Sets the user culture.
* Sets the user locale.
*
* @param string $culture
* @param string $locale
*/
public function setCulture($culture)
public function setLocale($locale)
{
if ($this->culture != $culture) {
$this->setAttribute('_culture', $culture);
if ($this->locale != $locale) {
$this->setAttribute('_locale', $locale);
$this->dispatcher->notify(new Event($this, 'user.change_culture', array('culture' => $culture)));
$this->dispatcher->notify(new Event($this, 'user.change_locale', array('locale' => $locale)));
}
}