retrieve local from session in translator

This commit is contained in:
Manuel Raynaud
2013-10-31 10:02:13 +01:00
parent 5be233c079
commit 8abe56458f
2 changed files with 17 additions and 2 deletions

View File

@@ -211,7 +211,7 @@
<!-- Translation and internationalisation -->
<service id="thelia.translator" class="Thelia\Core\Translation\Translator">
<argument>null</argument>
<argument type="service" id="service_container"/>
</service>
<!-- Security context for front and back office -->

View File

@@ -1,18 +1,28 @@
<?php
namespace Thelia\Core\Translation;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Translation\Translator as BaseTranslator;
class Translator extends BaseTranslator
{
/**
* @var \Symfony\Component\DependencyInjection\ContainerInterface
*/
protected $container;
protected static $instance = null;
public function __construct()
/**
* @param ContainerInterface $container
*/
public function __construct(ContainerInterface $container)
{
$this->container = $container;
// Allow singleton style calls once intanciated.
// For this to work, the Translator service has to be instanciated very early. This is done manually
// in TheliaHttpKernel, by calling $this->container->get('thelia.translator');
parent::__construct(null);
self::$instance = $this;
}
@@ -28,6 +38,11 @@ class Translator extends BaseTranslator
return self::$instance;
}
public function getLocale()
{
return $this->container->get('request')->getSession()->getLang()->getLocale();
}
/**
* {@inheritdoc}
*