Skip to content

Commit d0b7560

Browse files
committed
MAGETWO-72625: [2.3] - Translations from theme do not work(Authorize.net)
1 parent a1f3e7f commit d0b7560

File tree

9 files changed

+211
-119
lines changed

9 files changed

+211
-119
lines changed

app/code/Magento/Deploy/Service/DeployPackage.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,10 @@ public function __construct(
9595
public function deploy(Package $package, array $options, $skipLogging = false)
9696
{
9797
$result = $this->appState->emulateAreaCode(
98-
$package->getArea() == Package::BASE_AREA ? 'global' : $package->getArea(),
98+
$package->getArea() === Package::BASE_AREA ? 'global' : $package->getArea(),
9999
function () use ($package, $options, $skipLogging) {
100100
// emulate application locale needed for correct file path resolving
101101
$this->localeResolver->setLocale($package->getLocale());
102-
103102
$this->deployEmulated($package, $options, $skipLogging);
104103
}
105104
);
@@ -111,7 +110,7 @@ function () use ($package, $options, $skipLogging) {
111110
* @param Package $package
112111
* @param array $options
113112
* @param bool $skipLogging
114-
* @return int
113+
* @return bool
115114
*/
116115
public function deployEmulated(Package $package, array $options, $skipLogging = false)
117116
{
@@ -206,7 +205,7 @@ private function checkIfCanCopy(PackageFile $file, Package $package, Package $pa
206205
|| $file->getTheme() !== $package->getTheme()
207206
|| $file->getLocale() !== $package->getLocale()
208207
)
209-
&& $file->getOrigPackage() == $parentPackage
208+
&& $file->getOrigPackage() === $parentPackage
210209
&& $this->deployStaticFile->readFile($file->getDeployedFileId(), $parentPackage->getPath());
211210
}
212211

@@ -219,10 +218,10 @@ private function checkIfCanCopy(PackageFile $file, Package $package, Package $pa
219218
*/
220219
private function checkFileSkip($filePath, array $options)
221220
{
222-
if ($filePath != '.') {
221+
if ($filePath !== '.') {
223222
$ext = strtolower(pathinfo($filePath, PATHINFO_EXTENSION));
224223
$basename = pathinfo($filePath, PATHINFO_BASENAME);
225-
if ($ext == 'less' && strpos($basename, '_') === 0) {
224+
if ($ext === 'less' && strpos($basename, '_') === 0) {
226225
return true;
227226
}
228227
$option = isset(InputValidator::$fileExtensionOptionMap[$ext])

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,12 @@ public function updateTranslationFileContent($content)
129129
public function getTranslationFileVersion()
130130
{
131131
$translationFile = $this->getTranslationFileFullPath();
132-
if (!$this->driverFile->isExists($translationFile)) {
133-
$this->updateTranslationFileContent($this->translationFile->getTranslationFileContent());
132+
$translationFileHash = '';
133+
134+
if ($this->driverFile->isExists($translationFile)) {
135+
$translationFileHash = sha1_file($translationFile);
134136
}
135137

136-
$translationFileHash = sha1_file($translationFile);
137138
return sha1($translationFileHash . $this->getTranslationFilePath());
138139
}
139140
}

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,18 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Translation\Model\Json;
78

9+
use Magento\Framework\App\AreaList;
10+
use Magento\Framework\App\ObjectManager;
11+
use Magento\Framework\TranslateInterface;
12+
use Magento\Framework\View\Asset\File\FallbackContext;
13+
use Magento\Framework\View\Asset\PreProcessor\Chain;
814
use Magento\Framework\View\Asset\PreProcessorInterface;
15+
use Magento\Framework\View\DesignInterface;
916
use Magento\Translation\Model\Js\Config;
1017
use Magento\Translation\Model\Js\DataProviderInterface;
11-
use Magento\Framework\View\Asset\PreProcessor\Chain;
12-
use Magento\Framework\View\Asset\File\FallbackContext;
13-
use Magento\Framework\App\AreaList;
14-
use Magento\Framework\TranslateInterface;
1518

1619
/**
1720
* PreProcessor responsible for providing js translation dictionary
@@ -42,22 +45,30 @@ class PreProcessor implements PreProcessorInterface
4245
*/
4346
protected $translate;
4447

48+
/**
49+
* @var DesignInterface
50+
*/
51+
private $viewDesign;
52+
4553
/**
4654
* @param Config $config
4755
* @param DataProviderInterface $dataProvider
4856
* @param AreaList $areaList
4957
* @param TranslateInterface $translate
58+
* @param DesignInterface|null $viewDesign
5059
*/
5160
public function __construct(
5261
Config $config,
5362
DataProviderInterface $dataProvider,
5463
AreaList $areaList,
55-
TranslateInterface $translate
64+
TranslateInterface $translate,
65+
DesignInterface $viewDesign = null
5666
) {
5767
$this->config = $config;
5868
$this->dataProvider = $dataProvider;
5969
$this->areaList = $areaList;
6070
$this->translate = $translate;
71+
$this->viewDesign = $viewDesign ?? ObjectManager::getInstance()->get(DesignInterface::class);
6172
}
6273

6374
/**
@@ -77,6 +88,8 @@ public function process(Chain $chain)
7788
if ($context instanceof FallbackContext) {
7889
$themePath = $context->getThemePath();
7990
$areaCode = $context->getAreaCode();
91+
92+
$this->viewDesign->setDesignTheme($themePath, $areaCode);
8093
}
8194

8295
$area = $this->areaList->getArea($areaCode);

app/code/Magento/Translation/Test/Unit/Model/Json/PreProcessorTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,24 @@ class PreProcessorTest extends \PHPUnit\Framework\TestCase
3636
*/
3737
protected $translateMock;
3838

39+
/**
40+
* @var \Magento\Framework\View\DesignInterface|\PHPUnit_Framework_MockObject_MockObject
41+
*/
42+
private $designMock;
43+
3944
protected function setUp()
4045
{
4146
$this->configMock = $this->createMock(\Magento\Translation\Model\Js\Config::class);
4247
$this->dataProviderMock = $this->createMock(\Magento\Translation\Model\Js\DataProvider::class);
4348
$this->areaListMock = $this->createMock(\Magento\Framework\App\AreaList::class);
4449
$this->translateMock = $this->getMockForAbstractClass(\Magento\Framework\TranslateInterface::class);
50+
$this->designMock = $this->getMockForAbstractClass(\Magento\Framework\View\DesignInterface::class);
4551
$this->model = new PreProcessor(
4652
$this->configMock,
4753
$this->dataProviderMock,
4854
$this->areaListMock,
49-
$this->translateMock
55+
$this->translateMock,
56+
$this->designMock
5057
);
5158
}
5259

@@ -84,6 +91,8 @@ public function testGetData()
8491
->method('getLocale')
8592
->willReturn('en_US');
8693

94+
$this->designMock->expects($this->once())->method('setDesignTheme')->with($themePath, $areaCode);
95+
8796
$this->areaListMock->expects($this->once())
8897
->method('getArea')
8998
->with($areaCode)

app/code/Magento/Translation/view/base/templates/translate.phtml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
<?php $version = $block->getTranslationFileVersion(); ?>
3030

31-
if (versionObj.version !== '<?php $block->escapeJsQuote($version) ?>') {
31+
if (versionObj.version !== '<?= $block->escapeJsQuote($version) ?>') {
3232
dependencies.push(
3333
'text!<?= /* @noEscape */ Magento\Translation\Model\Js\Config::DICTIONARY_FILE_NAME ?>'
3434
);
@@ -44,7 +44,7 @@
4444
$.localStorage.set(
4545
'mage-translation-file-version',
4646
{
47-
version: '<?php $block->escapeJsQuote($version) ?>'
47+
version: '<?= $block->escapeJsQuote($version) ?>'
4848
}
4949
);
5050
} else {

dev/tests/integration/testsuite/Magento/Framework/TranslateTest.php

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Framework;
78

89
use Magento\TestFramework\Helper\Bootstrap;
910
use Magento\TestFramework\Helper\CacheCleaner;
11+
use PHPUnit_Framework_MockObject_MockObject as MockObject;
1012

1113
/**
1214
* @magentoAppIsolation enabled
@@ -15,28 +17,33 @@
1517
*/
1618
class TranslateTest extends \PHPUnit\Framework\TestCase
1719
{
18-
/** @var \Magento\Framework\Translate */
20+
/**
21+
* @var \Magento\Framework\Translate
22+
*/
1923
private $translate;
2024

25+
/**
26+
* @inheritdoc
27+
*/
2128
protected function setUp()
2229
{
23-
/** @var \Magento\Framework\View\FileSystem $viewFileSystem */
30+
/** @var \Magento\Framework\View\FileSystem|MockObject $viewFileSystem */
2431
$viewFileSystem = $this->createPartialMock(
2532
\Magento\Framework\View\FileSystem::class,
26-
['getLocaleFileName', 'getDesignTheme']
33+
['getLocaleFileName']
2734
);
2835

2936
$viewFileSystem->expects($this->any())
3037
->method('getLocaleFileName')
3138
->will(
32-
$this->returnValue(dirname(__DIR__) . '/Theme/Model/_files/design/frontend/Test/default/i18n/en_US.csv')
39+
$this->returnValue(
40+
dirname(__DIR__) . '/Translation/Model/_files/Magento/design/Magento/theme/i18n/en_US.csv'
41+
)
3342
);
3443

35-
/** @var \Magento\Framework\View\Design\ThemeInterface $theme */
44+
/** @var \Magento\Framework\View\Design\ThemeInterface|MockObject $theme */
3645
$theme = $this->createMock(\Magento\Framework\View\Design\ThemeInterface::class);
37-
$theme->expects($this->any())->method('getId')->will($this->returnValue(10));
38-
39-
$viewFileSystem->expects($this->any())->method('getDesignTheme')->will($this->returnValue($theme));
46+
$theme->expects($this->any())->method('getThemePath')->will($this->returnValue('Magento/luma'));
4047

4148
/** @var \Magento\TestFramework\ObjectManager $objectManager */
4249
$objectManager = Bootstrap::getObjectManager();
@@ -55,7 +62,7 @@ protected function setUp()
5562
dirname(__DIR__) . '/Translation/Model/_files/Magento/Catalog/i18n'
5663
);
5764

58-
/** @var \Magento\Theme\Model\View\Design $designModel */
65+
/** @var \Magento\Theme\Model\View\Design|MockObject $designModel */
5966
$designModel = $this->getMockBuilder(\Magento\Theme\Model\View\Design::class)
6067
->setMethods(['getDesignTheme'])
6168
->setConstructorArgs(
@@ -71,7 +78,7 @@ protected function setUp()
7178
)
7279
->getMock();
7380

74-
$designModel->expects($this->any())->method('getDesignTheme')->will($this->returnValue($theme));
81+
$designModel->expects($this->any())->method('getDesignTheme')->willReturnValue($theme);
7582

7683
$objectManager->addSharedInstance($designModel, \Magento\Theme\Model\View\Design\Proxy::class);
7784

@@ -96,6 +103,11 @@ public function testLoadData()
96103
/**
97104
* @magentoCache all disabled
98105
* @dataProvider translateDataProvider
106+
*
107+
* @param string $inputText
108+
* @param string $expectedTranslation
109+
* @return void
110+
* @throws Exception\LocalizedException
99111
*/
100112
public function testTranslate($inputText, $expectedTranslation)
101113
{
@@ -111,9 +123,26 @@ public function translateDataProvider()
111123
{
112124
return [
113125
['', ''],
114-
['Text with different translation on different modules', 'Text translation that was last loaded'],
115-
['text_with_no_translation', 'text_with_no_translation'],
116-
['Design value to translate', 'Design translated value']
126+
[
127+
'Theme phrase will be translated',
128+
'Theme phrase is translated',
129+
],
130+
[
131+
'Phrase in Magento_Store module that doesn\'t need translation',
132+
'Phrase in Magento_Store module that doesn\'t need translation',
133+
],
134+
[
135+
'Phrase in Magento_Catalog module that doesn\'t need translation',
136+
'Phrase in Magento_Catalog module that doesn\'t need translation',
137+
],
138+
[
139+
'Magento_Store module phrase will be override by theme translation',
140+
'Magento_Store module phrase is override by theme translation',
141+
],
142+
[
143+
'Magento_Catalog module phrase will be override by theme translation',
144+
'Magento_Catalog module phrase is override by theme translation',
145+
],
117146
];
118147
}
119148
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"Theme phrase will be translated","Theme phrase is translated"
2+
"Magento_Catalog module phrase will be override by theme translation","Magento_Catalog module phrase is override by theme translation"
3+
"Magento_Store module phrase will be override by theme translation","Magento_Store module phrase is override by theme translation"

0 commit comments

Comments
 (0)