Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Manager.php
Go to the documentation of this file.
1 <?php
7 
15 class Manager
16 {
20  protected $_session;
21 
25  protected $_authSession;
26 
30  protected $_translator;
31 
36  protected $_backendConfig;
37 
46  public function __construct(
47  \Magento\Backend\Model\Session $session,
48  \Magento\Backend\Model\Auth\Session $authSession,
49  \Magento\Framework\TranslateInterface $translator,
50  \Magento\Backend\App\ConfigInterface $backendConfig
51  ) {
52  $this->_session = $session;
53  $this->_authSession = $authSession;
54  $this->_translator = $translator;
55  $this->_backendConfig = $backendConfig;
56  }
57 
64  public function switchBackendInterfaceLocale($localeCode)
65  {
66  $this->_session->setSessionLocale(null);
67 
68  $this->_authSession->getUser()->setInterfaceLocale($localeCode);
69 
70  $this->_translator->setLocale($localeCode)->loadData(null, true);
71 
72  return $this;
73  }
74 
81  public function getGeneralLocale()
82  {
83  return $this->_backendConfig->getValue('general/locale/code');
84  }
85 
91  public function getUserInterfaceLocale()
92  {
93  $userData = $this->_authSession->getUser();
95 
96  if ($userData && $userData->getInterfaceLocale()) {
97  $interfaceLocale = $userData->getInterfaceLocale();
98  } elseif ($this->getGeneralLocale()) {
99  $interfaceLocale = $this->getGeneralLocale();
100  }
101 
102  return $interfaceLocale;
103  }
104 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
__construct(\Magento\Backend\Model\Session $session, \Magento\Backend\Model\Auth\Session $authSession, \Magento\Framework\TranslateInterface $translator, \Magento\Backend\App\ConfigInterface $backendConfig)
Definition: Manager.php:46
switchBackendInterfaceLocale($localeCode)
Definition: Manager.php:64