仓库多语言编辑
This commit is contained in:
@@ -192,32 +192,36 @@ class VehicleController extends Crud
|
||||
$data = $request->all();
|
||||
$data['shipping_cycle'] = !empty($data['shipping_cycle'])?$data['shipping_cycle']:0;
|
||||
|
||||
$lang = session('lang', 'zh-cn');
|
||||
list($vehicleModel,$local) = $this->getModel($lang);
|
||||
|
||||
// 保存主表数据
|
||||
if(!empty($data['id'])){
|
||||
$vehicle = Vehicle::find($data['id']);
|
||||
$vehicle = $vehicleModel::find($data['id']);
|
||||
}else{
|
||||
$vehicle = new Vehicle();
|
||||
$vehicle =$vehicleModel;
|
||||
}
|
||||
$vehicle->fill($data);
|
||||
|
||||
// return json($vehicle);
|
||||
$vehicle->save();
|
||||
|
||||
Log::info('$request',$data);
|
||||
// 处理多语言翻译
|
||||
$languages = ['en', 'ar', 'ru'];
|
||||
$languages = ['zh-cn' => 'cn', 'en' => 'en', 'ar' => 'ar', 'ru' => 'ru'];
|
||||
$translationModels = [
|
||||
'cn' => Vehicle::class,
|
||||
'en' => VehicleEn::class,
|
||||
'ar' => VehicleAr::class,
|
||||
'ru' => VehicleRu::class
|
||||
];
|
||||
//删除已保存的模型
|
||||
unset($translationModels[$lang]);
|
||||
unset($languages[$lang]);
|
||||
|
||||
// 创建翻译服务实例
|
||||
$translatorService = new \app\service\TranslatorService();
|
||||
|
||||
foreach ($languages as $lang) {
|
||||
$translationModel = $translationModels[$lang];
|
||||
foreach ($languages as $language) {
|
||||
$translationModel = $translationModels[$language];
|
||||
if(!empty($data['id'])){
|
||||
// $vehicle = Vehicle::find($data['id']);
|
||||
$translation = $translationModel::find($data['id']);
|
||||
@@ -230,8 +234,8 @@ class VehicleController extends Crud
|
||||
$translation->id = $vehicle->id;
|
||||
|
||||
// 使用翻译服务处理需要翻译的字段
|
||||
$translatedData = $translatorService->vehicle($data, $lang);
|
||||
Log::info($lang.':'.$vehicle->id,$translatedData);
|
||||
log::info('lang:',[$language,$lang]);
|
||||
$translatedData = $translatorService->vehicle($data, $language,$lang);
|
||||
|
||||
// 更新翻译后的字段
|
||||
$translation->brand = $translatedData['brand'] ?? $data['brand'];
|
||||
@@ -407,6 +411,7 @@ class VehicleController extends Crud
|
||||
// $item->status = "已到达迪拜仓库";
|
||||
$item->location_name = $location ? $location->name : '';
|
||||
$final_location = $hz::find($item->final_locations_id);
|
||||
// log::info('final_location_name:',[$item->final_locations_id]);
|
||||
$item->final_location_name = $final_location ? $final_location->name : '';
|
||||
$fbo_location = $hz::find($item->fbo_locations_id);
|
||||
$item->fbo_location_name = $fbo_location ? $fbo_location->name : '';
|
||||
@@ -415,8 +420,8 @@ class VehicleController extends Crud
|
||||
$item->location_name = $location ? $location->name : '';
|
||||
// $car = $vehicle::find($item->id);
|
||||
// $item->status = $car ? $car->status : $item->status;
|
||||
$location = $hz::find($item->final_location_id);
|
||||
$item->final_location_name = $location ? $location->name : '';
|
||||
// $location = $hz::find($item->final_location_id);
|
||||
// $item->final_location_name = $location ? $location->name : '';
|
||||
$location = $hz::find($item->fbo_locations_id);
|
||||
$item->fbo_location_name = $location ? $location->name : '';
|
||||
|
||||
@@ -447,7 +452,36 @@ class VehicleController extends Crud
|
||||
return $items;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $lang
|
||||
* @return array
|
||||
*/
|
||||
protected function getModel($lang){
|
||||
|
||||
switch ($lang) {
|
||||
case 'en':
|
||||
$vehicle = new \app\model\VehicleEn();
|
||||
$hz = new \app\model\LocationEn();
|
||||
break;
|
||||
|
||||
case 'ru':
|
||||
$vehicle = new \app\model\VehicleRu();
|
||||
$hz = new \app\model\LocationRu();
|
||||
break;
|
||||
case 'ar':
|
||||
$vehicle = new \app\model\VehicleAr();
|
||||
$hz = new \app\model\LocationAr();
|
||||
break;
|
||||
default:
|
||||
$vehicle = new \app\model\Vehicle();
|
||||
$hz = new \app\model\Location();
|
||||
break;
|
||||
}
|
||||
return array($vehicle, $hz);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取翻译
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
|
||||
Reference in New Issue
Block a user