Skip to content

Commit af58748

Browse files
committed
MC-19247: Broken translations with advanced bundling
- Add strict type to js unit test; - Eliminate preference for file system driver;
1 parent f3a03dc commit af58748

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

app/code/Magento/Translation/ViewModel/Dictionary.php

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use Magento\Framework\Exception\FileSystemException;
1111
use Magento\Framework\Exception\LocalizedException;
1212
use Magento\Framework\Filesystem;
13-
use Magento\Framework\View\Asset\File\NotFoundException;
1413
use Magento\Framework\View\Asset\Repository as AssetRepository;
1514
use Magento\Framework\View\Element\Block\ArgumentInterface;
1615
use Magento\Translation\Model\Js\Config as JsConfig;
@@ -64,26 +63,20 @@ public function __construct(
6463
* Get translation dictionary file content.
6564
*
6665
* @return string
66+
* @throws FileSystemException
67+
* @throws LocalizedException
6768
*/
6869
public function getTranslationDictionary(): string
6970
{
7071
if ($this->appState->getMode() === AppState::MODE_PRODUCTION) {
71-
try {
72-
$asset = $this->assetRepo->createAsset(JsConfig::DICTIONARY_FILE_NAME);
73-
$staticViewFilePath = $this->filesystem->getDirectoryRead(
74-
DirectoryList::STATIC_VIEW
75-
)->getAbsolutePath();
76-
$content = $this->filesystemDriver->fileGetContents($staticViewFilePath . $asset->getPath());
77-
} catch (LocalizedException | FileSystemException $e) {
78-
$content = '';
79-
}
72+
$asset = $this->assetRepo->createAsset(JsConfig::DICTIONARY_FILE_NAME);
73+
$staticViewFilePath = $this->filesystem->getDirectoryRead(
74+
DirectoryList::STATIC_VIEW
75+
)->getAbsolutePath();
76+
$content = $this->filesystemDriver->fileGetContents($staticViewFilePath . $asset->getPath());
8077
} else {
81-
try {
82-
$asset = $this->assetRepo->createAsset(JsConfig::DICTIONARY_FILE_NAME);
83-
$content = $asset->getContent();
84-
} catch (LocalizedException | NotFoundException $e) {
85-
$content = '';
86-
}
78+
$asset = $this->assetRepo->createAsset(JsConfig::DICTIONARY_FILE_NAME);
79+
$content = $asset->getContent();
8780
}
8881

8982
return $content;

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515
<preference for="Magento\Framework\Phrase\RendererInterface" type="Magento\Framework\Phrase\Renderer\Composite" />
1616
<preference for="Magento\Translation\Model\Js\DataProviderInterface" type="Magento\Translation\Model\Js\DataProvider"/>
1717
<preference for="Magento\Framework\Translate\Js\Config" type="Magento\Translation\Model\Js\Config"/>
18-
<preference for="Magento\Framework\Filesystem\DriverInterface" type="Magento\Framework\Filesystem\Driver\File"/>
18+
<type name="Magento\Translation\ViewModel\Dictionary">
19+
<arguments>
20+
<argument name="filesystemDriver" xsi:type="object">Magento\Framework\Filesystem\Driver\File</argument>
21+
</arguments>
22+
</type>
1923
<type name="Magento\Framework\Translate\Inline">
2024
<arguments>
2125
<argument name="templateFileName" xsi:type="string">Magento_Translation::translate_inline.phtml</argument>

dev/tests/js/jasmine/tests/lib/mage/fake-dictionary.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,7 @@
44
*/
55
// Fake dictionary for js unit tests as real dictionary is defined is template and cannot be initialized by requirejs
66
define([], function () {
7+
'use strict';
8+
79
return {};
810
});

0 commit comments

Comments
 (0)