2017-12-14 21:05:26 -06:00
|
|
|
<?php
|
|
|
|
|
|
2024-03-12 22:39:16 -04:00
|
|
|
namespace App\Traits\Helpers;
|
2017-12-14 21:05:26 -06:00
|
|
|
|
2024-03-23 10:39:19 -04:00
|
|
|
use Locale;
|
2017-12-14 21:05:26 -06:00
|
|
|
use Illuminate\Filesystem\Filesystem;
|
|
|
|
|
|
|
|
|
|
trait AvailableLanguages
|
|
|
|
|
{
|
2022-10-14 10:59:20 -06:00
|
|
|
private ?Filesystem $filesystem = null;
|
2017-12-14 21:05:26 -06:00
|
|
|
|
|
|
|
|
/**
|
2022-10-14 10:59:20 -06:00
|
|
|
* Return all the available languages on the Panel based on those
|
2017-12-14 21:05:26 -06:00
|
|
|
* that are present in the language folder.
|
|
|
|
|
*/
|
2024-03-23 12:43:01 -04:00
|
|
|
public function getAvailableLanguages(): array
|
2017-12-14 21:05:26 -06:00
|
|
|
{
|
2024-03-23 12:43:01 -04:00
|
|
|
return collect($this->getFilesystemInstance()->directories(base_path('lang')))->mapWithKeys(function ($path) {
|
2017-12-14 21:05:26 -06:00
|
|
|
$code = basename($path);
|
2024-03-23 10:39:19 -04:00
|
|
|
|
|
|
|
|
$value = Locale::getDisplayName($code, app()->currentLocale());
|
2017-12-14 21:05:26 -06:00
|
|
|
|
|
|
|
|
return [$code => title_case($value)];
|
|
|
|
|
})->toArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return an instance of the filesystem for getting a folder listing.
|
|
|
|
|
*/
|
|
|
|
|
private function getFilesystemInstance(): Filesystem
|
|
|
|
|
{
|
|
|
|
|
return $this->filesystem = $this->filesystem ?: app()->make(Filesystem::class);
|
|
|
|
|
}
|
|
|
|
|
}
|