3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
+ declare (strict_types=1 );
7
+
6
8
namespace Magento \Translation \Model ;
7
9
8
10
use Magento \Framework \App \Filesystem \DirectoryList ;
9
- use Magento \Framework \App \ ObjectManager ;
10
- use Magento \Translation \ Model \ Inline \ File as TranslationFile ;
11
+ use Magento \Framework \Filesystem \ Driver \ File ;
12
+ use Magento \Framework \ View \ Asset \ Repository ;
11
13
12
14
/**
13
15
* A service for handling Translation config files
@@ -20,41 +22,33 @@ class FileManager
20
22
const TRANSLATION_CONFIG_FILE_NAME = 'Magento_Translation/js/i18n-config.js ' ;
21
23
22
24
/**
23
- * @var \Magento\Framework\View\Asset\ Repository
25
+ * @var Repository
24
26
*/
25
27
private $ assetRepo ;
26
28
27
29
/**
28
- * @var \Magento\Framework\App\Filesystem\ DirectoryList
30
+ * @var DirectoryList
29
31
*/
30
32
private $ directoryList ;
31
33
32
34
/**
33
- * @var \Magento\Framework\Filesystem\Driver\ File
35
+ * @var File
34
36
*/
35
37
private $ driverFile ;
36
38
37
39
/**
38
- * @var TranslationFile
39
- */
40
- private $ translationFile ;
41
-
42
- /**
43
- * @param \Magento\Framework\View\Asset\Repository $assetRepo
44
- * @param \Magento\Framework\App\Filesystem\DirectoryList $directoryList
45
- * @param \Magento\Framework\Filesystem\Driver\File $driverFile
46
- * @param TranslationFile $translationFile
40
+ * @param Repository $assetRepo
41
+ * @param DirectoryList $directoryList
42
+ * @param File $driverFile
47
43
*/
48
44
public function __construct (
49
- \Magento \Framework \View \Asset \Repository $ assetRepo ,
50
- \Magento \Framework \App \Filesystem \DirectoryList $ directoryList ,
51
- \Magento \Framework \Filesystem \Driver \File $ driverFile ,
52
- \Magento \Translation \Model \Inline \File $ translationFile = null
45
+ Repository $ assetRepo ,
46
+ DirectoryList $ directoryList ,
47
+ File $ driverFile
53
48
) {
54
49
$ this ->assetRepo = $ assetRepo ;
55
50
$ this ->directoryList = $ directoryList ;
56
51
$ this ->driverFile = $ driverFile ;
57
- $ this ->translationFile = $ translationFile ?: ObjectManager::getInstance ()->get (TranslationFile::class);
58
52
}
59
53
60
54
/**
@@ -71,7 +65,7 @@ public function createTranslateConfigAsset()
71
65
}
72
66
73
67
/**
74
- * gets current js-translation.json timestamp
68
+ * Gets current js-translation.json timestamp
75
69
*
76
70
* @return string|void
77
71
*/
@@ -87,18 +81,22 @@ public function getTranslationFileTimestamp()
87
81
}
88
82
89
83
/**
84
+ * Retrieve full path for translation file
85
+ *
90
86
* @return string
91
87
*/
92
88
protected function getTranslationFileFullPath ()
93
89
{
94
90
return $ this ->directoryList ->getPath (DirectoryList::STATIC_VIEW ) .
95
- \DIRECTORY_SEPARATOR .
96
- $ this ->assetRepo ->getStaticViewFileContext ()->getPath () .
97
- \DIRECTORY_SEPARATOR .
98
- Js \Config::DICTIONARY_FILE_NAME ;
91
+ \DIRECTORY_SEPARATOR .
92
+ $ this ->assetRepo ->getStaticViewFileContext ()->getPath () .
93
+ \DIRECTORY_SEPARATOR .
94
+ Js \Config::DICTIONARY_FILE_NAME ;
99
95
}
100
96
101
97
/**
98
+ * Retrieve path for translation file
99
+ *
102
100
* @return string
103
101
*/
104
102
public function getTranslationFilePath ()
@@ -107,17 +105,22 @@ public function getTranslationFilePath()
107
105
}
108
106
109
107
/**
108
+ * Update translation file with content
109
+ *
110
110
* @param string $content
111
+ *
111
112
* @return void
112
113
*/
113
114
public function updateTranslationFileContent ($ content )
114
115
{
115
116
$ translationDir = $ this ->directoryList ->getPath (DirectoryList::STATIC_VIEW ) .
116
117
\DIRECTORY_SEPARATOR .
117
118
$ this ->assetRepo ->getStaticViewFileContext ()->getPath ();
119
+
118
120
if (!$ this ->driverFile ->isExists ($ this ->getTranslationFileFullPath ())) {
119
121
$ this ->driverFile ->createDirectory ($ translationDir );
120
122
}
123
+
121
124
$ this ->driverFile ->filePutContents ($ this ->getTranslationFileFullPath (), $ content );
122
125
}
123
126
0 commit comments