document.addEventListener("DOMContentLoaded", function () { var map = { "Actions": "批量操作", "Export": "导出", "Search": "搜索", "Filters": "筛选", "Apply Filter": "应用筛选", "Select operation...": "选择操作...", "Enter value": "输入值", "Showing": "显示第", "items": "条", "prev": "上一页", "next": "下一页", "/ Page": "条/页", "Show": "每页", "Delete selected items": "删除选中项", "View": "查看", "Edit": "编辑", "Delete": "删除", "Save": "保存", "Submit": "提交", "Cancel": "取消", "Back": "返回", "Create": "新建", "Are you sure?": "确定执行此操作吗?", "Go Back": "返回列表", "Continue Editing": "继续编辑", "Save and Add Another": "保存并新增", "Save and Continue Editing": "保存并继续编辑", "Details": "详情", "Logout": "退出登录", "Login": "登录", "Username": "用户名", "Password": "密码", "Login to": "登录", "[Clear]": "[清除]", }; function translateNode(node) { if (node.nodeType === 3) { var text = node.textContent; if (!text || !text.trim()) return; var trimmed = text.trim(); if (map[trimmed]) { node.textContent = text.replace(trimmed, map[trimmed]); } for (var en in map) { if (trimmed.indexOf(en) !== -1) { node.textContent = node.textContent.replace(en, map[en]); } } } } function walk(el) { var children = el.childNodes; for (var i = 0; i < children.length; i++) { var child = children[i]; if (child.nodeType === 3) { translateNode(child); } else if (child.nodeType === 1) { if (child.tagName === "SCRIPT" || child.tagName === "STYLE") continue; if (child.placeholder) { for (var en in map) { if (child.placeholder === en) child.placeholder = map[en]; } } if (child.title) { for (var en2 in map) { if (child.title === en2) child.title = map[en2]; } } walk(child); } } } walk(document.body); // Translate "+ New XXX" buttons document.querySelectorAll("a.btn-primary").forEach(function (a) { var t = a.textContent.trim(); if (t.startsWith("+ New ")) { a.textContent = "+ 新建" + t.replace("+ New ", ""); } }); // Translate "Showing X to Y of Z items" to Chinese format document.querySelectorAll(".card-footer .text-muted").forEach(function (el) { var m = el.textContent.match(/显示第\s*(\d+)\s*to\s*(\d+)\s*of\s*(\d+)\s*条/); if (m) { el.innerHTML = "显示第 " + m[1] + "" + m[2] + " 条,共 " + m[3] + " 条"; } var m2 = el.textContent.match(/Showing\s*(\d+)\s*to\s*(\d+)\s*of\s*(\d+)\s*items/); if (m2) { el.innerHTML = "显示第 " + m2[1] + "" + m2[2] + " 条,共 " + m2[3] + " 条"; } }); // Translate form submit buttons (input[type="submit"] uses value attr) document.querySelectorAll("input[type='submit']").forEach(function (btn) { var v = btn.value; var submitMap = { "Save": "保存", "Submit": "提交", "Create": "新建", "Save and continue editing": "保存并继续编辑", "Save and add another": "保存并新增", "Save as new": "另存为新记录", }; if (submitMap[v]) btn.value = submitMap[v]; }); document.querySelectorAll("button[type='submit']").forEach(function (btn) { var t = btn.textContent.trim(); if (t === "Save") btn.textContent = "保存"; if (t === "Submit") btn.textContent = "提交"; if (t === "Create") btn.textContent = "新建"; if (t === "Apply Filter") btn.textContent = "应用筛选"; }); // Translate "Go Back" / "Continue Editing" links document.querySelectorAll("a.btn").forEach(function (a) { var t = a.textContent.trim(); if (t === "Go Back") a.textContent = "返回列表"; if (t === "Continue Editing") a.textContent = "继续编辑"; if (t === "Go back") a.textContent = "返回列表"; }); // Translate delete modal document.querySelectorAll(".modal-title").forEach(function(el) { if (el.textContent.trim() === "Confirm Delete") el.textContent = "确认删除"; }); document.querySelectorAll(".modal-body").forEach(function(el) { var t = el.textContent.trim(); if (t.indexOf("Are you sure you want to delete") !== -1) { el.innerHTML = el.innerHTML.replace("Are you sure you want to delete", "确定要删除"); el.innerHTML = el.innerHTML.replace("selected items?", "所选项目吗?"); el.innerHTML = el.innerHTML.replace("item?", "吗?"); } }); document.querySelectorAll(".modal-footer .btn-danger").forEach(function(btn) { if (btn.textContent.trim() === "Delete") btn.textContent = "确认删除"; }); document.querySelectorAll(".modal-footer .btn-secondary, .modal-footer [data-bs-dismiss]").forEach(function(btn) { if (btn.textContent.trim() === "Cancel" || btn.textContent.trim() === "Close") btn.textContent = "取消"; }); // Style audit status badges in table cells document.querySelectorAll("td").forEach(function(td) { var t = td.textContent.trim(); var statusColors = { "pending": ["#f59e0b", "rgba(245,158,11,0.12)"], "approved": ["#22c55e", "rgba(34,197,94,0.12)"], "rejected": ["#ef4444", "rgba(239,68,68,0.12)"], "deleted": ["#94a3b8", "rgba(148,163,184,0.12)"], "processing": ["#3b82f6", "rgba(59,130,246,0.12)"], "resolved": ["#22c55e", "rgba(34,197,94,0.12)"], "dismissed": ["#94a3b8", "rgba(148,163,184,0.12)"], "accepted": ["#22c55e", "rgba(34,197,94,0.12)"], }; var statusLabels = { "pending": "待审核", "approved": "已通过", "rejected": "已驳回", "deleted": "已删除", "processing": "处理中", "resolved": "已处理", "dismissed": "已驳回", "accepted": "已采纳", }; if (statusColors[t]) { td.innerHTML = '' + (statusLabels[t] || t) + ''; } }); });