1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/**
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Backend\Controller\Adminhtml\Ajax;
use Magento\Backend\App\Action;
class Translate extends \Magento\Backend\App\Action
{
/**
* @var \Magento\Framework\Translate\Inline\ParserInterface
*/
protected $inlineParser;
/**
* @var \Magento\Framework\Controller\Result\JsonFactory
*/
protected $resultJsonFactory;
/**
* Authorization level of a basic admin session
*/
const ADMIN_RESOURCE = 'Magento_Backend::content_translation';
/**
* @param Action\Context $context
* @param \Magento\Framework\Translate\Inline\ParserInterface $inlineParser
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
*/
public function __construct(
Action\Context $context,
\Magento\Framework\Translate\Inline\ParserInterface $inlineParser,
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
) {
parent::__construct($context);
$this->resultJsonFactory = $resultJsonFactory;
$this->inlineParser = $inlineParser;
}
/**
* Ajax action for inline translation
*
* @return \Magento\Framework\Controller\Result\Json
*/
public function execute()
{
$translate = (array)$this->getRequest()->getPost('translate');
/** @var \Magento\Framework\Controller\Result\Json $resultJson */
$resultJson = $this->resultJsonFactory->create();
try {
$this->inlineParser->processAjaxPost($translate);
$response = ['success' => 'true'];
} catch (\Exception $e) {
$response = ['error' => 'true', 'message' => $e->getMessage()];
}
$this->_actionFlag->set('', self::FLAG_NO_POST_DISPATCH, true);
return $resultJson->setData($response);
}
}