Index.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Translation\Controller\Ajax;
  8. class Index extends \Magento\Framework\App\Action\Action
  9. {
  10. /**
  11. * @var \Magento\Framework\Translate\Inline\ParserInterface
  12. */
  13. protected $inlineParser;
  14. /**
  15. * @param \Magento\Framework\App\Action\Context $context
  16. * @param \Magento\Framework\Translate\Inline\ParserInterface $inlineParser
  17. */
  18. public function __construct(
  19. \Magento\Framework\App\Action\Context $context,
  20. \Magento\Framework\Translate\Inline\ParserInterface $inlineParser
  21. ) {
  22. parent::__construct($context);
  23. $this->inlineParser = $inlineParser;
  24. }
  25. /**
  26. * Ajax action for inline translation
  27. *
  28. * @return void
  29. */
  30. public function execute()
  31. {
  32. $translate = (array)$this->getRequest()->getPost('translate');
  33. try {
  34. $response = $this->inlineParser->processAjaxPost($translate);
  35. } catch (\Exception $e) {
  36. $response = "{error:true,message:'" . $e->getMessage() . "'}";
  37. }
  38. $this->getResponse()->representJson(json_encode($response));
  39. $this->_actionFlag->set('', self::FLAG_NO_POST_DISPATCH, true);
  40. }
  41. }