@@ -25,118 +25,118 @@ class ExportToCsvCommand extends Command
2525 {--E|enclosure=" : Field enclosure (optional, default - \'" \').}
2626 {--T|target-locale=" : Target language, only missing keys are exported (optional).} ' ;
2727
28- /**
29- * The console command description.
30- *
31- * @var string
32- */
33- protected $ description = "Exports the language files to CSV file " ;
28+ /**
29+ * The console command description.
30+ *
31+ * @var string
32+ */
33+ protected $ description = "Exports the language files to CSV file " ;
3434
35- /**
36- * Parameters provided to command.
37- *
38- * @var array
39- */
40- protected $ parameters = [];
35+ /**
36+ * Parameters provided to command.
37+ *
38+ * @var array
39+ */
40+ protected $ parameters = [];
4141
42- /**
43- * Default path for file save.
44- *
45- * @var string
46- */
47- protected $ defaultPath ;
42+ /**
43+ * Default path for file save.
44+ *
45+ * @var string
46+ */
47+ protected $ defaultPath ;
4848
49- /**
50- * File extension (default .csv).
51- *
52- * @var string
53- */
54- protected $ ext = '.csv ' ;
49+ /**
50+ * File extension (default .csv).
51+ *
52+ * @var string
53+ */
54+ protected $ ext = '.csv ' ;
5555
56- /**
57- * Class constructor.
58- *
59- * @return void
60- */
61- public function __construct ()
62- {
63- parent ::__construct ();
64- $ this ->defaultPath = base_path (':locale-export ' ) . $ this ->ext ;
65- }
56+ /**
57+ * Class constructor.
58+ *
59+ * @return void
60+ */
61+ public function __construct ()
62+ {
63+ parent ::__construct ();
64+ $ this ->defaultPath = base_path (':locale-export ' ) . $ this ->ext ;
65+ }
6666
67- /**
68- * Execute the console command.
69- *
70- * @return void
71- */
72- public function handle ()
73- {
74- $ this ->getParameters ();
67+ /**
68+ * Execute the console command.
69+ *
70+ * @return void
71+ */
72+ public function handle ()
73+ {
74+ $ this ->getParameters ();
7575
76- $ this ->sayItsBeginning ();
76+ $ this ->sayItsBeginning ();
7777
78- foreach (explode (', ' , $ this ->parameters ['locale ' ]) as $ locale ) {
78+ foreach (explode (', ' , $ this ->parameters ['locale ' ]) as $ locale ) {
7979 $ translations = $ this ->getTranslations ($ locale );
8080 $ this ->saveTranslations ($ locale , $ translations );
8181 $ this ->info (strtoupper ($ locale ) . ' Translations saved to: ' . $ this ->getOutputFileName ($ locale ));
8282 }
83- }
83+ }
8484
85- /**
86- * Fetch command parameters (arguments and options) and analyze them.
87- *
88- * @return void
89- */
90- private function getParameters ()
91- {
92- $ this ->parameters = [
93- 'group ' => $ this ->argument ('group ' ),
94- 'locale ' => $ this ->argument ('locale ' ) === null ? config ('app.locale ' ) : $ this ->argument ('locale ' ),
95- 'output ' => $ this ->argument ('output ' ) === null ? $ this ->defaultPath : base_path ($ this ->argument ('output ' )),
96- 'append ' => $ this ->option ('append ' ) !== false ,
97- 'excel ' => $ this ->option ('excel ' ) !== false ,
98- 'delimiter ' => $ this ->option ('delimiter ' ),
99- 'enclosure ' => $ this ->option ('enclosure ' ),
100- 'target_locale ' => $ this ->option ('target-locale ' ),
101- ];
85+ /**
86+ * Fetch command parameters (arguments and options) and analyze them.
87+ *
88+ * @return void
89+ */
90+ private function getParameters ()
91+ {
92+ $ this ->parameters = [
93+ 'group ' => $ this ->argument ('group ' ),
94+ 'locale ' => $ this ->argument ('locale ' ) === null ? config ('app.locale ' ) : $ this ->argument ('locale ' ),
95+ 'output ' => $ this ->argument ('output ' ) === null ? $ this ->defaultPath : base_path ($ this ->argument ('output ' )),
96+ 'append ' => $ this ->option ('append ' ) !== false ,
97+ 'excel ' => $ this ->option ('excel ' ) !== false ,
98+ 'delimiter ' => $ this ->option ('delimiter ' ),
99+ 'enclosure ' => $ this ->option ('enclosure ' ),
100+ 'target_locale ' => $ this ->option ('target-locale ' ),
101+ ];
102102
103- $ this ->setDefaultPath ();
104- }
103+ $ this ->setDefaultPath ();
104+ }
105105
106- /**
107- * Set possible file names.
108- *
109- * @return void
110- */
111- private function setDefaultPath ()
112- {
113- if ($ this ->parameters ['append ' ]) {
114- $ this ->parameters ['output ' ] .= '- ' . $ this ->parameters ['group ' ];
115- $ this ->defaultPath .= '- ' . $ this ->parameters ['group ' ];
116- }
117- }
106+ /**
107+ * Set possible file names.
108+ *
109+ * @return void
110+ */
111+ private function setDefaultPath ()
112+ {
113+ if ($ this ->parameters ['append ' ]) {
114+ $ this ->parameters ['output ' ] .= '- ' . $ this ->parameters ['group ' ];
115+ $ this ->defaultPath .= '- ' . $ this ->parameters ['group ' ];
116+ }
117+ }
118118
119- /**
120- * Display output that command has started and which groups are being exported.
121- *
122- * @return void
123- */
124- private function sayItsBeginning ()
125- {
126- $ this ->info (PHP_EOL
127- . 'Translations export of ' . ($ this ->parameters ['group ' ] === null ? 'all groups ' : $ this ->parameters ['group ' ] .' group ' ) .' - started. ' );
128- }
119+ /**
120+ * Display output that command has started and which groups are being exported.
121+ *
122+ * @return void
123+ */
124+ private function sayItsBeginning ()
125+ {
126+ $ this ->info (PHP_EOL
127+ . 'Translations export of ' . ($ this ->parameters ['group ' ] === null ? 'all groups ' : $ this ->parameters ['group ' ] . ' group ' ) . ' - started. ' );
128+ }
129129
130130 /**
131131 * Get translations from localization files.
132132 *
133133 * @param $locale
134134 * @return array
135135 */
136- private function getTranslations ($ locale )
137- {
138- $ from = LangListService::loadLangList ($ locale , $ this ->parameters ['group ' ]);
139- if ($ this ->parameters ['target_locale ' ]) {
136+ private function getTranslations ($ locale )
137+ {
138+ $ from = LangListService::loadLangList ($ locale , $ this ->parameters ['group ' ]);
139+ if ($ this ->parameters ['target_locale ' ]) {
140140 $ target = LangListService::loadLangList ($ this ->parameters ['target_locale ' ], $ this ->parameters ['group ' ]);
141141 foreach ($ target as $ group => $ translations ) {
142142 foreach ($ translations as $ key => $ v ) {
@@ -154,96 +154,99 @@ private function getTranslations($locale)
154154 * @param $translations
155155 * @return void
156156 */
157- private function saveTranslations ($ locale , $ translations )
158- {
159- $ output = $ this ->openFile ($ locale );
157+ private function saveTranslations ($ locale , $ translations )
158+ {
159+ $ output = $ this ->openFile ($ locale );
160160
161- $ this ->saveTranslationsToFile ($ output , $ translations );
161+ $ this ->saveTranslationsToFile ($ output , $ translations );
162162
163- $ this ->closeFile ($ output );
164- }
163+ $ this ->closeFile ($ output );
164+ }
165165
166- /**
167- * Open specified file (if not possible, open default one).
168- *
169- * @return FilePointerResource
170- */
171- private function openFile ($ locale )
172- {
166+ /**
167+ * Open specified file (if not possible, open default one).
168+ *
169+ * @return FilePointerResource
170+ */
171+ private function openFile ($ locale )
172+ {
173173 $ fileName = $ this ->getOutputFileName ($ locale );
174- if (substr ($ fileName , -4 ) != $ this ->ext )
175- $ fileName .= $ this ->ext ;
174+ if (substr ($ fileName , -4 ) != $ this ->ext ) {
175+ $ fileName .= $ this ->ext ;
176+ }
176177
177- if (!($ output = fopen ($ fileName , 'w ' ))) {
178- $ output = fopen ($ this ->defaultPath . $ this ->ext , 'w ' );
179- }
178+ if (!($ output = fopen ($ fileName , 'w ' ))) {
179+ $ output = fopen ($ this ->defaultPath . $ this ->ext , 'w ' );
180+ }
180181
181- fputs ($ output , "\xEF\xBB\xBF" );
182+ fputs ($ output , "\xEF\xBB\xBF" );
182183
183- return $ output ;
184- }
184+ return $ output ;
185+ }
185186
186- /**
187- * Save content of translation files to specified file.
188- *
189- * @param FilePointerResource $output
190- * @param array $translations
191- * @return void
192- */
193- private function saveTranslationsToFile ($ output , $ translations )
194- {
195- foreach ($ translations as $ group => $ files ) {
196- foreach ($ files as $ key => $ value ) {
197- if (is_array ($ value )) {
198- continue ;
199- }
200- $ this ->writeFile ($ output , $ group , $ key , $ value );
201- }
202- }
203- }
187+ /**
188+ * Save content of translation files to specified file.
189+ *
190+ * @param FilePointerResource $output
191+ * @param array $translations
192+ * @return void
193+ */
194+ private function saveTranslationsToFile ($ output , $ translations )
195+ {
196+ foreach ($ translations as $ group => $ files ) {
197+ foreach ($ files as $ key => $ value ) {
198+ if (is_array ($ value )) {
199+ continue ;
200+ }
201+ $ this ->writeFile ($ output , $ group , $ key , $ value );
202+ }
203+ }
204+ }
204205
205- /**
206- * Put content of file to specified file with CSV parameters.
207- *
208- * @param FilePointerResource $output
209- * @param string $group
210- * @param string $key
211- * @param string $value
212- * @return void
213- *
214- */
215- private function writeFile ()
216- {
217- $ data = func_get_args ();
218- $ output = array_shift ($ data );
219- fputcsv ($ output , $ data , $ this ->parameters ['delimiter ' ], $ this ->parameters ['enclosure ' ]);
220- }
206+ /**
207+ * Put content of file to specified file with CSV parameters.
208+ *
209+ * @param FilePointerResource $output
210+ * @param string $group
211+ * @param string $key
212+ * @param string $value
213+ * @return void
214+ *
215+ */
216+ private function writeFile ()
217+ {
218+ $ data = func_get_args ();
219+ $ output = array_shift ($ data );
220+ fputcsv ($ output , $ data , $ this ->parameters ['delimiter ' ], $ this ->parameters ['enclosure ' ]);
221+ }
221222
222- /**
223- * Close output file and check if adjust file to Excel format.
224- *
225- * @param FilePointerResource $output
226- * @return void
227- */
228- private function closeFile ($ output )
229- {
230- fclose ($ output );
223+ /**
224+ * Close output file and check if adjust file to Excel format.
225+ *
226+ * @param FilePointerResource $output
227+ * @return void
228+ */
229+ private function closeFile ($ output )
230+ {
231+ fclose ($ output );
231232
232- if ($ this ->parameters ['excel ' ])
233- $ this ->adjustToExcel ();
234- }
233+ if ($ this ->parameters ['excel ' ]) {
234+ $ this ->adjustToExcel ();
235+ }
236+ }
235237
236- /**
237- * Adjust file to Excel format.
238- *
239- * @return void
240- *
241- */
242- private function adjustToExcel ()
243- {
244- $ data = file_get_contents ($ this ->parameters ['output ' ]);
245- file_put_contents ($ this ->parameters ['output ' ], chr (255 ) . chr (254 ) . mb_convert_encoding ($ data , 'UTF-16LE ' , 'UTF-8 ' ));
246- }
238+ /**
239+ * Adjust file to Excel format.
240+ *
241+ * @return void
242+ *
243+ */
244+ private function adjustToExcel ()
245+ {
246+ $ data = file_get_contents ($ this ->parameters ['output ' ]);
247+ file_put_contents ($ this ->parameters ['output ' ],
248+ chr (255 ) . chr (254 ) . mb_convert_encoding ($ data , 'UTF-16LE ' , 'UTF-8 ' ));
249+ }
247250
248251 /**
249252 * @param $locale
0 commit comments