Magento Extensions Rating 2024
EXTENSIONS BY CATEGORY
B2B (Business-To-Business)
Blog
Customer
ERP (Enterprise Resource Planning)
Mega Menu
One Step Checkout
Order
POS (Point Of Sale)
Search
Shopping Cart
Sitemap
SEO
Social
Stock & Inventory Management
EXTENSIONS BY DEVELOPER
aheadWorks
Amasty
Boost My Shop
BSS Commerce
Magestore
MageWorx
Mirasvit
Templates Master
Wyomind
XTENTO
Magento 2 Documentation
Magento 2 Documentation
2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
vendor
magento
module-translation
Model
Js
PreProcessor.php
Go to the documentation of this file.
1
<?php
6
namespace
Magento\Translation\Model\Js
;
7
8
use
Magento\Framework\App\AreaList
;
9
use
Magento\Framework\TranslateInterface
;
10
use
Magento\Framework\View\Asset\File\FallbackContext
;
11
use
Magento\Framework\View\Asset\PreProcessor\Chain
;
12
use
Magento\Framework\View\Asset\PreProcessorInterface
;
13
17
class
PreProcessor
implements
PreProcessorInterface
18
{
24
protected
$config
;
25
29
protected
$areaList
;
30
34
protected
$translate
;
35
41
public
function
__construct
(
Config
$config
,
AreaList
$areaList
,
TranslateInterface
$translate
)
42
{
43
$this->config =
$config
;
44
$this->areaList =
$areaList
;
45
$this->
translate
=
$translate
;
46
}
47
54
public
function
process
(
Chain
$chain)
55
{
56
if
($this->config->isEmbeddedStrategy()) {
57
$context = $chain->
getAsset
()->getContext();
58
59
$areaCode =
\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE
;
60
61
if
($context instanceof
FallbackContext
) {
62
$areaCode = $context->getAreaCode();
63
$this->
translate
->setLocale($context->getLocale());
64
}
65
66
$area = $this->areaList->getArea($areaCode);
67
$area->load(\
Magento
\Framework\
App
\Area::PART_TRANSLATE);
68
69
$chain->
setContent
($this->
translate
($chain->
getContent
()));
70
}
71
}
72
79
public
function
translate
(
$content
)
80
{
81
foreach
($this->config->getPatterns() as
$pattern
) {
82
$content
= preg_replace_callback(
$pattern
, [$this,
'replaceCallback'
],
$content
);
83
}
84
return
$content
;
85
}
86
93
protected
function
replaceCallback
($matches)
94
{
95
return
'"'
.
__
($matches[1]) .
'"'
;
96
}
97
}
Magento\Translation\Model\Js\PreProcessor\$areaList
$areaList
Definition:
PreProcessor.php:29
Magento\Framework\App
Magento\Translation\Model\Js
$pattern
$pattern
Definition:
website.php:22
Magento\Framework\View\Asset\PreProcessor\Chain\setContent
setContent($content)
Definition:
Chain.php:126
Magento\Translation\Model\Js\PreProcessor\replaceCallback
replaceCallback($matches)
Definition:
PreProcessor.php:93
__
__()
Definition:
__.php:13
Magento\Translation\Model\Js\Config
Definition:
Config.php:14
Magento\Translation\Model\Js\PreProcessor\process
process(Chain $chain)
Definition:
PreProcessor.php:54
Magento\Backend\App\Area\FrontNameResolver\AREA_CODE
const AREA_CODE
Definition:
FrontNameResolver.php:33
Magento\Framework\View\Asset\File\FallbackContext
Definition:
FallbackContext.php:17
Magento\Translation\Model\Js\PreProcessor\$translate
$translate
Definition:
PreProcessor.php:34
Magento\Translation\Model\Js\PreProcessor\translate
translate($content)
Definition:
PreProcessor.php:79
Magento\Framework\App\AreaList
Definition:
AreaList.php:10
Magento\Framework\TranslateInterface
Definition:
TranslateInterface.php:11
Magento
Magento\Translation\Model\Js\PreProcessor
Definition:
PreProcessor.php:17
$content
$content
Definition:
downloadable_product_with_files_and_sample_url.php:93
Magento\Framework\View\Asset\PreProcessor\Chain\getAsset
getAsset()
Definition:
Chain.php:95
Magento\Framework\View\Asset\PreProcessor\Chain\getContent
getContent()
Definition:
Chain.php:115
Magento\Translation\Model\Js\PreProcessor\__construct
__construct(Config $config, AreaList $areaList, TranslateInterface $translate)
Definition:
PreProcessor.php:41
Magento\Framework\App\AreaList
Definition:
Proxy.php:8
Magento\Framework\View\Asset\PreProcessorInterface
Definition:
PreProcessorInterface.php:14
Magento\Translation\Model\Js\PreProcessor\$config
$config
Definition:
PreProcessor.php:24
Magento\Framework\View\Asset\PreProcessor\Chain
Definition:
Chain.php:18