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