Skip to content

Commit

Permalink
Merge pull request #342 from Laravel-Lang/15.x
Browse files Browse the repository at this point in the history
Fixed getting a list of available locales when deleting
  • Loading branch information
andrey-helldar committed Nov 2, 2023
2 parents cd11c1e + 2ffe433 commit a404d77
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
17 changes: 8 additions & 9 deletions src/Console/Add.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

namespace LaravelLang\Publisher\Console;

use LaravelLang\Locales\Enums\Locale;
use LaravelLang\Locales\Facades\Locales;
use LaravelLang\Publisher\Exceptions\UnknownLocaleCodeException;
use LaravelLang\Publisher\Processors\Add as AddProcessor;
Expand All @@ -38,14 +39,12 @@ protected function locales(): array
return Locales::raw()->available();
}

$locales = $this->getLocalesArgument();

foreach ($locales as $locale) {
if (! Locales::isAvailable($locale)) {
throw new UnknownLocaleCodeException($locale);
}
}

return $locales;
return $this->getLocalesArgument()
->each(function (Locale|string $locale) {
if (! Locales::isAvailable($locale)) {
throw new UnknownLocaleCodeException($locale);
}
})
->all();
}
}
6 changes: 3 additions & 3 deletions src/Console/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
namespace LaravelLang\Publisher\Console;

use Illuminate\Console\Command;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use LaravelLang\Locales\Facades\Locales;
use LaravelLang\Publisher\Contracts\TextDecorator;
use LaravelLang\Publisher\Helpers\Config;
Expand Down Expand Up @@ -70,8 +70,8 @@ protected function confirmAll(): bool
return false;
}

protected function getLocalesArgument(): array
protected function getLocalesArgument(): Collection
{
return Arr::wrap($this->argument('locales'));
return collect($this->argument('locales'));
}
}
29 changes: 15 additions & 14 deletions src/Console/Remove.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

namespace LaravelLang\Publisher\Console;

use LaravelLang\Locales\Enums\Locale;
use LaravelLang\Locales\Facades\Locales;
use LaravelLang\Publisher\Exceptions\ProtectedLocaleException;
use LaravelLang\Publisher\Exceptions\UnknownLocaleCodeException;
Expand All @@ -36,21 +37,21 @@ class Remove extends Base
protected function locales(): array
{
if ($this->confirmAll()) {
return Locales::raw()->installed(false);
return Locales::raw()->installed(
$this->option('force')
);
}

$locales = $this->getLocalesArgument();

foreach ($locales as $locale) {
if (! Locales::isAvailable($locale)) {
throw new UnknownLocaleCodeException($locale);
}

if (Locales::isProtected($locale) && ! $this->option('force')) {
throw new ProtectedLocaleException($locale);
}
}

return $locales;
return $this->getLocalesArgument()
->each(function (Locale|string $locale) {
if (! Locales::isAvailable($locale)) {
throw new UnknownLocaleCodeException($locale);
}

if (Locales::isProtected($locale) && ! $this->option('force')) {
throw new ProtectedLocaleException($locale);
}
})
->all();
}
}

0 comments on commit a404d77

Please sign in to comment.