mirror of
https://github.com/pelican-dev/panel.git
synced 2025-11-08 10:39:27 +01:00
correctly handle language plugins
This commit is contained in:
parent
2384cc870a
commit
5dc01a66f3
@ -21,6 +21,7 @@ use Filament\Panel;
|
||||
* @method static void disablePlugin(string|Plugin $plugin)
|
||||
* @method static void updateLoadOrder(array<int, string> $order)
|
||||
* @method static bool hasThemePluginEnabled()
|
||||
* @method static string[] getPluginLanguages()
|
||||
*
|
||||
* @see \App\Services\Helpers\PluginService
|
||||
*/
|
||||
|
||||
@ -248,6 +248,11 @@ class Plugin extends Model implements HasPluginSettings
|
||||
return $this->category === 'theme';
|
||||
}
|
||||
|
||||
public function isLanguage(): bool
|
||||
{
|
||||
return $this->category === 'language';
|
||||
}
|
||||
|
||||
/** @return null|array<string, array{version: string, download_url: string}> */
|
||||
private function getUpdateData(): ?array
|
||||
{
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Services\Helpers;
|
||||
|
||||
use App\Facades\Plugins;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Locale;
|
||||
|
||||
@ -21,10 +22,14 @@ class LanguageService
|
||||
*/
|
||||
public function getAvailableLanguages(string $path = 'lang'): array
|
||||
{
|
||||
return collect(File::directories(base_path($path)))->mapWithKeys(function ($path) {
|
||||
$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));
|
||||
}
|
||||
}
|
||||
|
||||
@ -64,7 +64,11 @@ class PluginService
|
||||
$translations = plugin_path($plugin->id, 'lang');
|
||||
if (file_exists($translations)) {
|
||||
$this->app->afterResolving('translator', function ($translator) use ($plugin, $translations) {
|
||||
$translator->addNamespace($plugin->id, $translations);
|
||||
if ($plugin->isLanguage()) {
|
||||
$translator->addPath($translations);
|
||||
} else {
|
||||
$translator->addNamespace($plugin->id, $translations);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -309,4 +313,11 @@ class PluginService
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @return string[] */
|
||||
public function getPluginLanguages(): array
|
||||
{
|
||||
// TODO
|
||||
return ['pirate'];
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user