@@ -16,10 +16,11 @@ class ImportFromCsvCommand extends Command
1616 * @var string
1717 */
1818 protected $ signature = 'lang:import
19- {input : Filename of file to be imported with translation files.}
19+ {input : Filename of file to be imported with translation files.}
2020 {--l|locale= : The locale to be imported (default - parsed from file name).}
2121 {--g|group= : The name of translation file to imported (default - base group from config).}
2222 {--p|placeholders : Search for missing placeholders in imported keys.}
23+ {--column-map= : Map columns if other columns are used for notes (e.g. "0,1,3").}
2324 {--D|delimiter=, : Field delimiter (optional, default - ",").}
2425 {--E|enclosure=" : Field enclosure (optional, default - \'" \').}
2526 {--escape=" : Field escape (optional, default - \'" \').}
@@ -91,8 +92,9 @@ private function readFile($input)
9192
9293 $ translations = [];
9394 $ confirmed = false ;
95+ $ map = explode (', ' , $ this ->option ('column-map ' ) ?: '0,1,2 ' );
9496 while (($ data = fgetcsv (
95- $ input , 0 , $ this ->option ('delimiter ' ), $ this ->option ('enclosure ' ), $ this ->option ('escape ' ))
97+ $ input , 0 , $ this ->option ('delimiter ' ), $ this ->option ('enclosure ' ), $ this ->option ('escape ' ))
9698 ) !== false ) {
9799 if (isset ($ translations [$ data [0 ]]) == false ) {
98100 $ translations [$ data [0 ]] = [];
@@ -101,10 +103,10 @@ private function readFile($input)
101103 if ($ columns < 3 ) {
102104 throw new \Exception ("File has only $ columns column/s " );
103105 }
104- if ($ columns > 3 ) {
105- throw new \Exception (' Canceled by user ' );
106+ if ($ columns > 3 && ! $ this -> option ( ' column-map ' ) ) {
107+ throw new \Exception (" File has $ columns columns " );
106108 }
107- $ translations [$ data [0 ]][$ data [1 ]] = $ data [2 ];
109+ $ translations [$ data [$ map [ 0 ]]] [$ data [$ map [ 1 ]]] = $ data [$ map [ 2 ] ];
108110 }
109111
110112 return $ translations ;
0 commit comments