Skip to content

Laravel7 compatibility #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"license": "MIT",
"require": {
"php": ">=5.3.0",
"illuminate/support": "~5.1"
"illuminate/support": "5.5.*|5.6.*|5.7.*|5.8.*|^6.0|^7.0"
},
"autoload": {
"classmap": [
Expand Down
4 changes: 2 additions & 2 deletions src/UFirst/LangImportExport/Console/ExportToCsvCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected function getOptions()
*
* @return void
*/
public function fire()
public function handle()
{
$locale = $this->argument('locale');
$group = $this->argument('group');
Expand All @@ -73,7 +73,7 @@ public function fire()

// Write CSV lintes
foreach ($strings as $key => $value) {
fputcsv($out, array($key, $value), $delimiter, $enclosure);
fputcsv($out, array($key, is_array($value) ? implode(',', $value) : $value), $delimiter, $enclosure);
}

fclose($out);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ protected function getOptions()
*
* @return void
*/
public function fire()
public function handle()
{
$locale = $this->argument('locale');
$group = $this->argument('group');
Expand Down
45 changes: 11 additions & 34 deletions src/UFirst/LangImportExport/LangImportExportServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,18 @@
namespace UFirst\LangImportExport;

use Illuminate\Support\ServiceProvider;
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;

use UFirst\LangImportExport\Console\ExportToCsvCommand;
use UFirst\LangImportExport\Console\ImportFromCsvCommand;

use UFirst\LangImportExport\LangListService;
class LangImportExportServiceProvider extends ServiceProvider {

/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = true;

/**
* Bootstrap the application events.
*
* @return void
*/
public function boot(DispatcherContract $events)
{
parent::boot($events);
$this->registerExportToCsvCommand();
$this->registerImportFromCsvCommand();
}
protected $defer = false;

/**
* Register the service provider.
Expand All @@ -36,7 +23,15 @@ public function boot(DispatcherContract $events)
*/
public function register()
{
require __DIR__.'/../../bindings.php';
if ($this->app->runningInConsole()) {
$this->commands([
ExportToCsvCommand::class,
ImportFromCsvCommand::class
]);
$this->app->singleton('LangImportExportLangListService', function ($app) {
return new LangListService();
});
}
}

/**
Expand All @@ -51,22 +46,4 @@ public function provides()
];
}

private function registerExportToCsvCommand() {
$this->app['lang-export.csv'] = $this->app->share(function($app)
{
return new ExportToCsvCommand();
});

$this->commands('lang-export.csv');
}

private function registerImportFromCsvCommand() {
$this->app['lang-import.csv'] = $this->app->share(function($app)
{
return new ImportFromCsvCommand();
});

$this->commands('lang-import.csv');
}

}
5 changes: 3 additions & 2 deletions src/UFirst/LangImportExport/LangListService.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
<?php

namespace UFirst\LangImportExport;
use Illuminate\Support\Arr;

use Lang;

class LangListService {

public function loadLangList($locale, $group) {
$translations = Lang::getLoader()->load($locale, $group);
$translations_with_prefix = array_dot(array($group => $translations));
$translations_with_prefix = Arr::dot(array($group => $translations));
return $translations_with_prefix;
}

public function writeLangList($locale, $group, $new_translations) {
$translations = Lang::getLoader()->load($locale, $group);
foreach($new_translations as $key => $value) {
array_set($translations, $key, $value);
Arr::set($translations, $key, $value);
}
$header = "<?php\n\nreturn ";

Expand Down
8 changes: 0 additions & 8 deletions src/bindings.php

This file was deleted.