翻译修改为队列
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace app\queue\jobs;
|
||||
|
||||
use app\model\VehicleAr;
|
||||
use app\model\VehicleEn;
|
||||
use app\model\VehicleRu;
|
||||
use app\service\TranslatorService;
|
||||
use plugin\admin\app\model\Vehicle;
|
||||
use support\Log;
|
||||
|
||||
class TranslationJob
|
||||
{
|
||||
|
||||
protected array $payload;
|
||||
|
||||
public function __construct(array $payload)
|
||||
{
|
||||
$this->payload = $payload;
|
||||
}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
$pt = $this->payload;
|
||||
$entityType = $pt['entityType'];
|
||||
$sourceFields = $pt['sourceFields'];
|
||||
$sourceLang = $pt['sourceLang'];
|
||||
// $locale = $pt['locale'];
|
||||
$id = $pt['id'];
|
||||
|
||||
$translator = new TranslatorService();
|
||||
if($entityType == 'location'){
|
||||
$translationModels = [
|
||||
'cn' => \app\model\Location::class,
|
||||
'en' => \app\model\LocationEn::class,
|
||||
'ar' => \app\model\LocationAr::class,
|
||||
'ru' => \app\model\LocationRu::class
|
||||
];
|
||||
|
||||
}elseif($entityType == 'vehicle'){
|
||||
$translationModels = [
|
||||
'cn' => Vehicle::class,
|
||||
'en' => VehicleEn::class,
|
||||
'ar' => VehicleAr::class,
|
||||
'ru' => VehicleRu::class
|
||||
];
|
||||
}
|
||||
|
||||
$languages = ['cn' => 'cn', 'en' => 'en', 'ar' => 'ar', 'ru' => 'ru'];
|
||||
unset($languages[$sourceLang]);
|
||||
foreach ($languages as $lang => $xflang) {
|
||||
|
||||
if($entityType =='location'){
|
||||
$fields = $translator->location($sourceFields,$lang,$sourceLang);
|
||||
}else{
|
||||
$fields = $translator->vehicle($sourceFields,$lang,$sourceLang);
|
||||
}
|
||||
|
||||
$translationModel = $translationModels[$xflang];
|
||||
|
||||
if(!empty($id)){
|
||||
$translation = $translationModel::find($id);
|
||||
}else{
|
||||
$translation = new $translationModel();
|
||||
}
|
||||
$translation->fill($fields);
|
||||
$res = $translation->save();
|
||||
log::info('$languages save', [$res,$fields]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user