retrieve local from session in translator
This commit is contained in:
@@ -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 -->
|
||||
|
||||
@@ -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}
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user