Files
syops/backend/app/services/shipping_notice/i18n.py
T
hugo 1fc9976ca3 feat(chat): 更新发货任务处理逻辑和界面文本
- 移除不必要的状态引用
- 更新上传处理提示文本,使用国际化支持
- 扩展发货任务摘要接口,增加错误信息和短缺信息
- 更新多语言支持的文本,改善用户体验
- 增加批次工作区的汇总信息和操作提示
2026-06-29 14:43:27 +08:00

466 lines
51 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
services/shipping_notice/i18n.py
用途:维护发货通知链路的多语言文案与语言解析工具。
依赖:Flask request 上下文、模块内 `_MESSAGES` 文案字典。
逻辑:由 parse_summary、field_alignment_summary、workflow 提示文案等上游模块调用本文件输出用户可读消息。
"""
from __future__ import annotations
from typing import Any
from flask import has_request_context, request
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.reservation_id": "预订单号",
"field.qty": "数量",
"field.unit_price": "单价",
"field.amount": "金额",
"field.required_date": "需求日期",
"field.ship_to": "收货方",
"field.vendor_part_number": "供应商料号",
"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_running": "已提交重新匹配请求,后台继续处理。",
"workflow.decision.mapping_confirmed_running": "库存字段对齐已确认,后台继续处理匹配与后续步骤。",
"workflow.decision.task_not_found": "未找到任务。用户说「确认/重新解析/驳回」时禁止 create_task。请先 get_task_status(conversation_id=...) 或 submit_decision 带上任务编号。",
"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_inventory 或 parse_inventory",
"workflow.decision.matched_confirmed": "已确认,可继续生成 Excel 并上传货代系统。",
"workflow.decision.confirm_invalid_state": "当前状态无法使用 confirm。请先完成库存匹配,或使用 confirm_inventory_mapping / reparse。",
"workflow.decision.mapping_not_needed": "当前无需确认库存字段对齐。",
"workflow.decision.mapping_missing_reservation_warning": "库存表必须包含 Reservation ID 列标题(该列允许为空值)。请改用「更正映射」重新选择 Reservation ID 对应的列,或重新上传包含该列的库存 Excel。",
"workflow.decision.mapping_correction_invalid_state": "当前不在库存字段对齐确认步骤,无法更正映射。",
"workflow.decision.read_inventory_preview_failed": "读取库存表头失败: {error}",
"workflow.decision.mapping_preview_note": "无已上传 Excel;请粘贴库存小表或重新上传后 apply_inventory_mapping / parse_inventory。",
"workflow.decision.mapping_correction_needed": "已回到列映射步骤。请根据 schema_preview 提供新的 map_json,再调用 apply_inventory_mapping。",
"workflow.decision.mapping_correction_next": "apply_inventory_mapping(map_json=...)",
"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.preview_read_failed": "读取库存表头失败: {error}",
"workflow.inventory.preview_ready": "已读取库存表头与样例行。请根据 schema_preview 推断列映射,调用 apply_inventory_mapping(map_json=...)。",
"workflow.inventory.preview_next": "根据 data.schema_preview.headers 与 sample_rows 推断 JSON:{\"sku\":\"<列名>\",\"reservation_id\":\"<列名>\",\"available_qty\":\"<列名>\"},再调用 apply_inventory_mapping",
"workflow.inventory.uploaded_file_missing_short": "未找到已上传的库存文件。请先 upload_inventory_file。",
"workflow.inventory.mapping_invalid": "map_json 无效或不完整。需要提供 {\"sku\":\"列名\",\"reservation_id\":\"列名\",\"available_qty\":\"列名\"}。(库存的 Reservation ID 列允许为空值,但必须有该列标题)",
"workflow.inventory.mapping_header_mismatch": "列映射与 Excel 表头不匹配。(表头在第 {row} 行){errors} 请根据 schema_preview.headers 重新调用 apply_inventory_mapping。",
"workflow.inventory.parse_failed_detail": "解析库存失败: {error}",
"workflow.inventory.file_missing": "未收到 file 字段",
"workflow.inventory.file_type_unsupported": "仅支持 .xlsx / .xls / .csv 库存文件",
"workflow.inventory.uploading": "正在上传并解析库存文件",
"workflow.inventory.uploading_detail": "正在处理库存文件 {filename}",
"workflow.inventory.save_failed": "保存库存文件失败: {error}",
"workflow.inventory.completed_task_locked": "该任务已完成,不能再重新上传库存。请切换到仍待处理的任务后再上传库存文件。",
"workflow.inventory.uploaded": "库存文件已上传。",
"workflow.inventory.uploaded_suggested_complete": " suggested_mapping 已完整,画布可直通 apply_inventory_mapping(无需 LLM)。",
"workflow.inventory.uploaded_need_llm": " 请由画布 LLM 推断列映射后 apply_inventory_mapping。",
"workflow.inventory.apply_mapping_next": "apply_inventory_mapping(map_json=...)",
"workflow.inventory.ready_for_match": "已有库存快照且字段对齐已确认,可调用 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。订单缺少 Reservation ID:{count} 行。请重新解析发货通知后再匹配。",
"workflow.fulfillment.excel_gate_unmatched": "尚未完成库存匹配。请先上传库存、确认字段对齐并调用 match_inventory。",
"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": "可重试上传或改为手工上传",
},
"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": "SKU",
"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.vendor_part_number": "Vendor PN",
"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_running": "The rematch request has been submitted. The backend is continuing processing.",
"workflow.decision.mapping_confirmed_running": "The inventory mapping is confirmed. The backend is continuing matching and the remaining steps.",
"workflow.decision.task_not_found": "Task not found. When the user says confirm / re-parse / reject, do not call create_task. Please call get_task_status(conversation_id=...) first or pass the task ID to submit_decision.",
"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_inventory 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. Please complete inventory matching first, or use confirm_inventory_mapping / reparse.",
"workflow.decision.mapping_not_needed": "Inventory field alignment confirmation is not needed right now.",
"workflow.decision.mapping_missing_reservation_warning": "The inventory sheet must contain a Reservation ID column header (the values in that column may be empty). Please use Fix Mapping to choose the Reservation ID column again, or re-upload an inventory Excel that contains that column.",
"workflow.decision.mapping_correction_invalid_state": "The task is not currently in the inventory field alignment confirmation step, so the mapping cannot be corrected.",
"workflow.decision.read_inventory_preview_failed": "Failed to read inventory headers: {error}",
"workflow.decision.mapping_preview_note": "No uploaded Excel was found. Please paste a small inventory table or re-upload, then call apply_inventory_mapping / parse_inventory.",
"workflow.decision.mapping_correction_needed": "The task has returned to the mapping step. Please provide a new map_json based on schema_preview, then call apply_inventory_mapping.",
"workflow.decision.mapping_correction_next": "apply_inventory_mapping(map_json=...)",
"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.preview_read_failed": "Failed to read inventory headers: {error}",
"workflow.inventory.preview_ready": "Inventory headers and sample rows have been loaded. Please infer the column mapping from schema_preview and call apply_inventory_mapping(map_json=...).",
"workflow.inventory.preview_next": "Infer JSON from data.schema_preview.headers and sample_rows: {\"sku\":\"<column>\",\"reservation_id\":\"<column>\",\"available_qty\":\"<column>\"}, then call apply_inventory_mapping",
"workflow.inventory.uploaded_file_missing_short": "No uploaded inventory file was found. Please call upload_inventory_file first.",
"workflow.inventory.mapping_invalid": "map_json is invalid or incomplete. You must provide {\"sku\":\"column\",\"reservation_id\":\"column\",\"available_qty\":\"column\"}. The Reservation ID column may contain empty values, but the column header itself must exist.",
"workflow.inventory.mapping_header_mismatch": "The column mapping does not match the Excel headers. (The header row is row {row}) {errors} Please call apply_inventory_mapping again using schema_preview.headers.",
"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 .xlsx / .xls / .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.uploaded_suggested_complete": " suggested_mapping is complete, so the canvas can call apply_inventory_mapping directly without using the LLM.",
"workflow.inventory.uploaded_need_llm": " Please let the canvas LLM infer the column mapping and then call apply_inventory_mapping.",
"workflow.inventory.apply_mapping_next": "apply_inventory_mapping(map_json=...)",
"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.fulfillment.excel_gate_unmatched": "Inventory matching is not complete yet. Please upload inventory, confirm field alignment, and call match_inventory first.",
"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.",
},
"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.reservation_id": "Reservation ID",
"field.qty": "จำนวน",
"field.unit_price": "ราคาต่อหน่วย",
"field.amount": "จำนวนเงิน",
"field.required_date": "วันที่ต้องการ",
"field.ship_to": "ผู้รับ",
"field.vendor_part_number": "หมายเลขชิ้นส่วนผู้ขาย",
"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_running": "ส่งคำขอจับคู่ใหม่แล้ว ระบบหลังบ้านกำลังดำเนินการต่อ",
"workflow.decision.mapping_confirmed_running": "ยืนยันการจับคู่คอลัมน์สต็อกแล้ว ระบบหลังบ้านกำลังดำเนินการจับคู่และขั้นตอนถัดไปต่อ",
"workflow.decision.task_not_found": "ไม่พบงาน เมื่อผู้ใช้พูดว่ายืนยัน / แยกใหม่ / ปฏิเสธ ห้ามเรียก create_task โปรดเรียก get_task_status(conversation_id=...) ก่อน หรือส่ง task ID ให้ submit_decision",
"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_inventory หรือ parse_inventory",
"workflow.decision.matched_confirmed": "ยืนยันแล้ว สามารถดำเนินการสร้างไฟล์ Excel และอัปโหลดไปยังระบบขนส่งต่อได้",
"workflow.decision.confirm_invalid_state": "ไม่สามารถใช้ confirm ในสถานะปัจจุบันได้ โปรดทำ inventory matching ให้เสร็จก่อน หรือใช้ confirm_inventory_mapping / reparse",
"workflow.decision.mapping_not_needed": "ขณะนี้ยังไม่ต้องยืนยันการจับคู่คอลัมน์สต็อก",
"workflow.decision.mapping_missing_reservation_warning": "ไฟล์สต็อกต้องมีหัวคอลัมน์ Reservation ID (ค่าภายในคอลัมน์นี้สามารถเว้นว่างได้) โปรดใช้ Fix Mapping เพื่อเลือกคอลัมน์ Reservation ID ใหม่ หรืออัปโหลดไฟล์ Excel สต็อกที่มีคอลัมน์นี้อีกครั้ง",
"workflow.decision.mapping_correction_invalid_state": "ขณะนี้งานไม่ได้อยู่ในขั้นตอนยืนยันการจับคู่คอลัมน์สต็อก จึงไม่สามารถแก้ไข mapping ได้",
"workflow.decision.read_inventory_preview_failed": "อ่านหัวตารางสต็อกไม่สำเร็จ: {error}",
"workflow.decision.mapping_preview_note": "ไม่พบไฟล์ Excel ที่อัปโหลดไว้ โปรดวางตารางสต็อกขนาดเล็กหรืออัปโหลดใหม่ แล้วจึงเรียก apply_inventory_mapping / parse_inventory",
"workflow.decision.mapping_correction_needed": "งานได้ย้อนกลับมาที่ขั้นตอนจับคู่คอลัมน์แล้ว โปรดส่ง map_json ใหม่ตาม schema_preview แล้วเรียก apply_inventory_mapping",
"workflow.decision.mapping_correction_next": "apply_inventory_mapping(map_json=...)",
"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.preview_read_failed": "อ่านหัวตารางสต็อกไม่สำเร็จ: {error}",
"workflow.inventory.preview_ready": "อ่านหัวตารางและแถวตัวอย่างของสต็อกแล้ว โปรดอนุมานการจับคู่คอลัมน์จาก schema_preview แล้วเรียก apply_inventory_mapping(map_json=...)",
"workflow.inventory.preview_next": "อนุมาน JSON จาก data.schema_preview.headers และ sample_rows: {\"sku\":\"<คอลัมน์>\",\"reservation_id\":\"<คอลัมน์>\",\"available_qty\":\"<คอลัมน์>\"} แล้วจึงเรียก apply_inventory_mapping",
"workflow.inventory.uploaded_file_missing_short": "ไม่พบไฟล์สต็อกที่อัปโหลดไว้ โปรดเรียก upload_inventory_file ก่อน",
"workflow.inventory.mapping_invalid": "map_json ไม่ถูกต้องหรือไม่ครบ ต้องระบุ {\"sku\":\"ชื่อคอลัมน์\",\"reservation_id\":\"ชื่อคอลัมน์\",\"available_qty\":\"ชื่อคอลัมน์\"} โดยคอลัมน์ Reservation ID สามารถมีค่าว่างได้ แต่ต้องมีหัวคอลัมน์นี้",
"workflow.inventory.mapping_header_mismatch": "การจับคู่คอลัมน์ไม่ตรงกับหัวตาราง Excel (หัวตารางอยู่ที่แถว {row}) {errors} โปรดเรียก apply_inventory_mapping ใหม่โดยอ้างอิง schema_preview.headers",
"workflow.inventory.parse_failed_detail": "解析库存失败: {error}",
"workflow.inventory.file_missing": "ไม่ได้รับฟิลด์ file",
"workflow.inventory.file_type_unsupported": "รองรับเฉพาะไฟล์สต็อก .xlsx / .xls / .csv",
"workflow.inventory.uploading": "กำลังอัปโหลดและ解析ไฟล์สต็อก",
"workflow.inventory.uploading_detail": "กำลังประมวลผลไฟล์สต็อก {filename}",
"workflow.inventory.save_failed": "บันทึกไฟล์สต็อกไม่สำเร็จ: {error}",
"workflow.inventory.completed_task_locked": "งานนี้เสร็จสิ้นแล้ว จึงไม่สามารถอัปโหลดสต็อกซ้ำได้ โปรดสลับไปยังงานที่ยังต้องดำเนินการ",
"workflow.inventory.uploaded": "อัปโหลดไฟล์สต็อกแล้ว",
"workflow.inventory.uploaded_suggested_complete": " suggested_mapping ครบแล้ว จึงสามารถเรียก apply_inventory_mapping ได้ตรงจาก canvas โดยไม่ต้องผ่าน LLM",
"workflow.inventory.uploaded_need_llm": " โปรดให้ LLM บน canvas อนุมานการจับคู่คอลัมน์ แล้วจึงเรียก apply_inventory_mapping",
"workflow.inventory.apply_mapping_next": "apply_inventory_mapping(map_json=...)",
"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.fulfillment.excel_gate_unmatched": "ยังจับคู่สต็อกไม่เสร็จ โปรดอัปโหลดสต็อก ยืนยันการจับคู่คอลัมน์ แล้วเรียก match_inventory ก่อน",
"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": "สามารถลองอัปโหลดใหม่หรือเปลี่ยนเป็นอัปโหลดด้วยตนเองได้",
},
}
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_request_context():
hdr = str(request.headers.get("X-Lang") or "").strip()
if hdr:
return normalize_lang(hdr)
accept = str(request.headers.get("Accept-Language") or "").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"
return _MESSAGES.get(resolved, {}).get(key) or _MESSAGES["zh"].get(key) or key