mirror of
https://github.com/alam00000/bentopdf.git
synced 2026-11-08 08:52:28 +01:00
fix: replace hardcoded strings with localized messages for table of contents functionality
This commit is contained in:
1 parent
a3692db354
commit
9c3f652553
3 files changed
+32
-10
No files matched your search
@@ -129,7 +129,7 @@ fileInput.addEventListener('change', (e) => {
|
||||
|
||||
async function generateTableOfContents() {
|
||||
if (!pdfFile) {
|
||||
showStatus('Please select a PDF file first.', 'error');
|
||||
showStatus(t('tools:tableOfContents.selectPdfFirst'), 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -141,11 +141,11 @@ async function generateTableOfContents() {
|
||||
|
||||
try {
|
||||
generateBtn.disabled = true;
|
||||
showStatus('Reading file (Main Thread)...', 'info');
|
||||
showStatus(t('tools:tableOfContents.statusReadingFileMainThread'), 'info');
|
||||
|
||||
const arrayBuffer = await pdfFile.arrayBuffer();
|
||||
|
||||
showStatus('Generating table of contents...', 'info');
|
||||
showStatus(t('tools:tableOfContents.statusGenerating'), 'info');
|
||||
|
||||
const title = tocTitleInput.value || t('tools:tableOfContents.name');
|
||||
const fontSize = parseInt(fontSizeSelect.value, 10);
|
||||
@@ -166,7 +166,10 @@ async function generateTableOfContents() {
|
||||
} catch (error) {
|
||||
console.error('Error reading file:', error);
|
||||
showStatus(
|
||||
`Error reading file: ${error instanceof Error ? error.message : 'Unknown error occurred'}`,
|
||||
t('tools:tableOfContents.errorReadingFileWithMessage', {
|
||||
message:
|
||||
error instanceof Error ? error.message : t('common.unknownError'),
|
||||
}),
|
||||
'error'
|
||||
);
|
||||
generateBtn.disabled = false;
|
||||
@@ -184,7 +187,7 @@ worker.onmessage = (e: MessageEvent<TOCWorkerResponse>) => {
|
||||
downloadFile(blob, pdfFile?.name || 'document.pdf');
|
||||
|
||||
showStatus(
|
||||
'Table of contents generated successfully! Download started.',
|
||||
t('tools:tableOfContents.successGeneratedDownloadStarted'),
|
||||
'success'
|
||||
);
|
||||
|
||||
@@ -195,15 +198,20 @@ worker.onmessage = (e: MessageEvent<TOCWorkerResponse>) => {
|
||||
fileDisplayArea.classList.add('hidden');
|
||||
generateBtn.disabled = true;
|
||||
} else if (e.data.status === 'error') {
|
||||
const errorMessage = e.data.message || 'Unknown error occurred in worker.';
|
||||
const errorMessage = e.data.message || t('common.unknownError');
|
||||
console.error('Worker Error:', errorMessage);
|
||||
showStatus(`Error: ${errorMessage}`, 'error');
|
||||
showStatus(
|
||||
t('tools:tableOfContents.workerErrorWithMessage', {
|
||||
message: errorMessage,
|
||||
}),
|
||||
'error'
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
worker.onerror = (error) => {
|
||||
console.error('Worker error:', error);
|
||||
showStatus('Worker error occurred. Check console for details.', 'error');
|
||||
showStatus(t('tools:tableOfContents.workerErrorOccurred'), 'error');
|
||||
generateBtn.disabled = false;
|
||||
};
|
||||
|
||||
|
||||
Reference in new issue
Block a user