2323use Magento \Framework \Filter \Template \Tokenizer \Parameter ;
2424use Magento \Framework \Filter \VariableResolverInterface ;
2525use Magento \Framework \Stdlib \StringUtils ;
26+ use Magento \Framework \Translate \Inline \StateInterface ;
2627use Magento \Framework \UrlInterface ;
2728use Magento \Framework \View \Asset \ContentProcessorException ;
2829use Magento \Framework \View \Asset \ContentProcessorInterface ;
@@ -53,12 +54,12 @@ class Filter extends Template
5354 /**
5455 * The name used in the {{trans}} directive
5556 */
56- const TRANS_DIRECTIVE_NAME = 'trans ' ;
57+ public const TRANS_DIRECTIVE_NAME = 'trans ' ;
5758
5859 /**
5960 * The regex to match interior portion of a {{trans "foo"}} translation directive
6061 */
61- const TRANS_DIRECTIVE_REGEX = '/^\s*([ \'"])([^\1]*?)(?<! \\\)\1(\s.*)?$/si ' ;
62+ public const TRANS_DIRECTIVE_REGEX = '/^\s*([ \'"])([^\1]*?)(?<! \\\)\1(\s.*)?$/si ' ;
6263
6364 /**
6465 * @var bool
@@ -119,8 +120,6 @@ class Filter extends Template
119120
120121 /**
121122 * Core store config
122- * Variable factory
123- *
124123 * @var VariableFactory
125124 */
126125 protected $ _variableFactory ;
@@ -190,6 +189,11 @@ class Filter extends Template
190189 */
191190 private $ storeInformation ;
192191
192+ /**
193+ * @var StateInterface
194+ */
195+ private $ inlineTranslationState ;
196+
193197 /**
194198 * Filter constructor.
195199 * @param StringUtils $string
@@ -211,6 +215,7 @@ class Filter extends Template
211215 * @param array $variables
212216 * @param array $directiveProcessors
213217 * @param StoreInformation|null $storeInformation
218+ * @param StateInterface|null $inlineTranslationState
214219 * @SuppressWarnings(PHPMD.ExcessiveParameterList)
215220 */
216221 public function __construct (
@@ -232,7 +237,8 @@ public function __construct(
232237 CssInliner $ cssInliner ,
233238 $ variables = [],
234239 array $ directiveProcessors = [],
235- ?StoreInformation $ storeInformation = null
240+ ?StoreInformation $ storeInformation = null ,
241+ StateInterface $ inlineTranslationState = null
236242 ) {
237243 $ this ->_escaper = $ escaper ;
238244 $ this ->_assetRepo = $ assetRepo ;
@@ -251,6 +257,8 @@ public function __construct(
251257 $ this ->configVariables = $ configVariables ;
252258 $ this ->storeInformation = $ storeInformation ?:
253259 ObjectManager::getInstance ()->get (StoreInformation::class);
260+ $ this ->inlineTranslationState = $ inlineTranslationState ?:
261+ ObjectManager::getInstance ()->get (StateInterface::class);
254262 parent ::__construct ($ string , $ variables , $ directiveProcessors , $ variableResolver );
255263 }
256264
@@ -616,8 +624,9 @@ public function transDirective($construction)
616624 if (empty ($ text )) {
617625 return '' ;
618626 }
619-
627+ $ this -> inlineTranslationState -> disable ();
620628 $ text = __ ($ text , $ params )->render ();
629+ $ this ->inlineTranslationState ->enable ();
621630 return $ this ->applyModifiers ($ text , $ modifiers );
622631 }
623632
0 commit comments