Skip to content

Commit c1eeed2

Browse files
author
Zach Nanninga
committed
ISSUE-28656 - Prevent inline translation markup from being added to translated phrases for areas other than frontend and adminhtml.
1 parent 8d90d12 commit c1eeed2

File tree

1 file changed

+35
-1
lines changed
  • lib/internal/Magento/Framework/Translate

1 file changed

+35
-1
lines changed

lib/internal/Magento/Framework/Translate/Inline.php

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,19 @@ class Inline implements \Magento\Framework\Translate\InlineInterface
6969
*/
7070
protected $state;
7171

72+
/**
73+
* @var array
74+
*/
75+
private $allowedAreas = [
76+
\Magento\Framework\App\Area::AREA_FRONTEND,
77+
\Magento\Framework\App\Area::AREA_ADMINHTML
78+
];
79+
80+
/**
81+
* @var \Magento\Framework\App\State
82+
*/
83+
private $appState;
84+
7285
/**
7386
* Initialize inline translation model
7487
*
@@ -78,6 +91,7 @@ class Inline implements \Magento\Framework\Translate\InlineInterface
7891
* @param Inline\ConfigInterface $config
7992
* @param Inline\ParserInterface $parser
8093
* @param Inline\StateInterface $state
94+
* @param \Magento\Framework\App\State $appState
8195
* @param string $templateFileName
8296
* @param string $translatorRoute
8397
* @param null $scope
@@ -89,6 +103,7 @@ public function __construct(
89103
\Magento\Framework\Translate\Inline\ConfigInterface $config,
90104
\Magento\Framework\Translate\Inline\ParserInterface $parser,
91105
\Magento\Framework\Translate\Inline\StateInterface $state,
106+
\Magento\Framework\App\State $appState,
92107
$templateFileName = '',
93108
$translatorRoute = '',
94109
$scope = null
@@ -99,6 +114,7 @@ public function __construct(
99114
$this->config = $config;
100115
$this->parser = $parser;
101116
$this->state = $state;
117+
$this->appState = $appState;
102118
$this->templateFileName = $templateFileName;
103119
$this->translatorRoute = $translatorRoute;
104120
$this->scope = $scope;
@@ -115,7 +131,8 @@ public function isAllowed()
115131
if (!$this->scope instanceof \Magento\Framework\App\ScopeInterface) {
116132
$scope = $this->scopeResolver->getScope($this->scope);
117133
}
118-
$this->isAllowed = $this->config->isActive($scope)
134+
$this->isAllowed = $this->isAreaAllowed()
135+
&& $this->config->isActive($scope)
119136
&& $this->config->isDevAllowed($scope);
120137
}
121138
return $this->state->isEnabled() && $this->isAllowed;
@@ -249,4 +266,21 @@ protected function stripInlineTranslations(&$body)
249266
}
250267
return $this;
251268
}
269+
270+
/**
271+
* Indicates whether the current area is valid for inline translation
272+
*
273+
* @return bool
274+
*/
275+
private function isAreaAllowed()
276+
{
277+
try {
278+
return in_array(
279+
$this->appState->getAreaCode(),
280+
$this->allowedAreas
281+
);
282+
} catch (\Magento\Framework\Exception\LocalizedException $e) {
283+
return false;
284+
}
285+
}
252286
}

0 commit comments

Comments
 (0)