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 --> <!-- Translation and internationalisation -->
<service id="thelia.translator" class="Thelia\Core\Translation\Translator"> <service id="thelia.translator" class="Thelia\Core\Translation\Translator">
<argument>null</argument> <argument type="service" id="service_container"/>
</service> </service>
<!-- Security context for front and back office --> <!-- Security context for front and back office -->

View File

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