支持插件选项多语言
This commit is contained in:
parent
8b8fe1730d
commit
d253c64613
|
|
@ -100,16 +100,32 @@ class Plugin implements Arrayable, \ArrayAccess
|
||||||
public function handleLabel()
|
public function handleLabel()
|
||||||
{
|
{
|
||||||
$this->columns = collect($this->columns)->map(function ($item) {
|
$this->columns = collect($this->columns)->map(function ($item) {
|
||||||
$labelKey = $item['label_key'] ?? '';
|
$item = $this->transLabel($item);
|
||||||
$label = $item['label'] ?? '';
|
if (isset($item['options'])) {
|
||||||
if (empty($label) && $labelKey) {
|
$item['options'] = collect($item['options'])->map(function ($option) {
|
||||||
$languageKey = "{$this->dirName}::{$labelKey}";
|
return $this->transLabel($option);
|
||||||
$item['label'] = trans($languageKey);
|
})->toArray();
|
||||||
}
|
}
|
||||||
return $item;
|
return $item;
|
||||||
})->toArray();
|
})->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 翻译 label
|
||||||
|
* @param $item
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
private function transLabel($item)
|
||||||
|
{
|
||||||
|
$labelKey = $item['label_key'] ?? '';
|
||||||
|
$label = $item['label'] ?? '';
|
||||||
|
if (empty($label) && $labelKey) {
|
||||||
|
$languageKey = "{$this->dirName}::{$labelKey}";
|
||||||
|
$item['label'] = trans($languageKey);
|
||||||
|
}
|
||||||
|
return $item;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getDirname(): string
|
public function getDirname(): string
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* setting.php
|
||||||
|
*
|
||||||
|
* @copyright 2022 opencart.cn - All Rights Reserved
|
||||||
|
* @link http://www.guangdawangluo.com
|
||||||
|
* @author Edward Yang <yangjin@opencart.cn>
|
||||||
|
* @created 2022-08-11 15:26:18
|
||||||
|
* @modified 2022-08-11 15:26:18
|
||||||
|
*/
|
||||||
|
|
||||||
|
return [
|
||||||
|
'sandbox_mode' => 'Sandbox Mode',
|
||||||
|
'enabled' => 'Enabled',
|
||||||
|
];
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* setting.php
|
||||||
|
*
|
||||||
|
* @copyright 2022 opencart.cn - All Rights Reserved
|
||||||
|
* @link http://www.guangdawangluo.com
|
||||||
|
* @author Edward Yang <yangjin@opencart.cn>
|
||||||
|
* @created 2022-08-11 15:26:18
|
||||||
|
* @modified 2022-08-11 15:26:18
|
||||||
|
*/
|
||||||
|
|
||||||
|
return [
|
||||||
|
'sandbox_mode' => '沙盒模式',
|
||||||
|
'enabled' => '开启',
|
||||||
|
];
|
||||||
|
|
@ -44,10 +44,10 @@ return [
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'name' => 'sandbox_mode',
|
'name' => 'sandbox_mode',
|
||||||
'label' => '沙盒模式',
|
'label_key' => 'setting.sandbox_mode',
|
||||||
'type' => 'select',
|
'type' => 'select',
|
||||||
'options' => [
|
'options' => [
|
||||||
['value' => '1', 'label' => '开启'],
|
['value' => '1', 'label_key' => 'setting.enabled'],
|
||||||
['value' => '0', 'label' => '关闭']
|
['value' => '0', 'label' => '关闭']
|
||||||
],
|
],
|
||||||
'required' => true,
|
'required' => true,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue