把 shipping 侧 inventory/receipt 词根迁到 onhand/inbound,29 张表与 枚举/权限/前端/i18n 同步改名;在手与入站报表配置及文件改由 freight_rpa 持有,发货与调拨仅按 source_code 消费;ORM 类加 FreightRpa 前缀, 上传动作改为 freight_rpa_upload。含类名与上传动作改名规格文档。 Co-authored-by: Cursor <cursoragent@cursor.com>
443 lines
45 KiB
Python
443 lines
45 KiB
Python
"""
|
||
services/shipping_notice/i18n.py
|
||
|
||
用途:维护发货通知链路的多语言文案与语言解析工具。
|
||
依赖:core.http_context、模块内 `_MESSAGES` 文案字典。
|
||
逻辑:由 parse_summary、field_alignment_summary、workflow 提示文案等上游模块调用本文件输出用户可读消息。
|
||
"""
|
||
|
||
from __future__ import annotations
|
||
|
||
from typing import Any
|
||
|
||
from app.core.http_context import has_http_request, header
|
||
|
||
SUPPORTED_LANGS = ("zh", "en", "th")
|
||
|
||
_MESSAGES: dict[str, dict[str, str]] = {
|
||
"zh": {
|
||
"parse.title": "【发货通知解析确认】任务编号:{task_no}",
|
||
"parse.no_lines": "未解析到订单明细行,请重新上传或重新解析。",
|
||
"parse.low_conf": "解析置信度较低,请重点核对料号、预订单号、数量、单价与金额。",
|
||
"parse.confirm": "请确认以上信息是否正确?",
|
||
"parse.hint": "请核对信息后使用下方按钮继续。",
|
||
"parse.hint_btn": "",
|
||
"align.title": "【库存字段对齐确认 — 确认后再匹配】任务编号:{task_no}",
|
||
"align.match_rule": "匹配规则:{rule}{note}",
|
||
"align.table.sys_field": "系统字段",
|
||
"align.table.inv_col": "库存 Excel 列",
|
||
"align.table.notice_field": "订单字段",
|
||
"align.table.display_only": "unit_price / amount(展示用,不参与匹配)",
|
||
"align.sample.notice": "订单样例:",
|
||
"align.sample.inventory": "库存样例:",
|
||
"align.stats": "统计:{stats}",
|
||
"align.source.llm": "(LLM 推断)",
|
||
"align.source.fallback": "(后端动态兜底)",
|
||
"align.source.other": "({source})",
|
||
"align.confirm": "请确认以上字段对齐是否正确。",
|
||
"align.hint": "请核对字段对齐后使用下方按钮继续。",
|
||
"align.hint_btn": "",
|
||
"common.tips": "提示:",
|
||
"table.field": "字段",
|
||
"table.value": "值",
|
||
"field.po": "采购单号",
|
||
"field.sku": "库存内部料号",
|
||
"field.part_number": "内部料号",
|
||
"field.customer_part_number": "客户料号",
|
||
"field.aws_part_number": "AWS 料号",
|
||
"field.reservation_id": "预订单号",
|
||
"field.qty": "数量",
|
||
"field.unit_price": "单价",
|
||
"field.amount": "金额",
|
||
"field.required_date": "需求日期",
|
||
"field.ship_to": "收货方",
|
||
"field.line_no": "项次",
|
||
"field.available_qty": "可用数量",
|
||
"field.aws_sku": "料号",
|
||
"match.title": "【库存匹配结果】任务编号:{task_no}",
|
||
"match.subtitle": "匹配明细(订单数量 vs 库存可用量)",
|
||
"match.col.order_qty": "订单需求",
|
||
"match.col.inv_qty": "库存可用",
|
||
"match.col.gap": "缺口",
|
||
"match.col.status": "状态",
|
||
"match.status.ok": "✅ 充足",
|
||
"match.status.partial": "⚠️ 部分满足",
|
||
"match.status.shortage": "❌ 不足",
|
||
"match.status.unknown": "未知",
|
||
"match.conclusion.fulfillable": "**结论**:库存充足,可生成发货 Excel 并上传货代系统。",
|
||
"match.conclusion.partial": "**结论**:存在库存缺口,无法发货。请补库存或返回修订后重新匹配,直至全部行满足。",
|
||
"match.conclusion.unfulfillable": "**结论**:库存均不足,无法发货。请补库存或返回修订后重新匹配。",
|
||
"match.conclusion.other": "**结论**:match_status={status}",
|
||
"match.no_lines": "无订单明细,无法比对数量。",
|
||
"workflow.parse.auto_continued": "解析完成,后台已开始继续处理后续步骤。",
|
||
"workflow.parse.check_later": "解析完成,请稍后继续查看任务状态。",
|
||
"workflow.decision.parse_confirmed_running": "发货通知已确认,后台已开始继续处理库存与后续步骤。",
|
||
"workflow.decision.inventory_preparing": "已确认,后台继续处理库存准备步骤。",
|
||
"workflow.decision.fulfillment_running": "发货通知已确认,后台继续处理库存与后续步骤。",
|
||
"workflow.decision.rematch_done": "已重新完成库存匹配。",
|
||
"workflow.decision.mapping_confirmed_running": "库存字段对齐已确认,后台继续处理匹配与后续步骤。",
|
||
"workflow.decision.task_not_found": "未找到明确任务。用户说「确认/重新解析/驳回」时禁止 create_task;多票会话必须带任务编号。",
|
||
"workflow.decision.rejected": "已驳回该发货任务。",
|
||
"workflow.decision.closed": "已关闭该发货任务(可在同一会话重新开新单)。",
|
||
"workflow.decision.shortage_confirm_blocked": "库存不足,无法使用 confirm 整单确认。请 reparse_inventory、rematch 或 reject。",
|
||
"workflow.decision.parse_confirmed_next": "发货通知已确认。请继续在当前任务中补充库存或等待后端继续处理,并稍后刷新任务状态。",
|
||
"workflow.decision.parse_confirmed_wait": "等待后台继续处理或稍后刷新任务状态",
|
||
"workflow.decision.parse_confirmed_manual_next": "ensure_onhand 或 parse_inventory",
|
||
"workflow.decision.matched_confirmed": "已确认,可继续生成 Excel 并上传货代系统。",
|
||
"workflow.decision.confirm_invalid_state": "当前状态无法使用确认。请先完成库存匹配,或选择重新解析订单。",
|
||
"workflow.decision.inventory_cleared": "已清除库存快照。请重新上传或粘贴库存,后续继续在当前任务中处理。",
|
||
"workflow.decision.unknown": "未知 decision: {decision}",
|
||
"workflow.inventory.task_not_found": "未找到任务编号",
|
||
"workflow.inventory.uploaded_file_missing": "未找到已上传的库存文件。请先 POST /tools/upload_inventory_file 上传 Excel。",
|
||
"workflow.inventory.text_too_large": "库存文本过大({chars} 字符,上限 {max_chars})。请勿将 Excel 全文传入 LLM;请用 HTTP 节点调用 POST /tools/upload_inventory_file 上传,再 parse_inventory(use_uploaded_file=true)。",
|
||
"workflow.inventory.upload_then_parse": "upload_inventory_file (multipart) then parse_inventory(use_uploaded_file=true)",
|
||
"workflow.inventory.parse_failed": "未能解析库存明细。大 Excel 请 upload_inventory_file;小表可粘贴;无库存可走 RPA。",
|
||
"workflow.inventory.uploaded_file_missing_short": "未找到已上传的库存文件。请先 upload_inventory_file。",
|
||
"workflow.inventory.parse_failed_detail": "解析库存失败: {error}",
|
||
"workflow.inventory.file_missing": "未收到 file 字段",
|
||
"workflow.inventory.file_type_unsupported": "仅支持 .xls / .xlsx / .csv 库存文件",
|
||
"workflow.inventory.uploading": "正在上传并解析库存文件",
|
||
"workflow.inventory.uploading_detail": "正在处理库存文件 {filename}",
|
||
"workflow.inventory.save_failed": "保存库存文件失败: {error}",
|
||
"workflow.inventory.completed_task_locked": "该任务已完成,不能再重新上传库存。请切换到仍待处理的任务后再上传库存文件。",
|
||
"workflow.inventory.uploaded": "库存文件已上传。",
|
||
"workflow.inventory.ready_for_match": "已有库存快照且字段对齐已确认,可调用 match_inventory。",
|
||
"workflow.inventory.unavailable": "暂无可用库存数据。请重新获取库存,或手动上传货代库存 Excel。",
|
||
"workflow.fulfillment.task_not_found": "未找到任务编号",
|
||
"workflow.fulfillment.match_running": "正在执行库存匹配",
|
||
"workflow.fulfillment.match_running_detail": "按 SKU + Reservation ID 逐行比对需求与库存",
|
||
"workflow.fulfillment.match_progress_detail": "已匹配 {processed}/{total} 行",
|
||
"workflow.fulfillment.match_completed": "库存匹配已完成",
|
||
"workflow.fulfillment.match_completed_ok_detail": "已匹配 {count}/{count} 行,全部订单行库存满足",
|
||
"workflow.fulfillment.match_completed_shortage_detail": "已匹配 {count}/{count} 行,存在缺口,需人工处理",
|
||
"workflow.fulfillment.reservation_required": "当前匹配规则要求发货需求(订单)必须提供 Reservation ID。订单缺少 Reservation ID:{count} 行。请重新解析发货通知后再匹配。",
|
||
"workflow.gate.field_conflict_blocked": "存在 {count} 条未解决的订单字段冲突,请先复核并解决后再继续库存/匹配/导出。",
|
||
"workflow.fulfillment.excel_gate_unmatched": "尚未完成库存匹配。请先上传库存、确认字段对齐并调用 match_inventory。",
|
||
"workflow.fulfillment.inventory_preparation_failed": "库存准备失败。请人工重试或上传库存文件后再继续。",
|
||
"workflow.fulfillment.excel_exists": "发货 Excel 已生成:{file}",
|
||
"workflow.fulfillment.match_first": "match_inventory(须先完成库存上传与字段对齐确认)",
|
||
"workflow.fulfillment.generate_running": "正在生成发货 Excel",
|
||
"workflow.fulfillment.generate_running_detail": "正在按货代模板填充全部应发行",
|
||
"workflow.fulfillment.generate_completed": "发货 Excel 已生成",
|
||
"workflow.fulfillment.generate_done": "已生成发货 Excel:{file}",
|
||
"workflow.fulfillment.manual_already_done": "任务 {task_no} 已标记为完成,无需重复操作。",
|
||
"workflow.fulfillment.manual_confirmed": "已确认手工上传货代完成",
|
||
"workflow.fulfillment.task_completed": "任务已完成",
|
||
"workflow.fulfillment.manual_done_message": "好的,任务 {task_no} 已确认完成,无需再处理。",
|
||
"workflow.fulfillment.upload_running": "RPA 上传进行中(第 {attempt}/{max_attempts} 次)。已等待 {elapsed}s / 超时 {timeout}s。请稍后再试(建议 {remaining}s 后)。",
|
||
"workflow.fulfillment.upload_timeout_error": "RPA 上传超时(>{timeout}s)",
|
||
"workflow.fulfillment.upload_exhausted": "已尝试 {attempts} 次仍无法通过 RPA 上传,请下载 Excel 手工上传。",
|
||
"workflow.fulfillment.upload_triggered_wait": "已触发 RPA 上传货代,等待回执",
|
||
"workflow.fulfillment.upload_triggered_detail": "第 {attempt}/{max_attempts} 次上传尝试",
|
||
"workflow.fulfillment.upload_triggered_message": "已触发 RPA 上传货代(第 {attempt}/{max_attempts} 次)。若 {timeout}s 内无回调,可重试;超过最大次数将转手工上传。",
|
||
"workflow.fulfillment.upload_takeover": "RPA 自动上传失败,请人工接管",
|
||
"workflow.fulfillment.upload_takeover_detail": "请下载 Excel 手工上传后确认完成",
|
||
"workflow.fulfillment.upload_trigger_failed": "RPA 上传目录未配置或触发失败",
|
||
"workflow.fulfillment.upload_takeover_message": "RPA 自动上传失败或未配置。请下载 Excel 在货代系统手工上传,完成后告知我。",
|
||
"workflow.fulfillment.rpa_uploaded": "RPA 已成功上传货代系统",
|
||
"workflow.fulfillment.rpa_uploaded_done": "RPA 已成功上传货代系统,任务已全部处理完毕。",
|
||
"workflow.fulfillment.upload_failed_wait_manual": "货代上传失败,等待人工处理",
|
||
"workflow.fulfillment.upload_failed_detail": "可重试上传或改为手工上传",
|
||
"workflow.fulfillment.upload_unknown_wait_manual": "货代上传结果未知,必须人工核验后再处理",
|
||
"workflow.fulfillment.upload_unknown_detail": "文件可能已提交但未能从页面确认结果;为避免重复上传,请人工核验货代系统后处理。",
|
||
},
|
||
"en": {
|
||
"parse.title": "[Shipping notice parsed] Task: {task_no}",
|
||
"parse.no_lines": "No order lines found. Please re-upload or re-parse.",
|
||
"parse.low_conf": "Low confidence. Please double-check SKU, Qty, Reservation ID, Unit Price and Amount.",
|
||
"parse.confirm": "Please confirm the above information.",
|
||
"parse.hint": "Review the information, then use the buttons below to continue.",
|
||
"parse.hint_btn": "",
|
||
"align.title": "[Inventory mapping confirmation] Task: {task_no}",
|
||
"align.match_rule": "Match rule: {rule}{note}",
|
||
"align.table.sys_field": "System field",
|
||
"align.table.inv_col": "Inventory column",
|
||
"align.table.notice_field": "Order field",
|
||
"align.table.display_only": "unit_price / amount (display only)",
|
||
"align.sample.notice": "Order samples:",
|
||
"align.sample.inventory": "Inventory samples:",
|
||
"align.stats": "Stats: {stats}",
|
||
"align.source.llm": " (LLM)",
|
||
"align.source.fallback": " (backend fallback)",
|
||
"align.source.other": " ({source})",
|
||
"align.confirm": "Please confirm the field alignment above.",
|
||
"align.hint": "Review the field alignment, then use the buttons below to continue.",
|
||
"align.hint_btn": "",
|
||
"common.tips": "Notes:",
|
||
"table.field": "Field",
|
||
"table.value": "Value",
|
||
"field.po": "PO",
|
||
"field.sku": "Inventory SKU",
|
||
"field.part_number": "Part Number",
|
||
"field.customer_part_number": "Customer Part Number",
|
||
"field.aws_part_number": "AWS Part Number",
|
||
"field.reservation_id": "Reservation ID",
|
||
"field.qty": "Qty",
|
||
"field.unit_price": "Unit Price",
|
||
"field.amount": "Amount",
|
||
"field.required_date": "Required date",
|
||
"field.ship_to": "Ship to",
|
||
"field.line_no": "Line",
|
||
"field.available_qty": "Available qty",
|
||
"field.aws_sku": "AWS Sku",
|
||
"match.title": "[Inventory match result] Task: {task_no}",
|
||
"match.subtitle": "Match details (order qty vs inventory available)",
|
||
"match.col.order_qty": "Order qty",
|
||
"match.col.inv_qty": "Available",
|
||
"match.col.gap": "Gap",
|
||
"match.col.status": "Status",
|
||
"match.status.ok": "✅ OK",
|
||
"match.status.partial": "⚠️ Partial",
|
||
"match.status.shortage": "❌ Short",
|
||
"match.status.unknown": "Unknown",
|
||
"match.conclusion.fulfillable": "**Result**: Inventory is sufficient. You may generate the shipment Excel and upload.",
|
||
"match.conclusion.partial": "**Result**: Inventory gap detected. Shipment blocked until all lines are fulfilled. Re-upload inventory or revise mapping, then rematch.",
|
||
"match.conclusion.unfulfillable": "**Result**: Insufficient inventory for all lines. Shipment blocked until inventory is replenished.",
|
||
"match.conclusion.other": "**Result**: match_status={status}",
|
||
"match.no_lines": "No order lines to compare.",
|
||
"workflow.parse.auto_continued": "Parsing is complete. The backend has started the remaining steps.",
|
||
"workflow.parse.check_later": "Parsing is complete. Please check the task status again later.",
|
||
"workflow.decision.parse_confirmed_running": "The shipping notice is confirmed. The backend has started inventory handling and the remaining steps.",
|
||
"workflow.decision.inventory_preparing": "Confirmed. The backend is continuing the inventory preparation steps.",
|
||
"workflow.decision.fulfillment_running": "The shipping notice is confirmed. The backend is continuing inventory handling and the remaining steps.",
|
||
"workflow.decision.rematch_done": "Inventory rematch has been completed.",
|
||
"workflow.decision.mapping_confirmed_running": "The inventory mapping is confirmed. The backend is continuing matching and the remaining steps.",
|
||
"workflow.decision.task_not_found": "No unambiguous task was found. When the user says confirm / re-parse / reject, do not call create_task; multi-task conversations must include the task ID.",
|
||
"workflow.decision.rejected": "The shipping task has been rejected.",
|
||
"workflow.decision.closed": "The shipping task has been closed. You may start a new one in the same conversation.",
|
||
"workflow.decision.shortage_confirm_blocked": "Inventory is insufficient. You cannot use confirm for the whole task. Please use reparse_inventory, rematch, or reject.",
|
||
"workflow.decision.parse_confirmed_next": "The shipping notice is confirmed. Please continue with inventory for the current task or wait for the backend to continue, then refresh the task status later.",
|
||
"workflow.decision.parse_confirmed_wait": "Wait for backend processing or refresh the task status later.",
|
||
"workflow.decision.parse_confirmed_manual_next": "ensure_onhand or parse_inventory",
|
||
"workflow.decision.matched_confirmed": "Confirmed. You may continue to generate the Excel and upload to the freight system.",
|
||
"workflow.decision.confirm_invalid_state": "Confirm cannot be used in the current state. Complete inventory matching first, or reparse the order.",
|
||
"workflow.decision.inventory_cleared": "The inventory snapshot has been cleared. Please re-upload or paste inventory data, then continue in the current task.",
|
||
"workflow.decision.unknown": "Unknown decision: {decision}",
|
||
"workflow.inventory.task_not_found": "Task ID not found.",
|
||
"workflow.inventory.uploaded_file_missing": "No uploaded inventory file was found. Please POST /tools/upload_inventory_file to upload the Excel file first.",
|
||
"workflow.inventory.text_too_large": "The inventory text is too large ({chars} characters, limit {max_chars}). Do not send the full Excel content to the LLM. Please call POST /tools/upload_inventory_file first, then parse_inventory(use_uploaded_file=true).",
|
||
"workflow.inventory.upload_then_parse": "upload_inventory_file (multipart) then parse_inventory(use_uploaded_file=true)",
|
||
"workflow.inventory.parse_failed": "Inventory lines could not be parsed. For large Excel files, use upload_inventory_file; for small tables, paste the content; if inventory is unavailable, use RPA.",
|
||
"workflow.inventory.uploaded_file_missing_short": "No uploaded inventory file was found. Please call upload_inventory_file first.",
|
||
"workflow.inventory.parse_failed_detail": "Failed to parse inventory: {error}",
|
||
"workflow.inventory.file_missing": "The file field was not received.",
|
||
"workflow.inventory.file_type_unsupported": "Only .xls / .xlsx / .csv inventory files are supported.",
|
||
"workflow.inventory.uploading": "Uploading and parsing the inventory file.",
|
||
"workflow.inventory.uploading_detail": "Processing inventory file {filename}",
|
||
"workflow.inventory.save_failed": "Failed to save inventory file: {error}",
|
||
"workflow.inventory.completed_task_locked": "This task is already completed, so inventory cannot be uploaded again. Please switch to a task that still needs processing.",
|
||
"workflow.inventory.uploaded": "The inventory file has been uploaded.",
|
||
"workflow.inventory.ready_for_match": "An inventory snapshot already exists and the field alignment has been confirmed. You may call match_inventory.",
|
||
"workflow.inventory.unavailable": "No usable inventory data is available yet. Please retry the RPA export or upload the freight inventory Excel manually.",
|
||
"workflow.fulfillment.task_not_found": "Task ID not found.",
|
||
"workflow.fulfillment.match_running": "Running inventory matching.",
|
||
"workflow.fulfillment.match_running_detail": "Comparing demand and inventory line by line using SKU + Reservation ID",
|
||
"workflow.fulfillment.match_progress_detail": "Matched {processed}/{total} lines",
|
||
"workflow.fulfillment.match_completed": "Inventory matching is complete.",
|
||
"workflow.fulfillment.match_completed_ok_detail": "Matched {count}/{count} lines. All order lines are fulfillable.",
|
||
"workflow.fulfillment.match_completed_shortage_detail": "Matched {count}/{count} lines. Shortage exists and manual handling is required.",
|
||
"workflow.fulfillment.reservation_required": "The current matching rule requires Reservation ID on the order side. {count} order lines are missing Reservation ID. Please re-parse the shipping notice before matching again.",
|
||
"workflow.gate.field_conflict_blocked": "There are {count} unresolved order field conflicts. Resolve them before inventory, matching, or export.",
|
||
"workflow.fulfillment.excel_gate_unmatched": "Inventory matching is not complete yet. Please upload inventory, confirm field alignment, and call match_inventory first.",
|
||
"workflow.fulfillment.inventory_preparation_failed": "Inventory preparation failed. Retry manually or upload an inventory file before continuing.",
|
||
"workflow.fulfillment.excel_exists": "Shipment Excel already exists: {file}",
|
||
"workflow.fulfillment.match_first": "match_inventory (inventory upload and field alignment confirmation are required first)",
|
||
"workflow.fulfillment.generate_running": "Generating shipment Excel.",
|
||
"workflow.fulfillment.generate_running_detail": "Filling all shippable lines into the freight template",
|
||
"workflow.fulfillment.generate_completed": "Shipment Excel has been generated.",
|
||
"workflow.fulfillment.generate_done": "Shipment Excel generated: {file}",
|
||
"workflow.fulfillment.manual_already_done": "Task {task_no} is already marked complete. No further action is needed.",
|
||
"workflow.fulfillment.manual_confirmed": "Manual freight upload has been confirmed.",
|
||
"workflow.fulfillment.task_completed": "Task completed.",
|
||
"workflow.fulfillment.manual_done_message": "Done. Task {task_no} is confirmed complete. No further action is needed.",
|
||
"workflow.fulfillment.upload_running": "RPA upload is in progress (attempt {attempt}/{max_attempts}). Waited {elapsed}s / timeout {timeout}s. Please try again later (recommended after {remaining}s).",
|
||
"workflow.fulfillment.upload_timeout_error": "RPA upload timed out (>{timeout}s)",
|
||
"workflow.fulfillment.upload_exhausted": "RPA upload failed after {attempts} attempts. Please download the Excel and upload it manually.",
|
||
"workflow.fulfillment.upload_triggered_wait": "RPA upload to freight has been triggered. Waiting for callback.",
|
||
"workflow.fulfillment.upload_triggered_detail": "Upload attempt {attempt}/{max_attempts}",
|
||
"workflow.fulfillment.upload_triggered_message": "RPA upload to freight has been triggered (attempt {attempt}/{max_attempts}). If no callback arrives within {timeout}s, you may retry. After the max attempts, the flow will fall back to manual upload.",
|
||
"workflow.fulfillment.upload_takeover": "RPA auto-upload failed. Manual takeover is required.",
|
||
"workflow.fulfillment.upload_takeover_detail": "Please download the Excel, upload it manually, then confirm completion.",
|
||
"workflow.fulfillment.upload_trigger_failed": "The RPA upload directory is not configured or triggering failed.",
|
||
"workflow.fulfillment.upload_takeover_message": "RPA auto-upload failed or is not configured. Please download the Excel and upload it manually in the freight system, then let me know when it is done.",
|
||
"workflow.fulfillment.rpa_uploaded": "RPA has uploaded to the freight system successfully.",
|
||
"workflow.fulfillment.rpa_uploaded_done": "RPA uploaded to the freight system successfully. The task is fully completed.",
|
||
"workflow.fulfillment.upload_failed_wait_manual": "Freight upload failed. Waiting for manual handling.",
|
||
"workflow.fulfillment.upload_failed_detail": "You may retry the upload or switch to manual upload.",
|
||
"workflow.fulfillment.upload_unknown_wait_manual": "Freight upload result is unknown. Manual verification is required.",
|
||
"workflow.fulfillment.upload_unknown_detail": "The file may have been submitted but the result could not be confirmed from the page. To avoid a duplicate upload, please verify the freight system manually.",
|
||
},
|
||
"th": {
|
||
"parse.title": "【ยืนยันการแยกใบแจ้งส่งสินค้า】งาน: {task_no}",
|
||
"parse.no_lines": "ไม่พบบรรทัดรายการสั่งซื้อ กรุณาอัปโหลดใหม่หรือแยกใหม่อีกครั้ง",
|
||
"parse.low_conf": "ความมั่นใจต่ำ กรุณาตรวจสอบ SKU, จำนวน, Reservation ID, ราคาต่อหน่วย และจำนวนเงิน",
|
||
"parse.confirm": "กรุณายืนยันว่าข้อมูลด้านบนถูกต้องหรือไม่",
|
||
"parse.hint": "ตรวจสอบข้อมูลแล้วใช้ปุ่มด้านล่างเพื่อดำเนินการต่อ",
|
||
"parse.hint_btn": "",
|
||
"align.title": "【ยืนยันการจับคู่คอลัมน์สต็อก】งาน: {task_no}",
|
||
"align.match_rule": "กฎการจับคู่: {rule}{note}",
|
||
"align.table.sys_field": "ฟิลด์ระบบ",
|
||
"align.table.inv_col": "คอลัมน์สต็อก",
|
||
"align.table.notice_field": "ฟิลด์คำสั่งซื้อ",
|
||
"align.table.display_only": "unit_price / amount (แสดงผลเท่านั้น)",
|
||
"align.sample.notice": "ตัวอย่างคำสั่งซื้อ:",
|
||
"align.sample.inventory": "ตัวอย่างสต็อก:",
|
||
"align.stats": "สถิติ: {stats}",
|
||
"align.source.llm": " (LLM)",
|
||
"align.source.fallback": " (สำรองโดยระบบ)",
|
||
"align.source.other": " ({source})",
|
||
"align.confirm": "กรุณายืนยันว่าการจับคู่ฟิลด์ด้านบนถูกต้อง",
|
||
"align.hint": "ตรวจสอบการจับคู่ฟิลด์แล้วใช้ปุ่มด้านล่างเพื่อดำเนินการต่อ",
|
||
"align.hint_btn": "",
|
||
"common.tips": "หมายเหตุ:",
|
||
"table.field": "ฟิลด์",
|
||
"table.value": "ค่า",
|
||
"field.po": "PO",
|
||
"field.sku": "SKU สต็อก",
|
||
"field.part_number": "หมายเลขชิ้นส่วน",
|
||
"field.customer_part_number": "หมายเลขชิ้นส่วนลูกค้า",
|
||
"field.aws_part_number": "หมายเลขชิ้นส่วน AWS",
|
||
"field.reservation_id": "Reservation ID",
|
||
"field.qty": "จำนวน",
|
||
"field.unit_price": "ราคาต่อหน่วย",
|
||
"field.amount": "จำนวนเงิน",
|
||
"field.required_date": "วันที่ต้องการ",
|
||
"field.ship_to": "ผู้รับ",
|
||
"field.line_no": "รายการ",
|
||
"field.available_qty": "จำนวนคงเหลือ",
|
||
"field.aws_sku": "AWS Sku",
|
||
"match.title": "【ผลการจับคู่สต็อก】งาน: {task_no}",
|
||
"match.subtitle": "รายละเอียดการจับคู่ (จำนวนสั่งซื้อ vs สต็อกคงเหลือ)",
|
||
"match.col.order_qty": "จำนวนสั่ง",
|
||
"match.col.inv_qty": "สต็อกคงเหลือ",
|
||
"match.col.gap": "ส่วนต่าง",
|
||
"match.col.status": "สถานะ",
|
||
"match.status.ok": "✅ เพียงพอ",
|
||
"match.status.partial": "⚠️ บางส่วน",
|
||
"match.status.shortage": "❌ ไม่พอ",
|
||
"match.status.unknown": "ไม่ทราบ",
|
||
"match.conclusion.fulfillable": "**สรุป**: สต็อกเพียงพอ สามารถสร้าง Excel และอัปโหลดได้",
|
||
"match.conclusion.partial": "**สรุป**: มีส่วนต่างสต็อก ไม่สามารถจัดส่งได้ กรุณาเติมสต็อกหรือแก้ไขแล้วจับคู่ใหม่จนกว่าทุกรายการจะครบ",
|
||
"match.conclusion.unfulfillable": "**สรุป**: สต็อกไม่เพียงพอทั้งหมด ไม่สามารถจัดส่งได้ กรุณาเติมสต็อกหรือแก้ไขแล้วจับคู่ใหม่",
|
||
"match.conclusion.other": "**สรุป**: match_status={status}",
|
||
"match.no_lines": "ไม่มีรายการสั่งซื้อสำหรับเปรียบเทียบ",
|
||
"workflow.parse.auto_continued": "แยกข้อมูลเสร็จแล้ว ระบบหลังบ้านได้เริ่มดำเนินขั้นตอนถัดไปต่อแล้ว",
|
||
"workflow.parse.check_later": "แยกข้อมูลเสร็จแล้ว กรุณากลับมาตรวจสอบสถานะงานอีกครั้งภายหลัง",
|
||
"workflow.decision.parse_confirmed_running": "ยืนยันใบแจ้งส่งสินค้าแล้ว ระบบหลังบ้านได้เริ่มจัดการสต็อกและขั้นตอนถัดไปต่อแล้ว",
|
||
"workflow.decision.inventory_preparing": "ยืนยันแล้ว ระบบหลังบ้านกำลังดำเนินขั้นตอนเตรียมสต็อกต่อ",
|
||
"workflow.decision.fulfillment_running": "ยืนยันใบแจ้งส่งสินค้าแล้ว ระบบหลังบ้านกำลังดำเนินการสต็อกและขั้นตอนถัดไปต่อ",
|
||
"workflow.decision.rematch_done": "จับคู่สต็อกใหม่เสร็จแล้ว",
|
||
"workflow.decision.mapping_confirmed_running": "ยืนยันการจับคู่คอลัมน์สต็อกแล้ว ระบบหลังบ้านกำลังดำเนินการจับคู่และขั้นตอนถัดไปต่อ",
|
||
"workflow.decision.task_not_found": "ไม่พบงานที่ระบุได้ชัดเจน เมื่อผู้ใช้พูดว่ายืนยัน / แยกใหม่ / ปฏิเสธ ห้ามเรียก create_task และหากมีหลายงานต้องส่ง task ID มาด้วย",
|
||
"workflow.decision.rejected": "ปฏิเสธงานจัดส่งนี้แล้ว",
|
||
"workflow.decision.closed": "ปิดงานจัดส่งนี้แล้ว และสามารถเริ่มงานใหม่ในบทสนทนาเดิมได้",
|
||
"workflow.decision.shortage_confirm_blocked": "สต็อกไม่เพียงพอ จึงไม่สามารถใช้ confirm เพื่อยืนยันทั้งงานได้ โปรดใช้ reparse_inventory, rematch หรือ reject",
|
||
"workflow.decision.parse_confirmed_next": "ยืนยันใบแจ้งส่งสินค้าแล้ว โปรดดำเนินการเรื่องสต็อกในงานปัจจุบันต่อ หรือรอให้ระบบหลังบ้านทำต่อ แล้วค่อยรีเฟรชสถานะงาน",
|
||
"workflow.decision.parse_confirmed_wait": "รอให้ระบบหลังบ้านดำเนินการต่อ หรือกลับมาตรวจสอบสถานะงานภายหลัง",
|
||
"workflow.decision.parse_confirmed_manual_next": "ensure_onhand หรือ parse_inventory",
|
||
"workflow.decision.matched_confirmed": "ยืนยันแล้ว สามารถดำเนินการสร้างไฟล์ Excel และอัปโหลดไปยังระบบขนส่งต่อได้",
|
||
"workflow.decision.confirm_invalid_state": "ไม่สามารถยืนยันในสถานะปัจจุบันได้ โปรดจับคู่สต็อกให้เสร็จก่อน หรือแยกวิเคราะห์คำสั่งซื้อใหม่",
|
||
"workflow.decision.inventory_cleared": "ล้าง snapshot สต็อกแล้ว โปรดอัปโหลดใหม่หรือวางข้อมูลสต็อก แล้วดำเนินการต่อในงานปัจจุบัน",
|
||
"workflow.decision.unknown": "ไม่รู้จัก decision: {decision}",
|
||
"workflow.inventory.task_not_found": "ไม่พบรหัสงาน",
|
||
"workflow.inventory.uploaded_file_missing": "ไม่พบไฟล์สต็อกที่อัปโหลดไว้ โปรดอัปโหลดไฟล์ Excel ผ่าน POST /tools/upload_inventory_file ก่อน",
|
||
"workflow.inventory.text_too_large": "ข้อความสต็อกมีขนาดใหญ่เกินไป ({chars} ตัวอักษร, จำกัด {max_chars}) โปรดอย่าส่งเนื้อหา Excel ทั้งหมดเข้า LLM ให้เรียก POST /tools/upload_inventory_file ก่อน แล้วจึงใช้ parse_inventory(use_uploaded_file=true)",
|
||
"workflow.inventory.upload_then_parse": "upload_inventory_file (multipart) then parse_inventory(use_uploaded_file=true)",
|
||
"workflow.inventory.parse_failed": "ไม่สามารถแยกรายการสต็อกได้ สำหรับไฟล์ Excel ขนาดใหญ่ให้ใช้ upload_inventory_file; สำหรับตารางเล็กสามารถวางข้อความได้; หากไม่มีสต็อกให้ใช้ RPA",
|
||
"workflow.inventory.uploaded_file_missing_short": "ไม่พบไฟล์สต็อกที่อัปโหลดไว้ โปรดเรียก upload_inventory_file ก่อน",
|
||
"workflow.inventory.parse_failed_detail": "解析库存失败: {error}",
|
||
"workflow.inventory.file_missing": "ไม่ได้รับฟิลด์ file",
|
||
"workflow.inventory.file_type_unsupported": "รองรับเฉพาะไฟล์สต็อก .xls / .xlsx / .csv",
|
||
"workflow.inventory.uploading": "กำลังอัปโหลดและ解析ไฟล์สต็อก",
|
||
"workflow.inventory.uploading_detail": "กำลังประมวลผลไฟล์สต็อก {filename}",
|
||
"workflow.inventory.save_failed": "บันทึกไฟล์สต็อกไม่สำเร็จ: {error}",
|
||
"workflow.inventory.completed_task_locked": "งานนี้เสร็จสิ้นแล้ว จึงไม่สามารถอัปโหลดสต็อกซ้ำได้ โปรดสลับไปยังงานที่ยังต้องดำเนินการ",
|
||
"workflow.inventory.uploaded": "อัปโหลดไฟล์สต็อกแล้ว",
|
||
"workflow.inventory.ready_for_match": "มี inventory snapshot อยู่แล้วและยืนยันการจับคู่คอลัมน์แล้ว สามารถเรียก match_inventory ได้",
|
||
"workflow.inventory.unavailable": "ยังไม่มีข้อมูลสต็อกที่ใช้งานได้ โปรดลองส่งออกผ่าน RPA ใหม่ หรืออัปโหลดไฟล์ Excel สต็อกของผู้ให้บริการขนส่งด้วยตนเอง",
|
||
"workflow.fulfillment.task_not_found": "ไม่พบรหัสงาน",
|
||
"workflow.fulfillment.match_running": "กำลังจับคู่สต็อก",
|
||
"workflow.fulfillment.match_running_detail": "กำลังเทียบความต้องการกับสต็อกทีละบรรทัดด้วย SKU + Reservation ID",
|
||
"workflow.fulfillment.match_progress_detail": "จับคู่แล้ว {processed}/{total} รายการ",
|
||
"workflow.fulfillment.match_completed": "จับคู่สต็อกเสร็จแล้ว",
|
||
"workflow.fulfillment.match_completed_ok_detail": "จับคู่แล้ว {count}/{count} รายการ และทุกรายการมีสต็อกเพียงพอ",
|
||
"workflow.fulfillment.match_completed_shortage_detail": "จับคู่แล้ว {count}/{count} รายการ แต่ยังมีของขาดและต้องให้คนจัดการต่อ",
|
||
"workflow.fulfillment.reservation_required": "กฎการจับคู่ปัจจุบันกำหนดให้ฝั่งคำสั่งซื้อมี Reservation ID ขณะนี้มี {count} รายการที่ขาด Reservation ID โปรดแยกใบแจ้งส่งสินค้าใหม่ก่อนแล้วค่อยจับคู่",
|
||
"workflow.gate.field_conflict_blocked": "มีข้อขัดแย้งของฟิลด์คำสั่งซื้อที่ยังไม่แก้ {count} รายการ กรุณาตรวจสอบก่อนดำเนินการสต็อก/จับคู่/ส่งออก",
|
||
"workflow.fulfillment.excel_gate_unmatched": "ยังจับคู่สต็อกไม่เสร็จ โปรดอัปโหลดสต็อก ยืนยันการจับคู่คอลัมน์ แล้วเรียก match_inventory ก่อน",
|
||
"workflow.fulfillment.inventory_preparation_failed": "การเตรียมสต็อกล้มเหลว โปรดลองด้วยตนเองหรืออัปโหลดไฟล์สต็อกก่อนดำเนินการต่อ",
|
||
"workflow.fulfillment.excel_exists": "สร้างไฟล์ Shipment Excel แล้ว: {file}",
|
||
"workflow.fulfillment.match_first": "match_inventory (ต้องอัปโหลดสต็อกและยืนยันการจับคู่คอลัมน์ก่อน)",
|
||
"workflow.fulfillment.generate_running": "กำลังสร้าง Shipment Excel",
|
||
"workflow.fulfillment.generate_running_detail": "กำลังเติมรายการที่สามารถจัดส่งได้ลงในเทมเพลตของผู้ให้บริการขนส่ง",
|
||
"workflow.fulfillment.generate_completed": "สร้าง Shipment Excel แล้ว",
|
||
"workflow.fulfillment.generate_done": "สร้าง Shipment Excel แล้ว: {file}",
|
||
"workflow.fulfillment.manual_already_done": "งาน {task_no} ถูกทำเครื่องหมายว่าเสร็จแล้ว จึงไม่ต้องดำเนินการซ้ำ",
|
||
"workflow.fulfillment.manual_confirmed": "ยืนยันการอัปโหลดเข้าระบบขนส่งด้วยตนเองแล้ว",
|
||
"workflow.fulfillment.task_completed": "งานเสร็จสิ้นแล้ว",
|
||
"workflow.fulfillment.manual_done_message": "เรียบร้อย งาน {task_no} ยืนยันว่าเสร็จแล้ว ไม่ต้องดำเนินการต่อ",
|
||
"workflow.fulfillment.upload_running": "RPA กำลังอัปโหลดอยู่ (ครั้งที่ {attempt}/{max_attempts}) รอแล้ว {elapsed}s / หมดเวลา {timeout}s โปรดลองอีกครั้งภายหลัง (แนะนำหลัง {remaining}s)",
|
||
"workflow.fulfillment.upload_timeout_error": "RPA อัปโหลดหมดเวลา (>{timeout}s)",
|
||
"workflow.fulfillment.upload_exhausted": "พยายามอัปโหลดผ่าน RPA มาแล้ว {attempts} ครั้งแต่ยังไม่สำเร็จ โปรดดาวน์โหลด Excel แล้วอัปโหลดด้วยตนเอง",
|
||
"workflow.fulfillment.upload_triggered_wait": "ทริกเกอร์ RPA ให้อัปโหลดเข้าระบบขนส่งแล้ว กำลังรอผลตอบกลับ",
|
||
"workflow.fulfillment.upload_triggered_detail": "พยายามอัปโหลดครั้งที่ {attempt}/{max_attempts}",
|
||
"workflow.fulfillment.upload_triggered_message": "ทริกเกอร์ RPA ให้อัปโหลดเข้าระบบขนส่งแล้ว (ครั้งที่ {attempt}/{max_attempts}) หากไม่มี callback ภายใน {timeout}s สามารถลองใหม่ได้ และถ้าเกินจำนวนครั้งสูงสุดจะเปลี่ยนเป็นอัปโหลดด้วยตนเอง",
|
||
"workflow.fulfillment.upload_takeover": "RPA อัปโหลดอัตโนมัติไม่สำเร็จ ต้องให้คนรับช่วงต่อ",
|
||
"workflow.fulfillment.upload_takeover_detail": "โปรดดาวน์โหลด Excel แล้วอัปโหลดด้วยตนเอง จากนั้นค่อยยืนยันว่าเสร็จแล้ว",
|
||
"workflow.fulfillment.upload_trigger_failed": "ไม่ได้ตั้งค่าไดเรกทอรีอัปโหลดของ RPA หรือการทริกเกอร์ล้มเหลว",
|
||
"workflow.fulfillment.upload_takeover_message": "RPA อัปโหลดอัตโนมัติล้มเหลวหรือยังไม่ได้ตั้งค่า โปรดดาวน์โหลด Excel แล้วอัปโหลดด้วยตนเองในระบบขนส่ง จากนั้นแจ้งฉันเมื่อเสร็จแล้ว",
|
||
"workflow.fulfillment.rpa_uploaded": "RPA อัปโหลดเข้าระบบขนส่งสำเร็จแล้ว",
|
||
"workflow.fulfillment.rpa_uploaded_done": "RPA อัปโหลดเข้าระบบขนส่งสำเร็จแล้ว และงานเสร็จสมบูรณ์",
|
||
"workflow.fulfillment.upload_failed_wait_manual": "อัปโหลดเข้าระบบขนส่งล้มเหลว กำลังรอให้คนจัดการต่อ",
|
||
"workflow.fulfillment.upload_failed_detail": "สามารถลองอัปโหลดใหม่หรือเปลี่ยนเป็นอัปโหลดด้วยตนเองได้",
|
||
"workflow.fulfillment.upload_unknown_wait_manual": "ผลการอัปโหลดขนส่งไม่ทราบแน่ชัด ต้องให้คนตรวจสอบก่อนดำเนินการ",
|
||
"workflow.fulfillment.upload_unknown_detail": "ไฟล์อาจถูกส่งไปแล้วแต่ไม่สามารถยืนยันผลจากหน้าเว็บได้ เพื่อหลีกเลี่ยงการอัปโหลดซ้ำ กรุณาตรวจสอบระบบขนส่งด้วยตนเอง",
|
||
},
|
||
}
|
||
|
||
|
||
def normalize_lang(raw: Any) -> str:
|
||
"""将 lang/locale 别名规范化为 zh / en / th。"""
|
||
text = str(raw or "").strip().lower()
|
||
if not text:
|
||
return "zh"
|
||
if text in {"zh-cn", "zh_hans", "zh-hans", "cn", "zh"}:
|
||
return "zh"
|
||
if text in {"en-us", "en_us", "en"}:
|
||
return "en"
|
||
if text in {"th-th", "th_th", "th"}:
|
||
return "th"
|
||
for prefix in SUPPORTED_LANGS:
|
||
if text.startswith(prefix):
|
||
return prefix
|
||
return "zh"
|
||
|
||
|
||
def resolve_lang(payload: dict[str, Any] | None = None) -> str:
|
||
"""从 payload 或 HTTP 请求头(X-Lang / Accept-Language)解析语言,默认 zh。"""
|
||
if isinstance(payload, dict):
|
||
for key in ("lang", "locale", "language"):
|
||
if key in payload:
|
||
val = str(payload.get(key) or "").strip()
|
||
if val:
|
||
return normalize_lang(val)
|
||
|
||
if has_http_request():
|
||
hdr = header("X-Lang").strip()
|
||
if hdr:
|
||
return normalize_lang(hdr)
|
||
accept = header("Accept-Language").strip()
|
||
if accept:
|
||
return normalize_lang(accept.split(",")[0].strip())
|
||
return "zh"
|
||
|
||
|
||
def t(key: str, *, lang: str | None = None) -> str:
|
||
"""按语言键查找 i18n 文案;未命中时回退 zh 或原 key。"""
|
||
resolved = normalize_lang(lang) if lang else "zh"
|
||
if key in _MESSAGES.get(resolved, {}):
|
||
return _MESSAGES[resolved][key]
|
||
if key in _MESSAGES["zh"]:
|
||
return _MESSAGES["zh"][key]
|
||
return key
|