2017-12-15 03:05:26 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Pterodactyl\Traits\Helpers;
|
|
|
|
|
|
|
|
use Matriphe\ISO639\ISO639;
|
|
|
|
use Illuminate\Filesystem\Filesystem;
|
|
|
|
|
|
|
|
trait AvailableLanguages
|
|
|
|
{
|
2022-10-14 16:59:20 +00:00
|
|
|
private ?ISO639 $iso639 = null;
|
2017-12-15 03:05:26 +00:00
|
|
|
|
2022-10-14 16:59:20 +00:00
|
|
|
private ?Filesystem $filesystem = null;
|
2017-12-15 03:05:26 +00:00
|
|
|
|
|
|
|
/**
|
2022-10-14 16:59:20 +00:00
|
|
|
* Return all the available languages on the Panel based on those
|
2017-12-15 03:05:26 +00:00
|
|
|
* that are present in the language folder.
|
|
|
|
*/
|
2022-10-14 16:59:20 +00:00
|
|
|
public function getAvailableLanguages(bool $localize = false): array
|
2017-12-15 03:05:26 +00:00
|
|
|
{
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
private function getFilesystemInstance(): Filesystem
|
|
|
|
{
|
|
|
|
return $this->filesystem = $this->filesystem ?: app()->make(Filesystem::class);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an instance of the ISO639 class for generating names.
|
|
|
|
*/
|
|
|
|
private function getIsoInstance(): ISO639
|
|
|
|
{
|
|
|
|
return $this->iso639 = $this->iso639 ?: app()->make(ISO639::class);
|
|
|
|
}
|
|
|
|
}
|