diff --git a/plugin/admin/app/controller/IndexController.php b/plugin/admin/app/controller/IndexController.php index cf509cc..babdb85 100644 --- a/plugin/admin/app/controller/IndexController.php +++ b/plugin/admin/app/controller/IndexController.php @@ -54,6 +54,10 @@ class IndexController // 加载语言文件 $common_translations = include __DIR__ . "/../lang/{$lang}/common.php"; + $vehicle_translations = include __DIR__ . "/../lang/{$lang}/vehicle.php"; + + // 合并翻译 + $translations = array_merge($common_translations, $vehicle_translations); // 获取菜单并应用翻译 $rules = Rule::whereIn('type', [0, 1])->orderBy('weight')->get(); @@ -66,7 +70,7 @@ class IndexController return view('index/index', [ 'lang' => $lang, - 'translations' => $common_translations, + 'translations' => $translations, 'menus' => $menus ]); } diff --git a/plugin/admin/app/controller/VehicleController.php b/plugin/admin/app/controller/VehicleController.php index 8c91218..2426f3d 100644 --- a/plugin/admin/app/controller/VehicleController.php +++ b/plugin/admin/app/controller/VehicleController.php @@ -54,45 +54,53 @@ class VehicleController extends Crud $lang = session('lang', 'zh-cn'); $translations = (array)require __DIR__ . '/../lang/' . $lang . '/vehicle.php'; $common = (array)require __DIR__ . '/../lang/' . $lang . '/common.php'; - $translations = array_merge($translations, $common); + $translations = array_merge($common, $translations); // 确保 common.php 的翻译优先 - // 只在中文时使用默认翻译 - if ($lang === 'zh-cn') { - $required_translations = [ - 'brand' => '车辆品牌', - 'brand_placeholder' => '请输入车辆品牌', - 'model' => '车辆型号', - 'model_placeholder' => '请输入车辆型号', - 'vin' => '车架号', - 'vin_placeholder' => '请输入车架号', - 'status' => '车辆状态', - 'status_placeholder' => '请选择状态', - 'purchase_location' => '买车地点', - 'purchase_location_placeholder' => '请输入买车地点', - 'procedure_location' => '手续办理地', - 'procedure_location_placeholder' => '请输入手续办理地', - 'fbo_location' => 'FBO目的地', - 'fbo_location_placeholder' => '请选择FBO目的地', - 'current_location' => '车辆所在地', - 'current_location_placeholder' => '请选择车辆所在地', - 'final_location' => '最终目的地', - 'final_location_placeholder' => '请选择最终目的地', - 'departure_time' => 'FBO发车时间', - 'departure_time_placeholder' => '请选择发车时间', - 'arrival_time' => 'FBO到达时间', - 'arrival_time_placeholder' => '请选择到达时间', - 'shipping_cycle' => '运输周期', - 'shipping_cycle_placeholder' => '请输入运输周期', - 'img_url' => '图片', - 'img_url_placeholder' => '请输入图片URL' - ]; - $translations = array_merge($required_translations, $translations); - } + // 添加默认翻译,确保所有语言都有基本翻译 + $required_translations = [ + 'title' => $lang === 'zh-cn' ? '车辆管理' : 'Vehicle Management', // 确保title翻译存在 + 'brand' => $lang === 'zh-cn' ? '车辆品牌' : 'Vehicle Brand', + 'brand_placeholder' => $lang === 'zh-cn' ? '请输入车辆品牌' : 'Please enter vehicle brand', + 'model' => $lang === 'zh-cn' ? '车辆型号' : 'Vehicle Model', + 'model_placeholder' => $lang === 'zh-cn' ? '请输入车辆型号' : 'Please enter vehicle model', + 'vin' => 'VIN', + 'vin_placeholder' => $lang === 'zh-cn' ? '请输入车架号' : 'Please enter VIN', + 'status' => $lang === 'zh-cn' ? '车辆状态' : 'Status', + 'status_placeholder' => $lang === 'zh-cn' ? '请选择状态' : 'Please select status', + 'purchase_location' => $lang === 'zh-cn' ? '买车地点' : 'Purchase Location', + 'purchase_location_placeholder' => $lang === 'zh-cn' ? '请输入买车地点' : 'Please enter purchase location', + 'procedure_location' => $lang === 'zh-cn' ? '手续办理地' : 'Procedure Location', + 'procedure_location_placeholder' => $lang === 'zh-cn' ? '请输入手续办理地' : 'Please enter procedure location', + 'fbo_location' => 'FBO Location', + 'fbo_location_placeholder' => $lang === 'zh-cn' ? '请选择FBO目的地' : 'Please select FBO location', + 'current_location' => $lang === 'zh-cn' ? '车辆所在地' : 'Current Location', + 'current_location_placeholder' => $lang === 'zh-cn' ? '请选择车辆所在地' : 'Please select current location', + 'final_location' => $lang === 'zh-cn' ? '最终目的地' : 'Final Location', + 'final_location_placeholder' => $lang === 'zh-cn' ? '请选择最终目的地' : 'Please select final location', + 'departure_time' => $lang === 'zh-cn' ? 'FBO发车时间' : 'FBO Departure Time', + 'departure_time_placeholder' => $lang === 'zh-cn' ? '请选择发车时间' : 'Please select departure time', + 'arrival_time' => $lang === 'zh-cn' ? 'FBO到达时间' : 'FBO Arrival Time', + 'arrival_time_placeholder' => $lang === 'zh-cn' ? '请选择到达时间' : 'Please select arrival time', + 'shipping_cycle' => $lang === 'zh-cn' ? '运输周期' : 'Shipping Cycle', + 'shipping_cycle_placeholder' => $lang === 'zh-cn' ? '请输入运输周期' : 'Please enter shipping cycle', + 'img_url' => $lang === 'zh-cn' ? '图片' : 'Image', + 'img_url_placeholder' => $lang === 'zh-cn' ? '请输入图片URL' : 'Please enter image URL', + 'operation' => $lang === 'zh-cn' ? '操作' : 'Operation', + 'refresh' => $lang === 'zh-cn' ? '刷新' : 'Refresh', + 'filter' => $lang === 'zh-cn' ? '筛选' : 'Filter', + 'print' => $lang === 'zh-cn' ? '打印' : 'Print', + 'export' => $lang === 'zh-cn' ? '导出' : 'Export', + 'id' => 'ID', + 'created_at' => $lang === 'zh-cn' ? '创建时间' : 'Created At', + 'updated_at' => $lang === 'zh-cn' ? '更新时间' : 'Updated At' + ]; + + // 合并翻译,确保语言文件中的翻译优先 + $translations = array_merge($required_translations, $translations); return view('vehicle/index', [ 'lang' => $lang, - 'translations' => $translations, - 'title' => $translations['title'] ?? '车辆管理' + 'translations' => $translations ]); } @@ -307,4 +315,19 @@ class VehicleController extends Crud return $items; } + + /** + * 获取翻译 + * @param Request $request + * @return Response + */ + public function getTranslations(Request $request): Response + { + $lang = session('lang', 'zh-cn'); + $translations = (array)require __DIR__ . '/../lang/' . $lang . '/vehicle.php'; + $common = (array)require __DIR__ . '/../lang/' . $lang . '/common.php'; + $translations = array_merge($translations, $common); + + return json(['code' => 0, 'msg' => 'success', 'data' => $translations]); + } } diff --git a/plugin/admin/app/lang/ar/vehicle.php b/plugin/admin/app/lang/ar/vehicle.php index 91daddf..c73c2f2 100644 --- a/plugin/admin/app/lang/ar/vehicle.php +++ b/plugin/admin/app/lang/ar/vehicle.php @@ -1,6 +1,7 @@ 'إدارة المركبات', 'title' => 'إدارة المركبات', 'add' => 'إضافة', 'edit' => 'تعديل', diff --git a/plugin/admin/app/lang/en/vehicle.php b/plugin/admin/app/lang/en/vehicle.php index 0fd8d22..aeed5cd 100644 --- a/plugin/admin/app/lang/en/vehicle.php +++ b/plugin/admin/app/lang/en/vehicle.php @@ -1,6 +1,7 @@ 'Vehicle Management', 'title' => 'Vehicle Management', 'add' => 'Add', 'edit' => 'Edit', @@ -34,8 +35,8 @@ return [ 'purchase_location_placeholder' => 'Please enter purchase location', 'procedure_location' => 'Procedure Location', 'procedure_location_placeholder' => 'Please enter procedure location', - 'location' => 'Current Location', - 'location_placeholder' => 'Please select current location', + 'current_location' => 'Current Location', + 'current_location_placeholder' => 'Please select current location', 'final_location' => 'Final Location', 'final_location_placeholder' => 'Please select final location', 'fbo_location' => 'FBO Location', diff --git a/plugin/admin/app/lang/ru/vehicle.php b/plugin/admin/app/lang/ru/vehicle.php index c8713b2..73ac6ae 100644 --- a/plugin/admin/app/lang/ru/vehicle.php +++ b/plugin/admin/app/lang/ru/vehicle.php @@ -34,8 +34,8 @@ return [ 'purchase_location_placeholder' => 'Введите место покупки', 'procedure_location' => 'Место оформления', 'procedure_location_placeholder' => 'Введите место оформления', - 'location' => 'Текущее местоположение', - 'location_placeholder' => 'Выберите текущее местоположение', + 'current_location' => 'Текущее местоположение', + 'current_location_placeholder' => 'Выберите текущее местоположение', 'final_location' => 'Конечное местоположение', 'final_location_placeholder' => 'Выберите конечное местоположение', 'fbo_location' => 'Местоположение FBO', diff --git a/plugin/admin/app/lang/zh-cn/vehicle.php b/plugin/admin/app/lang/zh-cn/vehicle.php index a3125b0..54b42e5 100644 --- a/plugin/admin/app/lang/zh-cn/vehicle.php +++ b/plugin/admin/app/lang/zh-cn/vehicle.php @@ -1,6 +1,7 @@ '车辆管理', 'title' => '车辆管理', 'add' => '新增', 'edit' => '编辑', diff --git a/plugin/admin/app/view/index/index.html b/plugin/admin/app/view/index/index.html index 8802738..90258b6 100644 --- a/plugin/admin/app/view/index/index.html +++ b/plugin/admin/app/view/index/index.html @@ -129,10 +129,13 @@