@@ -16,10 +16,10 @@ class ExportToCsvCommand extends Command
1616 * @var string
1717 */
1818 protected $ signature = 'lang:export
19- {--l|locale= : The locales to be exported. Separated by comma (default - default lang of application ).}
19+ {--l|locale= : The locales to be exported. Separated by comma (default - base locale from config ).}
2020 {--t|target= : Target languages, only missing keys are exported. Separated by comma.}
21- {--g|group= : The name of translation file to export (default all groups ).}
22- {--o|output= : Filename of exported translation, :locale, :target is replaced (optional, default - storage/:locale:target.csv ).}
21+ {--g|group= : The name of translation file to export (default - base group from config ).}
22+ {--o|output= : Filename of exported translation, :locale, :target is replaced (default - export_path from config ).}
2323 {--z|zip= : Zip all files.}
2424 {--X|excel : Set file encoding for Excel (optional, default - UTF-8).}
2525 {--D|delimiter=, : Field delimiter (optional, default - ",").}
@@ -30,14 +30,7 @@ class ExportToCsvCommand extends Command
3030 *
3131 * @var string
3232 */
33- protected $ description = "Exports the language files to CSV file " ;
34-
35- /**
36- * Parameters provided to command.
37- *
38- * @var array
39- */
40- protected $ parameters = [];
33+ protected $ description = "Exports language files to CSV file " ;
4134
4235 /**
4336 * List of files created by the export
@@ -53,16 +46,14 @@ class ExportToCsvCommand extends Command
5346 */
5447 public function handle ()
5548 {
56- $ this ->getParameters ();
57-
58- foreach ($ this ->strToArray ($ this ->parameters ['locale ' ]) as $ locale ) {
59- foreach ($ this ->strToArray ($ this ->parameters ['target ' ], [null ]) as $ target ) {
49+ foreach ($ this ->strToArray ($ this ->option ('locale ' )) as $ locale ) {
50+ foreach ($ this ->strToArray ($ this ->option ('target ' ), [null ]) as $ target ) {
6051 $ translations = $ this ->getTranslations ($ locale , $ target );
6152 $ this ->saveTranslations ($ locale , $ target , $ translations );
6253 $ this ->info (strtoupper ($ locale ) . strtoupper ($ target ?: '' ) . ' Translations saved to: ' . $ this ->getOutputFileName ($ locale , $ target ));
6354 }
6455 }
65- if ($ zipName = $ this ->parameters [ 'zip ' ] ) {
56+ if ($ zipName = $ this ->option ( 'zip ' ) ) {
6657 $ this ->info ('Creating archive... ' );
6758 $ zip = new \ZipArchive ;
6859 if (!$ zip ->open ($ zipName , \ZipArchive::CREATE )) {
@@ -87,29 +78,6 @@ private function strToArray($string, $fallback = [])
8778 return array_filter (array_map ('trim ' , explode (', ' , $ string )));
8879 }
8980
90- /**
91- * Fetch command parameters (arguments and options) and analyze them.
92- *
93- * @return void
94- */
95- private function getParameters ()
96- {
97- $ parameters = [
98- 'locale ' => $ this ->option ('locale ' ),
99- 'group ' => $ this ->option ('group ' ),
100- 'output ' => $ this ->option ('output ' ),
101- 'excel ' => $ this ->option ('excel ' ),
102- 'delimiter ' => $ this ->option ('delimiter ' ),
103- 'enclosure ' => $ this ->option ('enclosure ' ),
104- 'target ' => $ this ->option ('target ' ),
105- 'zip ' => $ this ->option ('zip ' ),
106- ];
107- $ parameters = array_filter ($ parameters , function ($ var ) {
108- return !is_null ($ var );
109- });
110- $ this ->parameters = array_merge (config ('lang_import_export.export ' , []), $ parameters );
111- }
112-
11381 /**
11482 * Get translations from localization files.
11583 *
@@ -119,9 +87,10 @@ private function getParameters()
11987 */
12088 private function getTranslations ($ locale , $ target = null )
12189 {
122- $ from = LangListService::loadLangList ($ locale , $ this ->parameters ['group ' ]);
90+ $ group = $ this ->option ('group ' ) ?: config ('lang_import_export.base_group ' );
91+ $ from = LangListService::loadLangList ($ locale , $ group );
12392 if ($ target ) {
124- $ targetList = LangListService::loadLangList ($ target , $ this -> parameters [ ' group ' ] );
93+ $ targetList = LangListService::loadLangList ($ target , $ group );
12594 foreach ($ targetList as $ group => $ translations ) {
12695 foreach ($ translations as $ key => $ v ) {
12796 unset($ from [$ group ][$ key ]);
@@ -203,7 +172,7 @@ private function writeFile()
203172 {
204173 $ data = func_get_args ();
205174 $ output = array_shift ($ data );
206- fputcsv ($ output , $ data , $ this ->parameters [ 'delimiter ' ] , $ this ->parameters [ 'enclosure ' ] );
175+ fputcsv ($ output , $ data , $ this ->option ( 'delimiter ' ) , $ this ->option ( 'enclosure ' ) );
207176 }
208177
209178 /**
@@ -216,7 +185,7 @@ private function closeFile($output)
216185 {
217186 fclose ($ output );
218187
219- if ($ this ->parameters [ 'excel ' ] ) {
188+ if ($ this ->option ( 'excel ' ) ) {
220189 $ this ->adjustToExcel ();
221190 }
222191 }
@@ -229,8 +198,8 @@ private function closeFile($output)
229198 */
230199 private function adjustToExcel ()
231200 {
232- $ data = file_get_contents ($ this ->parameters [ 'output ' ] );
233- file_put_contents ($ this ->parameters [ 'output ' ] ,
201+ $ data = file_get_contents ($ this ->option ( 'output ' ) );
202+ file_put_contents ($ this ->option ( 'output ' ) ,
234203 chr (255 ) . chr (254 ) . mb_convert_encoding ($ data , 'UTF-16LE ' , 'UTF-8 ' ));
235204 }
236205
@@ -241,7 +210,7 @@ private function adjustToExcel()
241210 */
242211 private function getOutputFileName ($ locale , $ target = null )
243212 {
244- $ fileName = $ this ->parameters [ 'output ' ] ;
213+ $ fileName = $ this ->option ( 'output ' ) ;
245214 $ fileName = str_replace (':locale ' , $ locale , $ fileName );
246215 $ fileName = str_replace (':target ' , $ target , $ fileName );
247216 return $ fileName ;
0 commit comments