Implement a better management interface for Settings (#809)
This commit is contained in:
parent
75eb506dab
commit
f9df463d32
40 changed files with 1274 additions and 383 deletions
56
app/Traits/Helpers/AvailableLanguages.php
Normal file
56
app/Traits/Helpers/AvailableLanguages.php
Normal file
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
namespace Pterodactyl\Traits\Helpers;
|
||||
|
||||
use Matriphe\ISO639\ISO639;
|
||||
use Illuminate\Filesystem\Filesystem;
|
||||
|
||||
trait AvailableLanguages
|
||||
{
|
||||
/**
|
||||
* @var \Illuminate\Filesystem\Filesystem
|
||||
*/
|
||||
private $filesystem;
|
||||
|
||||
/**
|
||||
* @var \Matriphe\ISO639\ISO639
|
||||
*/
|
||||
private $iso639;
|
||||
|
||||
/**
|
||||
* Return all of the available languages on the Panel based on those
|
||||
* that are present in the language folder.
|
||||
*
|
||||
* @param bool $localize
|
||||
* @return array
|
||||
*/
|
||||
public function getAvailableLanguages($localize = false): array
|
||||
{
|
||||
return collect($this->getFilesystemInstance()->directories(resource_path('lang')))->mapWithKeys(function ($path) use ($localize) {
|
||||
$code = basename($path);
|
||||
$value = $localize ? $this->getIsoInstance()->nativeByCode1($code) : $this->getIsoInstance()->languageByCode1($code);
|
||||
|
||||
return [$code => title_case($value)];
|
||||
})->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an instance of the filesystem for getting a folder listing.
|
||||
*
|
||||
* @return \Illuminate\Filesystem\Filesystem
|
||||
*/
|
||||
private function getFilesystemInstance(): Filesystem
|
||||
{
|
||||
return $this->filesystem = $this->filesystem ?: app()->make(Filesystem::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an instance of the ISO639 class for generating names.
|
||||
*
|
||||
* @return \Matriphe\ISO639\ISO639
|
||||
*/
|
||||
private function getIsoInstance(): ISO639
|
||||
{
|
||||
return $this->iso639 = $this->iso639 ?: app()->make(ISO639::class);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue