Files
panel/app/Traits/Helpers/AvailableLanguages.php

35 lines
915 B
PHP
Raw Normal View History

<?php
2024-03-12 22:39:16 -04:00
namespace App\Traits\Helpers;
2024-03-23 10:39:19 -04:00
use Locale;
use Illuminate\Filesystem\Filesystem;
trait AvailableLanguages
{
private ?Filesystem $filesystem = null;
/**
* Return all the available languages on the Panel based on those
* that are present in the language folder.
*/
2024-03-23 12:43:01 -04:00
public function getAvailableLanguages(): array
{
2024-03-23 12:43:01 -04:00
return collect($this->getFilesystemInstance()->directories(base_path('lang')))->mapWithKeys(function ($path) {
$code = basename($path);
2024-03-23 10:39:19 -04:00
$value = Locale::getDisplayName($code, app()->currentLocale());
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);
}
}