mirror of
https://github.com/pelican-dev/panel.git
synced 2025-11-09 11:59:26 +01:00
36 lines
995 B
PHP
36 lines
995 B
PHP
<?php
|
|
|
|
namespace App\Services\Helpers;
|
|
|
|
use App\Facades\Plugins;
|
|
use Illuminate\Support\Facades\File;
|
|
use Locale;
|
|
|
|
class LanguageService
|
|
{
|
|
public const TRANSLATED_COMPLETELY = [
|
|
'en',
|
|
];
|
|
|
|
public function isLanguageTranslated(string $countryCode = 'en'): bool
|
|
{
|
|
return in_array($countryCode, self::TRANSLATED_COMPLETELY, true);
|
|
}
|
|
|
|
/**
|
|
* @return array<array-key, string>
|
|
*/
|
|
public function getAvailableLanguages(string $path = 'lang'): array
|
|
{
|
|
$baseLanguages = collect(File::directories(base_path($path)))->mapWithKeys(function ($path) {
|
|
$code = basename($path);
|
|
|
|
return [$code => title_case(Locale::getDisplayName($code, $code))];
|
|
})->toArray();
|
|
|
|
$pluginLanguages = collect(Plugins::getPluginLanguages())->mapWithKeys(fn ($code) => [$code => title_case(Locale::getDisplayName($code, $code))])->toArray();
|
|
|
|
return array_unique(array_merge($baseLanguages, $pluginLanguages));
|
|
}
|
|
}
|