From 30f7e5d2a2dd7d326c696fe8cf153b68a4ae6d72 Mon Sep 17 00:00:00 2001 From: Edward Yang Date: Wed, 15 Feb 2023 00:05:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=90=8E=E5=8F=B0=E6=8F=92?= =?UTF-8?q?=E4=BB=B6=E6=98=BE=E7=A4=BA=E5=A4=9A=E8=AF=AD=E8=A8=80=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- beike/Admin/Http/Resources/PluginResource.php | 13 +++------- beike/Plugin/Plugin.php | 24 +++++++++++++++---- 2 files changed, 23 insertions(+), 14 deletions(-) diff --git a/beike/Admin/Http/Resources/PluginResource.php b/beike/Admin/Http/Resources/PluginResource.php index 0172fa94..aa22d381 100644 --- a/beike/Admin/Http/Resources/PluginResource.php +++ b/beike/Admin/Http/Resources/PluginResource.php @@ -16,15 +16,10 @@ class PluginResource extends JsonResource */ public function toArray($request): array { - $currentLocale = locale(); - - $name = is_array($this->name) ? ($this->name[$currentLocale] ?? '') : (string) $this->name; - $description = is_array($this->description) ? ($this->description[$currentLocale] ?? '') : (string) $this->description; - - $data = [ + return [ 'code' => $this->code, - 'name' => $name, - 'description' => $description, + 'name' => $this->getLocaleName(), + 'description' => $this->getLocaleDescription(), 'path' => $this->path, 'version' => $this->version, 'dir_name' => $this->dirName, @@ -36,7 +31,5 @@ class PluginResource extends JsonResource 'installed' => $this->getInstalled(), 'edit_url' => $this->getEditUrl(), ]; - - return $data; } } diff --git a/beike/Plugin/Plugin.php b/beike/Plugin/Plugin.php index d922cd62..37fc8f6d 100644 --- a/beike/Plugin/Plugin.php +++ b/beike/Plugin/Plugin.php @@ -154,9 +154,17 @@ class Plugin implements Arrayable, \ArrayAccess public function getLocaleName(): string { - $currentLocale = locale(); + $currentLocale = admin_locale(); - return is_array($this->name) ? ($this->name[$currentLocale] ?? '') : (string) $this->name; + if (is_array($this->name)) { + if ($this->name[$currentLocale] ?? '') { + return $this->name[$currentLocale]; + } + + return array_values($this->name)[0]; + } + + return (string) $this->name; } public function getDescription(): string @@ -166,9 +174,17 @@ class Plugin implements Arrayable, \ArrayAccess public function getLocaleDescription(): string { - $currentLocale = locale(); + $currentLocale = admin_locale(); - return is_array($this->description) ? ($this->description[$currentLocale] ?? '') : (string) $this->description; + if (is_array($this->description)) { + if ($this->description[$currentLocale] ?? '') { + return $this->description[$currentLocale]; + } + + return array_values($this->description)[0]; + } + + return (string) $this->description; } public function getDirname(): string