Path: blob/1.0-develop/app/Traits/Helpers/AvailableLanguages.php
10259 views
<?php12namespace Pterodactyl\Traits\Helpers;34use Matriphe\ISO639\ISO639;5use Illuminate\Filesystem\Filesystem;67trait AvailableLanguages8{9private ?ISO639 $iso639 = null;1011private ?Filesystem $filesystem = null;1213/**14* Return all the available languages on the Panel based on those15* that are present in the language folder.16*/17public function getAvailableLanguages(bool $localize = false): array18{19return collect($this->getFilesystemInstance()->directories(resource_path('lang')))->mapWithKeys(function ($path) use ($localize) {20$code = basename($path);21$value = $localize ? $this->getIsoInstance()->nativeByCode1($code) : $this->getIsoInstance()->languageByCode1($code);2223return [$code => title_case($value)];24})->toArray();25}2627/**28* Return an instance of the filesystem for getting a folder listing.29*/30private function getFilesystemInstance(): Filesystem31{32return $this->filesystem = $this->filesystem ?: app()->make(Filesystem::class);33}3435/**36* Return an instance of the ISO639 class for generating names.37*/38private function getIsoInstance(): ISO63939{40return $this->iso639 = $this->iso639 ?: app()->make(ISO639::class);41}42}434445