Skip to content

Commit

Permalink
Merge pull request #38 from IBEC-BOX/feat/make-locale-data
Browse files Browse the repository at this point in the history
Feat/make locale data
  • Loading branch information
ast21 authored Jul 31, 2024
2 parents fa8b415 + 534818d commit 16f1f59
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/DTO/LocaleData.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace AdminKit\Core\DTO;

use AdminKit\Core\Facades\AdminKit;
use Illuminate\Support\Collection;
use Spatie\LaravelData\Data;

class LocaleData extends Data
Expand All @@ -18,4 +20,23 @@ public function __construct(
$this->title = __("admin-kit::language.$this->code");
$this->native = __(key: "admin-kit::language.$this->code", locale: $this->code);
}

public static function make(?string $locale = null): self
{
if (! $locale) {
$locale = app()->getLocale();
}

return new self($locale);
}

public static function makeCollection(?array $locales = null): Collection
{
if (! $locales) {
$locales = AdminKit::locales();
}

return collect($locales)
->map(fn (string $code) => new self($code));
}
}
2 changes: 1 addition & 1 deletion src/Providers/FilamentServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private function getPlugins(): array

$plugins[] = $reflect->hasMethod('make')
? $pluginsClass::make()
: new $pluginsClass();
: new $pluginsClass;
}

return $plugins;
Expand Down

0 comments on commit 16f1f59

Please sign in to comment.