Skip to content

Commit 7522b39

Browse files
committed
MAGETWO-30169: Gather all phrases and compile a file
1 parent d96b3b9 commit 7522b39

File tree

8 files changed

+18
-88
lines changed

8 files changed

+18
-88
lines changed

app/code/Magento/Translation/Block/Js.php

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,61 +6,30 @@
66

77
namespace Magento\Translation\Block;
88

9-
use Magento\Framework\Translate\InlineInterface as InlineTranslator;
10-
use Magento\Translation\Model\Js as DataProvider;
119
use Magento\Framework\View\Element\Template;
1210
use Magento\Translation\Model\Js\Config;
1311

14-
class Js extends \Magento\Framework\View\Element\Template
12+
class Js extends Template
1513
{
16-
/**
17-
* Data provider model
18-
*
19-
* @var DataProvider
20-
*/
21-
protected $dataProvider;
22-
23-
/**
24-
* Inline translator
25-
*
26-
* @var InlineTranslator
27-
*/
28-
protected $translateInline;
29-
3014
/**
3115
* @var Config
3216
*/
3317
protected $config;
3418

3519
/**
3620
* @param Template\Context $context
37-
* @param DataProvider $dataProvider
38-
* @param InlineTranslator $translateInline
21+
* @param Config $config
3922
* @param array $data
4023
*/
4124
public function __construct(
4225
Template\Context $context,
43-
DataProvider $dataProvider,
44-
InlineTranslator $translateInline,
4526
Config $config,
4627
array $data = []
4728
) {
4829
parent::__construct($context, $data);
49-
$this->dataProvider = $dataProvider;
50-
$this->translateInline = $translateInline;
5130
$this->config = $config;
5231
}
5332

54-
/**
55-
* @return string
56-
*/
57-
public function getTranslatedJson()
58-
{
59-
$data = $this->dataProvider->getTranslateData();
60-
$this->translateInline->processResponseBody($data);
61-
return \Zend_Json::encode($data);
62-
}
63-
6433
/**
6534
* Is js translation set to dictionary mode
6635
*

app/code/Magento/Translation/Model/Js.php

Lines changed: 0 additions & 42 deletions
This file was deleted.

app/code/Magento/Translation/Model/Js/DataProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ public function __construct(State $appState, Config $config)
4242
/**
4343
* Get translation data
4444
*/
45-
public function getData()
45+
public function getData($themePath)
4646
{
4747
$dictionary = [];
4848

49-
$files = $this->filesUtility->getJsFilesForArea($this->appState->getAreaCode());
49+
$files = $this->filesUtility->getJsFiles($this->appState->getAreaCode(), $themePath);
5050
foreach ($files as $filePath) {
5151
foreach ($this->getPhrases(file_get_contents($filePath)) as $phrase) {
5252
$translatedPhrase = (string) __($phrase);

app/code/Magento/Translation/Model/Js/DataProviderInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ interface DataProviderInterface
1313
*
1414
* @return string[]
1515
*/
16-
public function getData();
16+
public function getData($themePath);
1717
}

app/code/Magento/Translation/Model/Json/PreProcessor.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Magento\Translation\Model\Js\Config;
1010
use Magento\Translation\Model\Js\DataProviderInterface;
1111
use Magento\Framework\View\Asset\PreProcessor\Chain;
12+
use Magento\Framework\View\Asset\File\FallbackContext;
1213

1314
/**
1415
* PreProcessor responsible for providing js translation dictionary
@@ -46,7 +47,9 @@ public function __construct(
4647
public function process(Chain $chain)
4748
{
4849
if ($this->isDictionaryPath($chain->getTargetAssetPath())) {
49-
$chain->setContent(json_encode($this->dataProvider->getData()));
50+
$context = $chain->getAsset()->getContext();
51+
$themePath = ($context instanceof FallbackContext) ? $context->getThemePath() : '*/*';
52+
$chain->setContent(json_encode($this->dataProvider->getData($themePath)));
5053
$chain->setContentType('json');
5154
}
5255
}

app/code/Magento/Translation/etc/config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
</invalid_caches>
1717
</translate_inline>
1818
<js>
19-
<translate_strategy>publishing</translate_strategy>
19+
<translate_strategy>embedded</translate_strategy>
2020
</js>
2121
</dev>
2222
</default>

lib/internal/Magento/Framework/Test/Utility/Files.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -459,18 +459,18 @@ public function getPageTypeFiles($incomingParams = [], $asDataSet = true)
459459
/**
460460
* Returns list of Javascript files in Magento
461461
*
462+
* @param string $area
463+
* @param string $themePath
464+
* @param string $namespace
465+
* @param string $module
462466
* @return array
463467
*/
464-
public function getJsFiles()
468+
public function getJsFiles($area = '*', $themePath = '*/*', $namespace = '*', $module = '*')
465469
{
466-
$key = __METHOD__ . $this->_path;
470+
$key = $area . $themePath . $namespace . $module . __METHOD__ . $this->_path;
467471
if (isset(self::$_cache[$key])) {
468472
return self::$_cache[$key];
469473
}
470-
$namespace = '*';
471-
$module = '*';
472-
$area = '*';
473-
$themePath = '*/*';
474474
$files = self::getFiles(
475475
[
476476
"{$this->_path}/app/code/{$namespace}/{$module}/view/{$area}/web",

lib/internal/Magento/Framework/View/Asset/Repository.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,12 +152,12 @@ public function createAsset($fileId, array $params = [])
152152
$module = $params['module'];
153153
}
154154
$isSecure = isset($params['_secure']) ? (bool) $params['_secure'] : null;
155-
$themePath = $this->design->getThemePath($params['themeModel']);
155+
$themePath = isset($params['theme']) ? $params['theme'] : $this->design->getThemePath($params['themeModel']);
156156
$context = $this->getFallbackContext(
157157
UrlInterface::URL_TYPE_STATIC,
158158
$isSecure,
159159
$params['area'],
160-
$themePath,
160+
$themePath ,
161161
$params['locale']
162162
);
163163
return new File(

0 commit comments

Comments
 (0)