翻译
This commit is contained in:
@@ -5,6 +5,8 @@ namespace app\admin\service;
|
||||
use app\admin\validate\SysCurrencyValidate;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\common\model\SysCurrency;
|
||||
use app\common\utils\translation\service\TranslationService;
|
||||
use app\queue\utils\Translat;
|
||||
use support\Request;
|
||||
|
||||
class SysCurrencyService
|
||||
@@ -58,4 +60,20 @@ class SysCurrencyService
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
public $translatFields = ['currency_name'];
|
||||
|
||||
public function afterServiceStore($res)
|
||||
{
|
||||
$sourceLocale = locale();
|
||||
$data = $res->toArray();
|
||||
$traitsourceFields = Translat::extractSourceFields($data, $this->translatFields);
|
||||
|
||||
(new TranslationService())->queueTranslations(
|
||||
'sys_currency',
|
||||
$res['id'],
|
||||
$sourceLocale,
|
||||
$traitsourceFields
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@ namespace app\admin\service;
|
||||
use app\admin\validate\SysDictItemValidate;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\common\model\SysDictItem;
|
||||
use app\common\utils\translation\service\TranslationService;
|
||||
use app\queue\utils\Translat;
|
||||
use support\Request;
|
||||
|
||||
class SysDictItemService
|
||||
@@ -72,4 +74,20 @@ class SysDictItemService
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
public $translatFields = ['item_label'];
|
||||
|
||||
public function afterServiceStore($res)
|
||||
{
|
||||
$sourceLocale = locale();
|
||||
$data = $res->toArray();
|
||||
$traitsourceFields = Translat::extractSourceFields($data, $this->translatFields);
|
||||
|
||||
(new TranslationService())->queueTranslations(
|
||||
'sys_dict_item',
|
||||
$res['id'],
|
||||
$sourceLocale,
|
||||
$traitsourceFields
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,8 @@ namespace app\admin\service;
|
||||
use app\admin\validate\SysDictValidate;
|
||||
use app\common\traits\crud\CrudServiceTrait;
|
||||
use app\common\model\SysDict;
|
||||
use app\common\utils\translation\service\TranslationService;
|
||||
use app\queue\utils\Translat;
|
||||
use support\Request;
|
||||
|
||||
class SysDictService
|
||||
@@ -124,4 +126,20 @@ class SysDictService
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public $translatFields = ['dict_name', 'description'];
|
||||
|
||||
public function afterServiceStore($res)
|
||||
{
|
||||
$sourceLocale = locale();
|
||||
$data = $res->toArray();
|
||||
$traitsourceFields = Translat::extractSourceFields($data, $this->translatFields);
|
||||
|
||||
(new TranslationService())->queueTranslations(
|
||||
'sys_dict',
|
||||
$res['id'],
|
||||
$sourceLocale,
|
||||
$traitsourceFields
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
class SysCurrencyTranslation extends Model
|
||||
{
|
||||
/**
|
||||
* The connection name for the model.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $connection = 'mysql';
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'sys_currency_translation';
|
||||
|
||||
/**
|
||||
* The primary key associated with the table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* Indicates if the model should be timestamped.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = true;
|
||||
|
||||
|
||||
protected $dateFormat = 'U';
|
||||
|
||||
/**
|
||||
* 允许自动填充模型字段
|
||||
*/
|
||||
protected $fillable = ['id', 'currency_id', 'locale', 'currency_name', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* 不允许自动填充模型字段
|
||||
*/
|
||||
protected $guarded = [];
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
class SysDictItemTranslation extends Model
|
||||
{
|
||||
/**
|
||||
* The connection name for the model.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $connection = 'mysql';
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'sys_dict_translation';
|
||||
|
||||
/**
|
||||
* The primary key associated with the table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* Indicates if the model should be timestamped.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = true;
|
||||
|
||||
|
||||
protected $dateFormat = 'U';
|
||||
|
||||
/**
|
||||
* 允许自动填充模型字段
|
||||
*/
|
||||
protected $fillable = ['id', 'dict_id', 'locale', 'dict_name', 'description', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* 不允许自动填充模型字段
|
||||
*/
|
||||
protected $guarded = [];
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace app\common\model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
class SysDictTranslation extends Model
|
||||
{
|
||||
/**
|
||||
* The connection name for the model.
|
||||
*
|
||||
* @var string|null
|
||||
*/
|
||||
protected $connection = 'mysql';
|
||||
|
||||
/**
|
||||
* The table associated with the model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $table = 'sys_dict_translation';
|
||||
|
||||
/**
|
||||
* The primary key associated with the table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
/**
|
||||
* Indicates if the model should be timestamped.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
public $timestamps = true;
|
||||
|
||||
|
||||
protected $dateFormat = 'U';
|
||||
|
||||
/**
|
||||
* 允许自动填充模型字段
|
||||
*/
|
||||
protected $fillable = ['id', 'dict_id', 'locale', 'dict_name', 'description', 'created_at', 'updated_at'];
|
||||
|
||||
/**
|
||||
* 不允许自动填充模型字段
|
||||
*/
|
||||
protected $guarded = [];
|
||||
}
|
||||
@@ -7,6 +7,18 @@ return [
|
||||
'translation_model' => \app\ticket\model\CategorieTranslation::class,
|
||||
'foreign_key' => 'categorie_id',
|
||||
],
|
||||
'sys_currency' => [
|
||||
'translation_model' => app\common\model\SysCurrencyTranslation::class,
|
||||
'foreign_key' => 'currency_id',
|
||||
],
|
||||
'sys_dict' => [
|
||||
'translation_model' => app\common\model\SysDictTranslation::class,
|
||||
'foreign_key' => 'dict_id',
|
||||
],
|
||||
'sys_dict_item' => [
|
||||
'translation_model' => app\common\model\SysDictItemTranslation::class,
|
||||
'foreign_key' => 'dict_item_id',
|
||||
],
|
||||
],
|
||||
|
||||
// 默认支持的目标语种列表
|
||||
|
||||
Reference in New Issue
Block a user