diff options
Diffstat (limited to 'components/form-data/sedp-excel-download.tsx')
| -rw-r--r-- | components/form-data/sedp-excel-download.tsx | 43 |
1 files changed, 24 insertions, 19 deletions
diff --git a/components/form-data/sedp-excel-download.tsx b/components/form-data/sedp-excel-download.tsx index 24e1003d..36be4847 100644 --- a/components/form-data/sedp-excel-download.tsx +++ b/components/form-data/sedp-excel-download.tsx @@ -1,4 +1,6 @@ import * as React from "react"; +import { useParams } from "next/navigation"; +import { useTranslation } from "@/i18n/client"; import { Button } from "@/components/ui/button"; import { FileDown, Loader } from "lucide-react"; import { toast } from "sonner"; @@ -28,6 +30,9 @@ interface ExcelDownloadProps { export function ExcelDownload({ comparisonResults, missingTags, formCode, disabled }: ExcelDownloadProps) { const [isExporting, setIsExporting] = React.useState(false); + const params = useParams(); + const lng = (params?.lng as string) || "ko"; + const { t } = useTranslation(lng, "engineering"); // Function to generate and download Excel file with differences const handleExportDifferences = async () => { @@ -39,7 +44,7 @@ export function ExcelDownload({ comparisonResults, missingTags, formCode, disabl const hasMissingTags = missingTags.localOnly.length > 0 || missingTags.sedpOnly.length > 0; if (itemsWithDifferences.length === 0 && !hasMissingTags) { - toast.info("차이가 없어 다운로드할 내용이 없습니다"); + toast.info(t("excelDownload.noDifferencesToDownload")); return; } @@ -50,15 +55,15 @@ export function ExcelDownload({ comparisonResults, missingTags, formCode, disabl // Add a worksheet for attribute differences if (itemsWithDifferences.length > 0) { - const worksheet = workbook.addWorksheet('속성 차이'); + const worksheet = workbook.addWorksheet(t("excelDownload.attributeDifferencesSheet")); // Add headers worksheet.columns = [ - { header: 'Tag Number', key: 'tagNo', width: 20 }, - { header: 'Tag Description', key: 'tagDesc', width: 30 }, - { header: 'Attribute', key: 'attribute', width: 25 }, - { header: 'Local Value', key: 'localValue', width: 20 }, - { header: 'SEDP Value', key: 'sedpValue', width: 20 } + { header: t("excelDownload.tagNumber"), key: 'tagNo', width: 20 }, + { header: t("excelDownload.tagDescription"), key: 'tagDesc', width: 30 }, + { header: t("excelDownload.attribute"), key: 'attribute', width: 25 }, + { header: t("excelDownload.localValue"), key: 'localValue', width: 20 }, + { header: t("excelDownload.sedpValue"), key: 'sedpValue', width: 20 } ]; // Style the header row @@ -90,12 +95,12 @@ export function ExcelDownload({ comparisonResults, missingTags, formCode, disabl // Format local value with UOM const localDisplay = diff.localValue === null || diff.localValue === undefined || diff.localValue === '' - ? "(empty)" + ? t("excelDownload.emptyValue") : diff.uom ? `${diff.localValue} ${diff.uom}` : diff.localValue; // SEDP value is displayed as-is const sedpDisplay = diff.sedpValue === null || diff.sedpValue === undefined || diff.sedpValue === '' - ? "(empty)" + ? t("excelDownload.emptyValue") : diff.sedpValue; // Set cell values @@ -127,13 +132,13 @@ export function ExcelDownload({ comparisonResults, missingTags, formCode, disabl // Add a worksheet for missing tags if there are any if (hasMissingTags) { - const missingWorksheet = workbook.addWorksheet('누락된 태그'); + const missingWorksheet = workbook.addWorksheet(t("excelDownload.missingTagsSheet")); // Add headers missingWorksheet.columns = [ - { header: 'Tag Number', key: 'tagNo', width: 20 }, - { header: 'Tag Description', key: 'tagDesc', width: 30 }, - { header: 'Status', key: 'status', width: 20 } + { header: t("excelDownload.tagNumber"), key: 'tagNo', width: 20 }, + { header: t("excelDownload.tagDescription"), key: 'tagDesc', width: 30 }, + { header: t("excelDownload.status"), key: 'status', width: 20 } ]; // Style the header row @@ -160,7 +165,7 @@ export function ExcelDownload({ comparisonResults, missingTags, formCode, disabl row.getCell('tagNo').value = tag.tagNo; row.getCell('tagDesc').value = tag.tagDesc; - row.getCell('status').value = '로컬에만 존재'; + row.getCell('status').value = t("excelDownload.localOnlyStatus"); // Style the status cell row.getCell('status').font = { color: { argb: 'FFFF8C00' } }; // Orange for local-only @@ -187,7 +192,7 @@ export function ExcelDownload({ comparisonResults, missingTags, formCode, disabl row.getCell('tagNo').value = tag.tagNo; row.getCell('tagDesc').value = tag.tagDesc; - row.getCell('status').value = 'SEDP에만 존재'; + row.getCell('status').value = t("excelDownload.sedpOnlyStatus"); // Style the status cell row.getCell('status').font = { color: { argb: 'FF0000FF' } }; // Blue for SEDP-only @@ -214,7 +219,7 @@ export function ExcelDownload({ comparisonResults, missingTags, formCode, disabl const url = window.URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; - a.download = `SEDP_차이점_${formCode}_${new Date().toISOString().slice(0, 10)}.xlsx`; + a.download = `${t("excelDownload.fileNamePrefix")}_${formCode}_${new Date().toISOString().slice(0, 10)}.xlsx`; document.body.appendChild(a); a.click(); @@ -222,10 +227,10 @@ export function ExcelDownload({ comparisonResults, missingTags, formCode, disabl window.URL.revokeObjectURL(url); document.body.removeChild(a); - toast.success("Excel 다운로드 완료"); + toast.success(t("excelDownload.downloadComplete")); } catch (error) { console.error("Error exporting to Excel:", error); - toast.error("Excel 다운로드 실패"); + toast.error(t("excelDownload.downloadFailed")); } finally { setIsExporting(false); } @@ -248,7 +253,7 @@ export function ExcelDownload({ comparisonResults, missingTags, formCode, disabl ) : ( <FileDown className="h-4 w-4" /> )} - 차이점 Excel로 다운로드 + {t("excelDownload.downloadButtonText")} </Button> ); }
\ No newline at end of file |
