Commit 150d32cb authored by ThinhNC's avatar ThinhNC

fix(ocr): localize OCR receipt extraction warnings for Vietnamese and English

parent 57d7b4b7
...@@ -1537,6 +1537,7 @@ ...@@ -1537,6 +1537,7 @@
"previewAlt": "Receipt preview", "previewAlt": "Receipt preview",
"itemCount": "{{count}} items", "itemCount": "{{count}} items",
"warnings": "AI Warnings", "warnings": "AI Warnings",
"defaultWarning": "Please verify extracted values against the original receipt before creating a transaction.",
"confirmTransaction": "Confirm Create Transaction", "confirmTransaction": "Confirm Create Transaction",
"confirmHint": "Pre-fill this extracted receipt data into a new Transaction", "confirmHint": "Pre-fill this extracted receipt data into a new Transaction",
"reScan": "Scan Another Receipt" "reScan": "Scan Another Receipt"
......
...@@ -1638,6 +1638,7 @@ ...@@ -1638,6 +1638,7 @@
"previewAlt": "Bản xem trước hóa đơn", "previewAlt": "Bản xem trước hóa đơn",
"itemCount": "{{count}} món", "itemCount": "{{count}} món",
"warnings": "Cảnh báo từ AI", "warnings": "Cảnh báo từ AI",
"defaultWarning": "Vui lòng đối chiếu các giá trị đã trích xuất với hóa đơn gốc trước khi tạo giao dịch.",
"confirmTransaction": "Xác nhận tạo Giao dịch", "confirmTransaction": "Xác nhận tạo Giao dịch",
"confirmHint": "Tự động điền dữ liệu hóa đơn này vào Form tạo giao dịch mới", "confirmHint": "Tự động điền dữ liệu hóa đơn này vào Form tạo giao dịch mới",
"reScan": "Quét hóa đơn khác" "reScan": "Quét hóa đơn khác"
......
...@@ -1549,6 +1549,7 @@ export function handleGuestRequest(config: InternalAxiosRequestConfig): AxiosRes ...@@ -1549,6 +1549,7 @@ export function handleGuestRequest(config: InternalAxiosRequestConfig): AxiosRes
rawText: `SIEU THI CO.OPMART\nNgay: ${todayStr}\n1. Sua chua hoa qua: 70.000\n2. Banh mi sandwich: 45.000\n3. Nuoc ep cam: 110.000\n4. Khan giay: 25.000\nTong tien: 250.000 VND\nVAT 8%: 20.000 VND`, rawText: `SIEU THI CO.OPMART\nNgay: ${todayStr}\n1. Sua chua hoa qua: 70.000\n2. Banh mi sandwich: 45.000\n3. Nuoc ep cam: 110.000\n4. Khan giay: 25.000\nTong tien: 250.000 VND\nVAT 8%: 20.000 VND`,
confidence: 0.96, confidence: 0.96,
warnings: [ warnings: [
"Vui lòng đối chiếu các giá trị đã trích xuất với hóa đơn gốc trước khi tạo giao dịch.",
"Hóa đơn mẫu mô phỏng trong Chế độ Dùng thử (100% xử lý tại máy, không tốn token AI thật).", "Hóa đơn mẫu mô phỏng trong Chế độ Dùng thử (100% xử lý tại máy, không tốn token AI thật).",
], ],
}, },
......
...@@ -61,7 +61,13 @@ export const ReceiptScannerView: React.FC<ReceiptScannerViewProps> = ({ onTransa ...@@ -61,7 +61,13 @@ export const ReceiptScannerView: React.FC<ReceiptScannerViewProps> = ({ onTransa
// Auto trigger extraction // Auto trigger extraction
extractMutation.mutate( extractMutation.mutate(
{ file }, {
file,
hints: {
languageHint: intlLocale === "vi" ? "vi" : "en",
currencyHint: "VND",
},
},
{ {
onSuccess: (res) => { onSuccess: (res) => {
if (res.success && res.data) { if (res.success && res.data) {
...@@ -165,6 +171,16 @@ export const ReceiptScannerView: React.FC<ReceiptScannerViewProps> = ({ onTransa ...@@ -165,6 +171,16 @@ export const ReceiptScannerView: React.FC<ReceiptScannerViewProps> = ({ onTransa
}) })
: "—"; : "—";
const localizeWarning = (warn: string): string => {
const trimmed = warn.trim();
const standardEn = "please verify extracted values against the original receipt before creating a transaction.";
const standardVi = "vui lòng đối chiếu các giá trị đã trích xuất với hóa đơn gốc trước khi tạo giao dịch.";
if (trimmed.toLowerCase() === standardEn || trimmed.toLowerCase() === standardVi) {
return t("ai.ocr.defaultWarning");
}
return trimmed;
};
return ( return (
<div className="flex flex-col gap-5 px-2 pb-4 pt-2"> <div className="flex flex-col gap-5 px-2 pb-4 pt-2">
<section className="text-center"> <section className="text-center">
...@@ -391,7 +407,7 @@ export const ReceiptScannerView: React.FC<ReceiptScannerViewProps> = ({ onTransa ...@@ -391,7 +407,7 @@ export const ReceiptScannerView: React.FC<ReceiptScannerViewProps> = ({ onTransa
{t("ai.ocr.warnings")}: {t("ai.ocr.warnings")}:
</span> </span>
{extractedData.warnings.map((warn, i) => ( {extractedData.warnings.map((warn, i) => (
<p key={i}>• {warn}</p> <p key={i}>• {localizeWarning(warn)}</p>
))} ))}
</div> </div>
)} )}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment