fixed plugin column languages

This commit is contained in:
Edward Yang 2022-08-11 15:20:12 +08:00
parent 4f88ce7570
commit 32dfe47037
5 changed files with 24 additions and 1 deletions

View File

@ -123,6 +123,7 @@ class Manager
public function getPluginOrFail($code): ?Plugin
{
$plugin = $this->getPlugin($code);
$plugin->handleLabel();
if (empty($plugin)) {
throw new \Exception('无效的插件');
}

View File

@ -93,6 +93,24 @@ class Plugin implements Arrayable, \ArrayAccess
}
/**
* 处理插件后台设置字段多语言 优先级: label > label_key
* 有label字段则直接返回, label_key 则翻译
*/
public function handleLabel()
{
$this->columns = collect($this->columns)->map(function ($item) {
$labelKey = $item['label_key'] ?? '';
$label = $item['label'] ?? '';
if (empty($label) && $labelKey) {
$languageKey = "{$this->dirName}::{$labelKey}";
$item['label'] = trans($languageKey);
}
return $item;
})->toArray();
}
public function getDirname(): string
{
return $this->dirName;

View File

@ -10,6 +10,8 @@
*/
return [
'publishable_key' => 'Publishable Key',
'title_info' => 'Card information',
'cardnum' => 'Cardnum',
'expiration_date' => 'Expiration Date',

View File

@ -10,6 +10,8 @@
*/
return [
'publishable_key' => '公钥',
'title_info' => '卡信息',
'cardnum' => '卡号',
'expiration_date' => '截止日期',

View File

@ -12,7 +12,7 @@
return [
[
'name' => 'publishable_key',
'label' => '公钥',
'label_key' => 'common.publishable_key',
'type' => 'string',
'required' => true,
'rules' => 'required|size:32',