Example #1
0
 /**
  * Switch backend locale according to locale code
  *
  * @param string $localeCode
  * @return $this
  */
 public function switchBackendInterfaceLocale($localeCode)
 {
     $this->_session->setSessionLocale(null);
     $this->_authSession->getUser()->setInterfaceLocale($localeCode);
     $this->_translator->setLocale($localeCode)->loadData(null, true);
     return $this;
 }
Example #2
0
 public function testRenderIfInlineTranslationIsAllowed()
 {
     $theme = 'theme';
     $text = 'test';
     $result = sprintf('{{{%s}}{{%s}}}', $text, $theme);
     $this->translator->expects($this->once())->method('getTheme')->will($this->returnValue($theme));
     $inlineTranslate = $this->getMock('Magento\\Framework\\Translate\\InlineInterface', [], [], '', []);
     $inlineTranslate->expects($this->once())->method('isAllowed')->will($this->returnValue(true));
     $this->provider->expects($this->once())->method('get')->will($this->returnValue($inlineTranslate));
     $this->assertEquals($result, $this->renderer->render([$text], []));
 }
Example #3
0
 protected function setUp()
 {
     $this->_session = $this->getMock('Magento\\Backend\\Model\\Session', [], [], '', false);
     $this->_authSession = $this->getMock('Magento\\Backend\\Model\\Auth\\Session', ['getUser'], [], '', false);
     $userMock = new \Magento\Framework\Object();
     $this->_authSession->expects($this->any())->method('getUser')->will($this->returnValue($userMock));
     $this->_translator = $this->getMock('Magento\\Framework\\TranslateInterface', [], [], '', false);
     $this->_translator->expects($this->any())->method('setLocale')->will($this->returnValue($this->_translator));
     $this->_translator->expects($this->any())->method('init')->will($this->returnValue(false));
     $this->_model = new \Magento\Backend\Model\Locale\Manager($this->_session, $this->_authSession, $this->_translator);
 }
Example #4
0
 /**
  * Render source text
  *
  * @param [] $source
  * @param [] $arguments
  * @return string
  * @throws \Exception
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function render(array $source, array $arguments)
 {
     $text = end($source);
     try {
         $data = $this->translator->getData();
     } catch (\Exception $e) {
         $this->logger->critical($e->getMessage());
         throw $e;
     }
     return array_key_exists($text, $data) ? $data[$text] : $text;
 }
Example #5
0
 /**
  * Render source text
  *
  * @param [] $source
  * @param [] $arguments
  * @return string
  */
 public function render(array $source, array $arguments)
 {
     $text = end($source);
     if (!$this->inlineProvider->get()->isAllowed()) {
         return $text;
     }
     if (strpos($text, '{{{') === false || strpos($text, '}}}') === false || strpos($text, '}}{{') === false) {
         $text = '{{{' . implode('}}{{', array_reverse($source)) . '}}{{' . $this->translator->getTheme() . '}}}';
     }
     return $text;
 }
Example #6
0
 /**
  * Render source text
  *
  * @param [] $source
  * @param [] $arguments
  * @return string
  */
 public function render(array $source, array $arguments)
 {
     $text = end($source);
     $code = $this->translator->getTheme() . '::' . $text;
     $data = $this->translator->getData();
     if (array_key_exists($code, $data)) {
         return $data[$code];
     }
     if (array_key_exists($text, $data)) {
         return $data[$text];
     }
     return $text;
 }
 /**
  * Transform content and/or content type for the specified preprocessing chain object
  *
  * @param Chain $chain
  * @return void
  */
 public function process(Chain $chain)
 {
     if ($this->config->isEmbeddedStrategy()) {
         $context = $chain->getAsset()->getContext();
         $areaCode = \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE;
         if ($context instanceof FallbackContext) {
             $areaCode = $context->getAreaCode();
             $this->translate->setLocale($context->getLocale());
         }
         $area = $this->areaList->getArea($areaCode);
         $area->load(\Magento\Framework\App\Area::PART_TRANSLATE);
         $chain->setContent($this->translate($chain->getContent()));
     }
 }
Example #8
0
 /**
  * Render source text
  *
  * @param [] $source
  * @param [] $arguments
  * @return string
  * @throws \Exception
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function render(array $source, array $arguments)
 {
     $text = end($source);
     /* If phrase contains escaped quotes then use translation for phrase with non-escaped quote */
     $text = str_replace('\\"', '"', $text);
     $text = str_replace("\\'", "'", $text);
     try {
         $data = $this->translator->getData();
     } catch (\Exception $e) {
         $this->logger->critical($e->getMessage());
         throw $e;
     }
     return array_key_exists($text, $data) ? $data[$text] : end($source);
 }
Example #9
0
 /**
  * Render source text
  *
  * @param [] $source
  * @param [] $arguments
  * @return string
  * @throws \Exception
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function render(array $source, array $arguments)
 {
     $text = end($source);
     try {
         if (!$this->inlineProvider->get()->isAllowed()) {
             return $text;
         }
         if (strpos($text, '{{{') === false || strpos($text, '}}}') === false || strpos($text, '}}{{') === false) {
             $text = '{{{' . implode('}}{{', array_reverse($source)) . '}}{{' . $this->translator->getTheme() . '}}}';
         }
     } catch (\Exception $e) {
         $this->logger->critical($e->getMessage());
         throw $e;
     }
     return $text;
 }
Example #10
0
 /**
  * Restore locale of the initial store
  *
  * @param string $initialLocaleCode
  * @param string $initialArea
  * @return $this
  */
 protected function _restoreInitialLocale($initialLocaleCode, $initialArea = \Magento\Framework\App\Area::AREA_ADMIN)
 {
     $this->_localeResolver->setLocale($initialLocaleCode);
     $this->_translate->setLocale($initialLocaleCode);
     $this->_translate->loadData($initialArea);
     return $this;
 }
Example #11
0
 public function testStop()
 {
     // Test data
     $initArea = 'initial area';
     $initTheme = 'initial design theme';
     $initLocale = 'initial locale code';
     $initialStore = 1;
     $initTranslateInline = false;
     $this->inlineTranslationMock->expects($this->once())->method('isEnabled')->willReturn($initTranslateInline);
     $this->viewDesignMock->expects($this->once())->method('getArea')->willReturn($initArea);
     $this->viewDesignMock->expects($this->once())->method('getDesignTheme')->willReturn($initTheme);
     $this->storeManagerMock->expects($this->any())->method('getStore')->willReturn($this->storeMock);
     $this->storeMock->expects($this->once())->method('getStoreId')->willReturn($initialStore);
     $this->localeResolverMock->expects($this->once())->method('getLocale')->willReturn($initLocale);
     $this->model->storeCurrentEnvironmentInfo();
     // Expectations
     $this->inlineTranslationMock->expects($this->once())->method('resume')->with($initTranslateInline);
     $this->viewDesignMock->expects($this->once())->method('setDesignTheme')->with($initTheme, $initArea);
     $this->storeManagerMock->expects($this->once())->method('setCurrentStore')->with($initialStore);
     $this->localeResolverMock->expects($this->once())->method('setLocale')->with($initLocale);
     $this->translateMock->expects($this->once())->method('setLocale')->with($initLocale);
     $this->translateMock->expects($this->once())->method('loadData')->with($initArea);
     // Test
     $this->model->stopEnvironmentEmulation();
 }
Example #12
0
 /**
  * Transform content and/or content type for the specified preprocessing chain object
  *
  * @param Chain $chain
  * @return void
  */
 public function process(Chain $chain)
 {
     if ($this->isDictionaryPath($chain->getTargetAssetPath())) {
         $context = $chain->getAsset()->getContext();
         $themePath = '*/*';
         $areaCode = \Magento\Backend\App\Area\FrontNameResolver::AREA_CODE;
         if ($context instanceof FallbackContext) {
             $themePath = $context->getThemePath();
             $areaCode = $context->getAreaCode();
             $this->translate->setLocale($context->getLocale());
         }
         $area = $this->areaList->getArea($areaCode);
         $area->load(\Magento\Framework\App\Area::PART_TRANSLATE);
         $chain->setContent(json_encode($this->dataProvider->getData($themePath)));
         $chain->setContentType('json');
     }
 }
Example #13
0
 /**
  * Initialize translate object.
  *
  * @return $this
  */
 protected function _initTranslate()
 {
     $this->_translator->loadData(null, false);
     \Magento\Framework\Phrase::setRenderer($this->_objectManager->get('Magento\\Framework\\Phrase\\RendererInterface'));
     return $this;
 }
Example #14
0
 /**
  * @param string|null $localeCode
  * @return void
  */
 protected function _init($localeCode)
 {
     if ($localeCode !== null) {
         $this->_translate->setLocale($localeCode)->loadData();
     }
 }
Example #15
0
 /**
  * @param string|null $localeCode
  * @return void
  */
 protected function _init($localeCode)
 {
     if (!is_null($localeCode)) {
         $this->_translate->setLocale($localeCode)->loadData(null, true);
     }
 }
Example #16
0
 /**
  * Render source text
  *
  * @param [] $source
  * @param [] $arguments
  * @return string
  */
 public function render(array $source, array $arguments)
 {
     $text = end($source);
     $data = $this->translator->getData();
     return array_key_exists($text, $data) ? $data[$text] : $text;
 }