支持插件选项多语言

This commit is contained in:
Edward Yang 2022-08-11 15:37:00 +08:00
parent 8b8fe1730d
commit d253c64613
4 changed files with 53 additions and 7 deletions

View File

@ -100,16 +100,32 @@ class Plugin implements Arrayable, \ArrayAccess
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);
$item = $this->transLabel($item);
if (isset($item['options'])) {
$item['options'] = collect($item['options'])->map(function ($option) {
return $this->transLabel($option);
})->toArray();
}
return $item;
})->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
{

View File

@ -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',
];

View File

@ -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' => '开启',
];

View File

@ -44,10 +44,10 @@ return [
],
[
'name' => 'sandbox_mode',
'label' => '沙盒模式',
'label_key' => 'setting.sandbox_mode',
'type' => 'select',
'options' => [
['value' => '1', 'label' => '开启'],
['value' => '1', 'label_key' => 'setting.enabled'],
['value' => '0', 'label' => '关闭']
],
'required' => true,