Skip to content

Commit bcc242c

Browse files
committed
refactor
1 parent 331cb76 commit bcc242c

File tree

10 files changed

+72
-150
lines changed

10 files changed

+72
-150
lines changed

LICENSE

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ The MIT License (MIT)
22

33
Copyright (c) 2014 UFirst Group
44
Copyright (c) 2017 HighSolutions
5+
Copyright (c) 2019 Aidas Klimas
56

67
Permission is hereby granted, free of charge, to any person obtaining a copy
78
of this software and associated documentation files (the "Software"), to deal
@@ -19,4 +20,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1920
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2021
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2122
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22-
SOFTWARE.
23+
SOFTWARE.

README.md

Lines changed: 9 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
![Laravel-Lang-Import-Export by HighSolutions](https://raw.githubusercontent.com/highsolutions/laravel-lang-import-export/master/intro.jpg)
1+
![Laravel-Lang-Import-Export v6](https://raw.githubusercontent.com/AidasK/laravel-lang-import-export/master/logo.png)
22

33
Laravel-Lang-Import-Export
44
==========================
@@ -45,7 +45,7 @@ Add the following line to the `require` section of your Laravel webapp's `compos
4545

4646
```javascript
4747
"require": {
48-
"HighSolutions/laravel-lang-import-export": "5.4.*"
48+
"AidasK/laravel-lang-import-export": "6.0.*"
4949
}
5050
```
5151

@@ -57,7 +57,7 @@ For previous versions of Laravel, you need to update `config/app.php` by adding
5757
```php
5858
'providers' => array(
5959
/* ... */
60-
'HighSolutions\LangImportExport\LangImportExportServiceProvider'
60+
'AidasK\LangImportExportServiceProvider'
6161
)
6262
```
6363

@@ -69,47 +69,22 @@ The package currently provides two commands, one for exporting the files and one
6969
### Export
7070

7171
```bash
72-
php artisan lang:export
73-
php artisan lang:export en * path/to/export
74-
php artisan lang:export en auth -A -X
72+
php artisan lang:export --locale en
73+
php artisan lang:export --locale en --target fr # export en translations only missing in fr locale
7574
```
7675

77-
When you call command without parameters, export file will be generated for all localization files within default locale. But you can define **locale** explicitly. You can also export only one file (second parameter - **group**) and define where to store file (you can provide name with and without .csv extension). When you use **output** argument, default path is base_path() -> catalog of your whole project.
78-
But there is few more useful parameters:
79-
80-
| name of parameter | description | is required? | default value |
81-
|-------------------|-----------------------------------------|--------------|------------------------------------|
82-
| locale | The locale to be exported. Multiple separated by comma | NO | default lang of application |
83-
| group | The name of translation file to export | NO | \* - all files |
84-
| output | Filename of exported translation files | NO | storage/app/lang-import-export.csv |
85-
| -A / --append | Append name of group to the name of file | NO | empty |
86-
| -X / --excel | Set file encoding (UTF-16) for Excel | NO | UTF-8 |
87-
| -D / --delimiter | Field delimiter | NO | , |
88-
| -E / --enclosure | Field enclosure | NO | " |
89-
| -T / --target-locale | Only missing keys for for this locale are exported | NO | " |
9076
### Import
9177

9278
```
9379
php artisan lang:import
94-
php artisan lang:import en * path/to/import
95-
php artisan lang:import en auth -X
9680
```
9781

98-
When you call command without parameters - it will try to read default file of export command without parameters for default locale and all localization files. You can of course specify all parameters (**locale**, **group**, **input**) and there is few more options:
99-
100-
| name of parameter | description | is required? | default value |
101-
|-------------------|----------------------------------------------|--------------|------------------------------------|
102-
| locale | The locale to be imported | NO | default lang of application |
103-
| group | The name of translation file to import | NO | * - all files |
104-
| output | Filename of translation files to be imported | NO | storage/app/lang-import-export.csv |
105-
| -X / --excel | Set file encoding from Excel | NO | UTF-8 |
106-
| -D / --delimiter | Field delimiter | NO | , |
107-
| -E / --enclosure | Field enclosure | NO | " |
108-
| -C / --escape | Field escape | NO | \ |
109-
11082
Changelog
11183
------------
11284

85+
6.0.0
86+
* refactor whole repository
87+
11388
5.4.10
11489
* Laravel 5.7 support
11590

@@ -142,17 +117,10 @@ Changelog
142117
- add support for export and import all localization files
143118
- any arguments are not required
144119

145-
Roadmap
146-
------------
147-
148-
* Removing tabs from text
149-
* Option for deleting export file after importing.
150-
* Option for excluding certain files (and system ones).
151-
* Unit tests!
152120

153121
Credits
154122
------------
155123

156124
This package was originally created by [UFirst](http://github.com/ufirstgroup) and is available here: [Laravel-lang-import-export](https://github.com/ufirstgroup/laravel-lang-import-export).
157125

158-
Currently is developed by [HighSolutions](https://highsolutions.org), software house from Poland in love in Laravel.
126+
Currently is developed by [Aidas Klimas](https://klimas.lt/), software house from Lithuania

composer.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
{
2-
"name": "highsolutions/laravel-lang-import-export",
2+
"name": "AidasK/laravel-lang-import-export",
33
"description": "A Laravel package providing artisan commands to import and export language files from and to CSV.",
44
"keywords": ["laravel", "localization", "translation", "messages", "import", "export", "CSV"],
55
"authors": [
6+
{
7+
"name": "Aidas Klimas",
8+
"email": "[email protected]"
9+
},
610
{
711
"name": "Michael Ruoss",
812
"email": "[email protected]"
@@ -19,7 +23,7 @@
1923
},
2024
"autoload": {
2125
"psr-4": {
22-
"HighSolutions\\LangImportExport\\": "src/"
26+
"LangImportExport\\": "src/"
2327
},
2428
"files": [
2529
"src/Support/helpers.php"
@@ -30,8 +34,8 @@
3034
"frameworks": ["Laravel 5.7"],
3135
"laravel": {
3236
"providers": [
33-
"HighSolutions\\LangImportExport\\LangImportExportServiceProvider"
34-
]
37+
"LangImportExport\\LangImportExportServiceProvider"
38+
]
3539
}
3640
},
3741
"minimum-stability": "stable"

logo.png

25.6 KB
Loading

src/Console/ExportToCsvCommand.php

Lines changed: 25 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22

3-
namespace HighSolutions\LangImportExport\Console;
3+
namespace LangImportExport\Console;
44

55
use Illuminate\Console\Command;
66
use Symfony\Component\Console\Input\InputOption;
77
use Symfony\Component\Console\Input\InputArgument;
8-
use HighSolutions\LangImportExport\Facades\LangListService;
8+
use LangImportExport\Facades\LangListService;
99

1010
class ExportToCsvCommand extends Command
1111
{
@@ -16,14 +16,13 @@ class ExportToCsvCommand extends Command
1616
* @var string
1717
*/
1818
protected $signature = 'lang:export
19-
{locale? : The locales to be exported. Separated by comma (default - default lang of application).}
20-
{group? : The name of translation file to export (default - all files).}
21-
{output? : Filename of exported translation, :locale, :target is replaced (optional, default - :locale:target-export.csv).}
22-
{--A|append : Append name of group to the name of file (optional, default - empty).}
23-
{--X|excel : Set file encoding for Excel (optional, default - UTF-8).}
19+
{--l|locale? : The locales to be exported. Separated by comma (default - default lang of application).}
20+
{--t|target: Target languages, only missing keys are exported. Separated by comma.}
21+
{--g|group: The name of translation file to export (default, groups in config).}
22+
{--o|output: Filename of exported translation, :locale, :target is replaced (optional, default - storage/:locale:target.csv).}
23+
{--X|excel: Set file encoding for Excel (optional, default - UTF-8).}
2424
{--D|delimiter=, : Field delimiter (optional, default - ",").}
25-
{--E|enclosure=" : Field enclosure (optional, default - \'"\').}
26-
{--T|target-locale=" : Target languages, only missing keys are exported. Separated by comma (optional).} ';
25+
{--E|enclosure=" : Field enclosure (optional, default - \'"\').} ';
2726

2827
/**
2928
* The console command description.
@@ -39,31 +38,13 @@ class ExportToCsvCommand extends Command
3938
*/
4039
protected $parameters = [];
4140

42-
/**
43-
* Default path for file save.
44-
*
45-
* @var string
46-
*/
47-
protected $defaultPath;
48-
4941
/**
5042
* File extension (default .csv).
5143
*
5244
* @var string
5345
*/
5446
protected $ext = '.csv';
5547

56-
/**
57-
* Class constructor.
58-
*
59-
* @return void
60-
*/
61-
public function __construct()
62-
{
63-
parent::__construct();
64-
$this->defaultPath = base_path(':locale:target-export') . $this->ext;
65-
}
66-
6748
/**
6849
* Execute the console command.
6950
*
@@ -73,10 +54,10 @@ public function handle()
7354
{
7455
$this->getParameters();
7556

76-
$this->sayItsBeginning();
57+
$this->info('Translations export started.');
7758

7859
foreach ($this->strToArray($this->parameters['locale']) as $locale) {
79-
foreach ($this->strToArray($this->parameters['target_locale'], [null]) as $target) {
60+
foreach ($this->strToArray($this->parameters['target'], [null]) as $target) {
8061
$translations = $this->getTranslations($locale, $target);
8162
$this->saveTranslations($locale, $target, $translations);
8263
$this->info(strtoupper($locale) . strtoupper($target ?: '') . ' Translations saved to: ' . $this->getOutputFileName($locale, $target));
@@ -99,44 +80,25 @@ private function strToArray($string, $fallback = [])
9980
*/
10081
private function getParameters()
10182
{
102-
$this->parameters = [
103-
'group' => $this->argument('group'),
104-
'locale' => $this->argument('locale') === null ? config('app.locale') : $this->argument('locale'),
105-
'output' => $this->argument('output') === null ? $this->defaultPath : base_path($this->argument('output')),
106-
'append' => $this->option('append') !== false,
107-
'excel' => $this->option('excel') !== false,
83+
$parameters = [
84+
'locale' => $this->option('locale'),
85+
'group' => $this->option('group'),
86+
'output' => $this->option('output'),
87+
'append' => $this->option('append'),
88+
'excel' => $this->option('excel'),
10889
'delimiter' => $this->option('delimiter'),
10990
'enclosure' => $this->option('enclosure'),
110-
'target_locale' => $this->option('target-locale'),
91+
'target' => $this->option('target'),
11192
];
112-
113-
$this->setDefaultPath();
114-
}
115-
116-
/**
117-
* Set possible file names.
118-
*
119-
* @return void
120-
*/
121-
private function setDefaultPath()
122-
{
93+
$parameters = array_filter($parameters, function ($var) {
94+
return !is_null($var);
95+
});
96+
$this->parameters = array_merge(config('lang_import_export.export'), $parameters);
12397
if ($this->parameters['append']) {
12498
$this->parameters['output'] .= '-' . $this->parameters['group'];
125-
$this->defaultPath .= '-' . $this->parameters['group'];
12699
}
127100
}
128101

129-
/**
130-
* Display output that command has started and which groups are being exported.
131-
*
132-
* @return void
133-
*/
134-
private function sayItsBeginning()
135-
{
136-
$this->info(PHP_EOL
137-
. 'Translations export of ' . ($this->parameters['group'] === null ? 'all groups' : $this->parameters['group'] . ' group') . ' - started.');
138-
}
139-
140102
/**
141103
* Get translations from localization files.
142104
*
@@ -180,7 +142,8 @@ private function saveTranslations($locale, $target, $translations)
180142
*
181143
* @param $locale
182144
* @param $target
183-
* @return FilePointerResource
145+
* @throws \Exception
146+
* @return resource
184147
*/
185148
private function openFile($locale, $target)
186149
{
@@ -190,7 +153,7 @@ private function openFile($locale, $target)
190153
}
191154

192155
if (!($output = fopen($fileName, 'w'))) {
193-
$output = fopen($this->defaultPath . $this->ext, 'w');
156+
throw new \Exception("$fileName failed to open");
194157
}
195158

196159
fputs($output, "\xEF\xBB\xBF");
@@ -201,7 +164,7 @@ private function openFile($locale, $target)
201164
/**
202165
* Save content of translation files to specified file.
203166
*
204-
* @param FilePointerResource $output
167+
* @param resource $output
205168
* @param array $translations
206169
* @return void
207170
*/

src/Console/ImportFromCsvCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
<?php
22

3-
namespace HighSolutions\LangImportExport\Console;
3+
namespace LangImportExport\Console;
44

55
use Illuminate\Console\Command;
66
use Symfony\Component\Console\Input\InputOption;
77
use Symfony\Component\Console\Input\InputArgument;
8-
use HighSolutions\LangImportExport\Facades\LangListService;
8+
use LangImportExport\Facades\LangListService;
99

1010
class ImportFromCsvCommand extends Command
1111
{

src/Facades/LangListService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace HighSolutions\LangImportExport\Facades;
3+
namespace LangImportExport\Facades;
44

55
use Illuminate\Support\Facades\Facade;
66

0 commit comments

Comments
 (0)