创建时翻译
This commit is contained in:
@@ -158,6 +158,54 @@ class VehicleController extends Crud
|
||||
$translations = array_merge($required_translations, $translations);
|
||||
}
|
||||
|
||||
// 如果是 POST 请求,处理数据保存和翻译
|
||||
if ($request->method() === 'POST') {
|
||||
// 获取表单数据
|
||||
$data = $request->all();
|
||||
$data['shipping_cycle'] = !empty($data['shipping_cycle'])?$data['shipping_cycle']:0;
|
||||
|
||||
|
||||
// 保存主表数据
|
||||
$vehicle = new Vehicle();
|
||||
$vehicle->fill($data);
|
||||
$vehicle->save();
|
||||
|
||||
Log::info('$request',$data);
|
||||
// 处理多语言翻译
|
||||
$languages = ['en', 'ar', 'ru'];
|
||||
$translationModels = [
|
||||
'en' => VehicleEn::class,
|
||||
'ar' => VehicleAr::class,
|
||||
'ru' => VehicleRu::class
|
||||
];
|
||||
|
||||
// 创建翻译服务实例
|
||||
$translatorService = new \app\service\TranslatorService();
|
||||
|
||||
foreach ($languages as $lang) {
|
||||
$translationModel = $translationModels[$lang];
|
||||
$translation = new $translationModel();
|
||||
|
||||
// 复制主表数据
|
||||
$translation->fill($data);
|
||||
$translation->id = $vehicle->id;
|
||||
|
||||
// 使用翻译服务处理需要翻译的字段
|
||||
$translatedData = $translatorService->vehicle($data, $lang);
|
||||
Log::info($lang.':'.$vehicle->id,$translatedData);
|
||||
|
||||
// 更新翻译后的字段
|
||||
$translation->brand = $translatedData['brand'] ?? $data['brand'];
|
||||
$translation->model = $translatedData['model'] ?? $data['model'];
|
||||
$translation->status = $translatedData['status'] ?? $data['status'];
|
||||
$translation->purchase_location = $translatedData['purchase_location'] ?? $data['purchase_location'];
|
||||
$translation->procedure_location = $translatedData['procedure_location'] ?? $data['procedure_location'];
|
||||
// $translation->fbo_destination = $translatedData['fbo_destination'] ?? $data['fbo_destination'];
|
||||
|
||||
$translation->save();
|
||||
}
|
||||
}
|
||||
|
||||
return view('vehicle/insert', [
|
||||
'lang' => $lang,
|
||||
'translations' => $translations
|
||||
|
||||
Reference in New Issue
Block a user