mirror of
https://github.com/pelican-dev/panel.git
synced 2025-11-09 20:19:26 +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 disablePlugin(string|Plugin $plugin)
|
||||||
* @method static void updateLoadOrder(array<int, string> $order)
|
* @method static void updateLoadOrder(array<int, string> $order)
|
||||||
* @method static bool hasThemePluginEnabled()
|
* @method static bool hasThemePluginEnabled()
|
||||||
|
* @method static string[] getPluginLanguages()
|
||||||
*
|
*
|
||||||
* @see \App\Services\Helpers\PluginService
|
* @see \App\Services\Helpers\PluginService
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -248,6 +248,11 @@ class Plugin extends Model implements HasPluginSettings
|
|||||||
return $this->category === 'theme';
|
return $this->category === 'theme';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function isLanguage(): bool
|
||||||
|
{
|
||||||
|
return $this->category === 'language';
|
||||||
|
}
|
||||||
|
|
||||||
/** @return null|array<string, array{version: string, download_url: string}> */
|
/** @return null|array<string, array{version: string, download_url: string}> */
|
||||||
private function getUpdateData(): ?array
|
private function getUpdateData(): ?array
|
||||||
{
|
{
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Services\Helpers;
|
namespace App\Services\Helpers;
|
||||||
|
|
||||||
|
use App\Facades\Plugins;
|
||||||
use Illuminate\Support\Facades\File;
|
use Illuminate\Support\Facades\File;
|
||||||
use Locale;
|
use Locale;
|
||||||
|
|
||||||
@ -21,10 +22,14 @@ class LanguageService
|
|||||||
*/
|
*/
|
||||||
public function getAvailableLanguages(string $path = 'lang'): array
|
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);
|
$code = basename($path);
|
||||||
|
|
||||||
return [$code => title_case(Locale::getDisplayName($code, $code))];
|
return [$code => title_case(Locale::getDisplayName($code, $code))];
|
||||||
})->toArray();
|
})->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');
|
$translations = plugin_path($plugin->id, 'lang');
|
||||||
if (file_exists($translations)) {
|
if (file_exists($translations)) {
|
||||||
$this->app->afterResolving('translator', function ($translator) use ($plugin, $translations) {
|
$this->app->afterResolving('translator', function ($translator) use ($plugin, $translations) {
|
||||||
|
if ($plugin->isLanguage()) {
|
||||||
|
$translator->addPath($translations);
|
||||||
|
} else {
|
||||||
$translator->addNamespace($plugin->id, $translations);
|
$translator->addNamespace($plugin->id, $translations);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -309,4 +313,11 @@ class PluginService
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @return string[] */
|
||||||
|
public function getPluginLanguages(): array
|
||||||
|
{
|
||||||
|
// TODO
|
||||||
|
return ['pirate'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user