翻译
This commit is contained in:
@@ -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
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -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]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'menu_vehicle' => 'إدارة المركبات',
|
||||
'title' => 'إدارة المركبات',
|
||||
'add' => 'إضافة',
|
||||
'edit' => 'تعديل',
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'menu_vehicle' => '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',
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'menu_vehicle' => '车辆管理',
|
||||
'title' => '车辆管理',
|
||||
'add' => '新增',
|
||||
'edit' => '编辑',
|
||||
|
||||
@@ -129,10 +129,13 @@
|
||||
<script src="/app/admin/component/pear/pear.js"></script>
|
||||
<!-- 框 架 初 始 化 -->
|
||||
<script>
|
||||
// 初始化翻译
|
||||
var translations = <?= json_encode($translations ?? []) ?>;
|
||||
|
||||
// Admin
|
||||
window.Admin = {
|
||||
Account: {},
|
||||
Translations: <?= json_encode($translations ?? []) ?>
|
||||
Translations: translations
|
||||
};
|
||||
|
||||
layui.use(["admin","jquery","popup","drawer","form","tab"], function() {
|
||||
@@ -150,7 +153,7 @@
|
||||
// 初始化菜单
|
||||
var config = {
|
||||
logo: {
|
||||
title: "<?= $translations['system_name'] ?? 'Vehicle Data Platform' ?>",
|
||||
title: translations.system_name || 'Vehicle Data Platform',
|
||||
image: "/app/admin/admin/images/logo.png",
|
||||
href: "/"
|
||||
},
|
||||
@@ -162,22 +165,7 @@
|
||||
control: false,
|
||||
controlWidth: 2000,
|
||||
select: "1",
|
||||
async: true,
|
||||
click: function(data) {
|
||||
// 更新标签页标题
|
||||
if (data.title) {
|
||||
// 获取当前标签页
|
||||
var currentTab = $('.layui-tab-title .layui-this');
|
||||
if (currentTab.length) {
|
||||
// 保存完整的菜单信息
|
||||
currentTab.find('span')
|
||||
.data('menu-id', data.id)
|
||||
.data('menu-key', data.key)
|
||||
.data('menu-pid', data.pid)
|
||||
.text(data.title);
|
||||
}
|
||||
}
|
||||
}
|
||||
async: true
|
||||
},
|
||||
tab: {
|
||||
enable: true,
|
||||
@@ -188,23 +176,7 @@
|
||||
index: {
|
||||
id: "1",
|
||||
href: "/app/admin/vehicle/index",
|
||||
title: "<?= $translations['vehicle_management'] ?? '车辆管理' ?>"
|
||||
},
|
||||
close: function(layid) {
|
||||
// 获取当前标签页
|
||||
var currentTab = $('.layui-tab-title li[lay-id="' + layid + '"]');
|
||||
if (currentTab.length) {
|
||||
// 移除标签页
|
||||
currentTab.remove();
|
||||
// 移除对应的内容
|
||||
$('.layui-tab-content .layui-tab-item[lay-id="' + layid + '"]').remove();
|
||||
// 如果还有其他标签页,激活最后一个
|
||||
var lastTab = $('.layui-tab-title li:last');
|
||||
if (lastTab.length) {
|
||||
lastTab.addClass('layui-this');
|
||||
$('.layui-tab-content .layui-tab-item:last').addClass('layui-show');
|
||||
}
|
||||
}
|
||||
title: translations.title || "车辆管理"
|
||||
}
|
||||
},
|
||||
theme: {
|
||||
@@ -284,6 +256,12 @@
|
||||
.text(menuItem.title);
|
||||
}
|
||||
});
|
||||
|
||||
// 确保默认标签页使用正确的翻译
|
||||
var defaultTab = $('.layui-tab-title li[lay-id="1"]');
|
||||
if (defaultTab.length) {
|
||||
defaultTab.find('span').text(translations.title || '车辆管理');
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -298,21 +276,23 @@
|
||||
data: { lang: lang },
|
||||
success: function(res) {
|
||||
if (res.code === 0) {
|
||||
// 关闭所有非首页标签页
|
||||
$('.layui-tab-title li').each(function() {
|
||||
var layId = $(this).attr('lay-id');
|
||||
if (layId && layId !== '1') { // 保留车辆管理标签
|
||||
var closeBtn = $(this).find('.layui-tab-close');
|
||||
if (closeBtn.length) {
|
||||
closeBtn.trigger('click');
|
||||
// 获取新的翻译
|
||||
$.get('/app/admin/vehicle/getTranslations', function(newTranslations) {
|
||||
// 更新全局翻译
|
||||
window.Admin.Translations = newTranslations;
|
||||
translations = newTranslations;
|
||||
|
||||
// 关闭所有标签页
|
||||
$('.layui-tab-title li').each(function() {
|
||||
var layid = $(this).attr('lay-id');
|
||||
if (layid) {
|
||||
$(this).find('.layui-tab-close').trigger('click');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// 等待标签页关闭后刷新页面
|
||||
setTimeout(function() {
|
||||
});
|
||||
|
||||
// 刷新页面
|
||||
window.location.reload();
|
||||
}, 100);
|
||||
});
|
||||
} else {
|
||||
popup.failure(res.msg);
|
||||
}
|
||||
|
||||
@@ -16,51 +16,108 @@
|
||||
<div class="main-container mr-5">
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><?= $translations['name'] ?? '名称' ?></label>
|
||||
<div class="layui-input-block">
|
||||
<div class="layui-form-mid"><?= $data['name'] ?? '' ?></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><?= $translations['name_en'] ?? '英文名称' ?></label>
|
||||
<div class="layui-input-block">
|
||||
<div class="layui-form-mid"><?= $data['name_en'] ?? '' ?></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><?= $translations['vin'] ?? 'VIN' ?></label>
|
||||
<label class="layui-form-label"><?= $translations['vin'] ?? '车架号' ?></label>
|
||||
<div class="layui-input-block">
|
||||
<div class="layui-form-mid"><?= $data['vin'] ?? '' ?></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><?= $translations['status'] ?? '状态' ?></label>
|
||||
<label class="layui-form-label"><?= $translations['classify'] ?? '分类' ?></label>
|
||||
<div class="layui-input-block">
|
||||
<div class="layui-form-mid"><?= ($data['status'] ?? '') == '1' ? ($translations['status_1'] ?? '正常') : ($translations['status_0'] ?? '禁用') ?></div>
|
||||
<div class="layui-form-mid"><?= ($data['classify'] ?? '') == '1' ? ($translations['self_owned'] ?? '自主') : ($translations['agent'] ?? '代理') ?></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><?= $translations['location'] ?? '当前位置' ?></label>
|
||||
<label class="layui-form-label"><?= $translations['brand'] ?? '车辆品牌' ?></label>
|
||||
<div class="layui-input-block">
|
||||
<div class="layui-form-mid"><?= $data['brand'] ?? '' ?></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><?= $translations['model'] ?? '车辆型号' ?></label>
|
||||
<div class="layui-input-block">
|
||||
<div class="layui-form-mid"><?= $data['model'] ?? '' ?></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><?= $translations['status'] ?? '车辆状态' ?></label>
|
||||
<div class="layui-input-block">
|
||||
<div class="layui-form-mid">
|
||||
<?php
|
||||
$status = $data['status'] ?? '';
|
||||
$statusText = '';
|
||||
switch($status) {
|
||||
case '1': $statusText = $translations['status_pending'] ?? '待发车'; break;
|
||||
case '2': $statusText = $translations['status_shipping_to_fbo'] ?? '在途(发往fbo港口)'; break;
|
||||
case '3': $statusText = $translations['status_arrived_fbo'] ?? '抵达发货港口'; break;
|
||||
case '4': $statusText = $translations['status_shipping_to_warehouse'] ?? '在途(发往目的地仓库)'; break;
|
||||
case '5': $statusText = $translations['status_arrived_warehouse'] ?? '抵达仓库'; break;
|
||||
case '6': $statusText = $translations['status_sold'] ?? '售出'; break;
|
||||
default: $statusText = $translations['status_unknown'] ?? '未知';
|
||||
}
|
||||
echo $statusText;
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><?= $translations['purchase_location'] ?? '买车地点' ?></label>
|
||||
<div class="layui-input-block">
|
||||
<div class="layui-form-mid"><?= $data['purchase_location'] ?? '' ?></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><?= $translations['procedure_location'] ?? '手续办理地' ?></label>
|
||||
<div class="layui-input-block">
|
||||
<div class="layui-form-mid"><?= $data['procedure_location'] ?? '' ?></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><?= $translations['fbo_location'] ?? 'FBO目的地' ?></label>
|
||||
<div class="layui-input-block">
|
||||
<div class="layui-form-mid"><?= $data['fbo_location_name'] ?? '' ?></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><?= $translations['current_location'] ?? '车辆所在地' ?></label>
|
||||
<div class="layui-input-block">
|
||||
<div class="layui-form-mid"><?= $data['location_name'] ?? '' ?></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><?= $translations['final_location'] ?? '最终位置' ?></label>
|
||||
<label class="layui-form-label"><?= $translations['final_location'] ?? '最终目的地' ?></label>
|
||||
<div class="layui-input-block">
|
||||
<div class="layui-form-mid"><?= $data['final_location_name'] ?? '' ?></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><?= $translations['fbo_location'] ?? 'FBO位置' ?></label>
|
||||
<label class="layui-form-label"><?= $translations['departure_time'] ?? 'FBO发车时间' ?></label>
|
||||
<div class="layui-input-block">
|
||||
<div class="layui-form-mid"><?= $data['fbo_location_name'] ?? '' ?></div>
|
||||
<div class="layui-form-mid"><?= $data['departure_time'] ?? '' ?></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><?= $translations['arrival_time'] ?? 'FBO到达时间' ?></label>
|
||||
<div class="layui-input-block">
|
||||
<div class="layui-form-mid"><?= $data['arrival_time'] ?? '' ?></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="layui-form-item">
|
||||
<label class="layui-form-label"><?= $translations['shipping_cycle'] ?? '运输周期' ?></label>
|
||||
<div class="layui-input-block">
|
||||
<div class="layui-form-mid"><?= $data['shipping_cycle'] ?? '' ?></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -70,22 +70,28 @@
|
||||
|
||||
console.log('Layui initialized');
|
||||
|
||||
// 更新标签页标题
|
||||
try {
|
||||
if (window.parent && window.parent.layui) {
|
||||
window.parent.layui.use(['tab'], function() {
|
||||
let tab = window.parent.layui.tab;
|
||||
if (tab && typeof tab.changeTitle === 'function') {
|
||||
let currentTab = window.parent.document.querySelector('.layui-tab-title .layui-this');
|
||||
if (currentTab) {
|
||||
tab.changeTitle(currentTab.getAttribute('lay-id'), translations.title);
|
||||
}
|
||||
// 监听语言更新消息
|
||||
window.addEventListener('message', function(event) {
|
||||
if (event.data && event.data.type === 'language_changed') {
|
||||
// 重新获取翻译
|
||||
$.get('/app/admin/vehicle/getTranslations', function(translations) {
|
||||
// 更新标签页标题
|
||||
if (window.parent && window.parent.layui) {
|
||||
window.parent.layui.use(['tab'], function() {
|
||||
let tab = window.parent.layui.tab;
|
||||
if (tab && typeof tab.changeTitle === 'function') {
|
||||
let currentTab = window.parent.document.querySelector('.layui-tab-title .layui-this');
|
||||
if (currentTab) {
|
||||
tab.changeTitle(currentTab.getAttribute('lay-id'), translations.title);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
// 重新加载表格
|
||||
table.reload('data-table');
|
||||
});
|
||||
}
|
||||
} catch (e) {
|
||||
console.warn('Failed to update tab title:', e);
|
||||
}
|
||||
});
|
||||
|
||||
// 表头参数
|
||||
let cols = [[
|
||||
@@ -93,7 +99,7 @@
|
||||
{title: translations.id, align: "center", field: "id"},
|
||||
{title: translations.vin, align: "center", field: "vin"},
|
||||
{title: translations.status, align: "center", field: "status"},
|
||||
{title: translations.location, align: "center", field: "location_name"},
|
||||
{title: translations.current_location, align: "center", field: "location_name"},
|
||||
{title: translations.final_location, align: "center", field: "final_location_name"},
|
||||
{title: translations.fbo_location, align: "center", field: "fbo_location_name"},
|
||||
{title: translations.created_at, align: "center", field: "created_at"},
|
||||
|
||||
Reference in New Issue
Block a user