Files

31 lines
826 B
PHP
Raw Permalink Normal View History

<?php
2026-10-05 18:10:18 -04:00
declare(strict_types=1);
namespace Pterodactyl\Traits\Helpers;
2026-10-05 18:10:18 -04:00
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
use Locale;
trait AvailableLanguages
{
/**
2022-10-14 10:59:20 -06:00
* Return all the available languages on the Panel based on those
* 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
*/
2022-10-14 10:59:20 -06:00
public function getAvailableLanguages(bool $localize = false): array
{
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) {
$code = basename($path);
2026-10-05 18:10:18 -04:00
$value = Locale::getDisplayLanguage($code, $localize ? $code : 'en') ?: $code;
$languages[$code] = Str::title($value);
}
2026-10-05 18:10:18 -04:00
return $languages;
}
}