6
6
namespace Magento \Translation \Model ;
7
7
8
8
use Magento \Framework \App \Filesystem \DirectoryList ;
9
+ use Magento \Framework \App \ObjectManager ;
10
+ use Magento \Translation \Model \Inline \File as TranslationFile ;
9
11
10
12
/**
11
13
* A service for handling Translation config files
@@ -17,28 +19,42 @@ class FileManager
17
19
*/
18
20
const TRANSLATION_CONFIG_FILE_NAME = 'Magento_Translation/js/i18n-config.js ' ;
19
21
20
- /** @var \Magento\Framework\View\Asset\Repository */
22
+ /**
23
+ * @var \Magento\Framework\View\Asset\Repository
24
+ */
21
25
private $ assetRepo ;
22
26
23
- /** @var \Magento\Framework\App\Filesystem\DirectoryList */
27
+ /**
28
+ * @var \Magento\Framework\App\Filesystem\DirectoryList
29
+ */
24
30
private $ directoryList ;
25
31
26
- /** @var \Magento\Framework\Filesystem\Driver\File */
32
+ /**
33
+ * @var \Magento\Framework\Filesystem\Driver\File
34
+ */
27
35
private $ driverFile ;
28
36
37
+ /**
38
+ * @var TranslationFile
39
+ */
40
+ private $ translationFile ;
41
+
29
42
/**
30
43
* @param \Magento\Framework\View\Asset\Repository $assetRepo
31
- * @param \Magento\Framework\App\Filesystem\DirectoryList $directoryList,
32
- * @param \Magento\Framework\Filesystem\Driver\File $driverFile,
44
+ * @param \Magento\Framework\App\Filesystem\DirectoryList $directoryList
45
+ * @param \Magento\Framework\Filesystem\Driver\File $driverFile
46
+ * @param TranslationFile $translationFile
33
47
*/
34
48
public function __construct (
35
49
\Magento \Framework \View \Asset \Repository $ assetRepo ,
36
50
\Magento \Framework \App \Filesystem \DirectoryList $ directoryList ,
37
- \Magento \Framework \Filesystem \Driver \File $ driverFile
51
+ \Magento \Framework \Filesystem \Driver \File $ driverFile ,
52
+ \Magento \Translation \Model \Inline \File $ translationFile = null
38
53
) {
39
54
$ this ->assetRepo = $ assetRepo ;
40
55
$ this ->directoryList = $ directoryList ;
41
56
$ this ->driverFile = $ driverFile ;
57
+ $ this ->translationFile = $ translationFile ?: ObjectManager::getInstance ()->get (TranslationFile::class);
42
58
}
43
59
44
60
/**
@@ -111,12 +127,11 @@ public function updateTranslationFileContent($content)
111
127
public function getTranslationFileVersion ()
112
128
{
113
129
$ translationFile = $ this ->getTranslationFileFullPath ();
114
- $ translationFileHash = '' ;
115
-
116
- if ($ this ->driverFile ->isExists ($ translationFile )) {
117
- $ translationFileHash = sha1_file ($ translationFile );
130
+ if (!$ this ->driverFile ->isExists ($ translationFile )) {
131
+ $ this ->updateTranslationFileContent ($ this ->translationFile ->getTranslationFileContent ());
118
132
}
119
133
134
+ $ translationFileHash = sha1_file ($ translationFile );
120
135
return sha1 ($ translationFileHash . $ this ->getTranslationFilePath ());
121
136
}
122
137
}
0 commit comments