Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pterodactyl
GitHub Repository: pterodactyl/panel
Path: blob/1.0-develop/app/Traits/Helpers/AvailableLanguages.php
10259 views
1
<?php
2
3
namespace Pterodactyl\Traits\Helpers;
4
5
use Matriphe\ISO639\ISO639;
6
use Illuminate\Filesystem\Filesystem;
7
8
trait AvailableLanguages
9
{
10
private ?ISO639 $iso639 = null;
11
12
private ?Filesystem $filesystem = null;
13
14
/**
15
* Return all the available languages on the Panel based on those
16
* that are present in the language folder.
17
*/
18
public function getAvailableLanguages(bool $localize = false): array
19
{
20
return collect($this->getFilesystemInstance()->directories(resource_path('lang')))->mapWithKeys(function ($path) use ($localize) {
21
$code = basename($path);
22
$value = $localize ? $this->getIsoInstance()->nativeByCode1($code) : $this->getIsoInstance()->languageByCode1($code);
23
24
return [$code => title_case($value)];
25
})->toArray();
26
}
27
28
/**
29
* Return an instance of the filesystem for getting a folder listing.
30
*/
31
private function getFilesystemInstance(): Filesystem
32
{
33
return $this->filesystem = $this->filesystem ?: app()->make(Filesystem::class);
34
}
35
36
/**
37
* Return an instance of the ISO639 class for generating names.
38
*/
39
private function getIsoInstance(): ISO639
40
{
41
return $this->iso639 = $this->iso639 ?: app()->make(ISO639::class);
42
}
43
}
44
45