forked from pterodactyl/panel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAvailableLanguages.php
More file actions
43 lines (35 loc) · 1.26 KB
/
AvailableLanguages.php
File metadata and controls
43 lines (35 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php
namespace Pterodactyl\Traits\Helpers;
use Matriphe\ISO639\ISO639;
use Illuminate\Filesystem\Filesystem;
trait AvailableLanguages
{
private ?ISO639 $iso639 = null;
private ?Filesystem $filesystem = null;
/**
* Return all the available languages on the Panel based on those
* that are present in the language folder.
*/
public function getAvailableLanguages(bool $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.
*/
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);
}
}