2017-12-14 21:05:26 -06:00
|
|
|
<?php
|
|
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2017-12-14 21:05:26 -06:00
|
|
|
namespace Pterodactyl\Traits\Helpers;
|
|
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
use Illuminate\Support\Facades\File;
|
|
|
|
|
use Illuminate\Support\Str;
|
|
|
|
|
use Locale;
|
2017-12-14 21:05:26 -06:00
|
|
|
|
|
|
|
|
trait AvailableLanguages
|
|
|
|
|
{
|
|
|
|
|
/**
|
2022-10-14 10:59:20 -06:00
|
|
|
* Return all the available languages on the Panel based on those
|
2017-12-14 21:05:26 -06:00
|
|
|
* that are present in the language folder.
|
2026-10-05 18:10:18 -04:00
|
|
|
*
|
|
|
|
|
* @return array<string, string> language code mapped to its display name
|
2017-12-14 21:05:26 -06:00
|
|
|
*/
|
2022-10-14 10:59:20 -06:00
|
|
|
public function getAvailableLanguages(bool $localize = false): array
|
2017-12-14 21:05:26 -06:00
|
|
|
{
|
2026-10-05 18:10:18 -04:00
|
|
|
$languages = [];
|
2026-10-11 20:11:13 -04:00
|
|
|
foreach (array_filter(File::directories(resource_path('lang')), is_string(...)) as $path) {
|
2017-12-14 21:05:26 -06:00
|
|
|
$code = basename($path);
|
2026-10-05 18:10:18 -04:00
|
|
|
$value = Locale::getDisplayLanguage($code, $localize ? $code : 'en') ?: $code;
|
|
|
|
|
$languages[$code] = Str::title($value);
|
|
|
|
|
}
|
2017-12-14 21:05:26 -06:00
|
|
|
|
2026-10-05 18:10:18 -04:00
|
|
|
return $languages;
|
2017-12-14 21:05:26 -06:00
|
|
|
}
|
|
|
|
|
}
|