mirror of
https://github.com/alam00000/bentopdf.git
synced 2026-11-08 16:57:14 +01:00
feat(i18n): localize status messages and UI elements across various tools
This commit is contained in:
1 parent
651793bffa
commit
63707f0a18
19 files changed
+530
-124
No files matched your search
+21
-14
@@ -10,6 +10,7 @@ import {
|
||||
showWasmRequiredDialog,
|
||||
WasmProvider,
|
||||
} from '../utils/wasm-provider.js';
|
||||
import { t } from '../i18n/i18n';
|
||||
|
||||
const worker = new Worker(
|
||||
import.meta.env.BASE_URL + 'workers/json-to-pdf.worker.js'
|
||||
@@ -80,10 +81,12 @@ jsonFilesInput.addEventListener('change', (e) => {
|
||||
updateFileList();
|
||||
|
||||
if (selectedFiles.length === 0) {
|
||||
showStatus('Please select at least 1 JSON file', 'info');
|
||||
showStatus(t('tools:jsonToPdf.status.selectAtLeastOne'), 'info');
|
||||
} else {
|
||||
showStatus(
|
||||
`${selectedFiles.length} file(s) selected. Ready to convert!`,
|
||||
t('tools:jsonToPdf.status.selectedReady', {
|
||||
count: selectedFiles.length,
|
||||
}),
|
||||
'info'
|
||||
);
|
||||
}
|
||||
@@ -92,7 +95,7 @@ jsonFilesInput.addEventListener('change', (e) => {
|
||||
|
||||
async function convertJSONsToPDF() {
|
||||
if (selectedFiles.length === 0) {
|
||||
showStatus('Please select at least 1 JSON file', 'error');
|
||||
showStatus(t('tools:jsonToPdf.status.selectAtLeastOne'), 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -104,13 +107,13 @@ async function convertJSONsToPDF() {
|
||||
|
||||
try {
|
||||
convertBtn.disabled = true;
|
||||
showStatus('Reading files (Main Thread)...', 'info');
|
||||
showStatus(t('tools:jsonToPdf.status.readingFiles'), 'info');
|
||||
|
||||
const fileBuffers = await Promise.all(
|
||||
selectedFiles.map((file) => readFileAsArrayBuffer(file))
|
||||
);
|
||||
|
||||
showStatus('Converting JSONs to PDFs...', 'info');
|
||||
showStatus(t('tools:jsonToPdf.status.converting'), 'info');
|
||||
|
||||
worker.postMessage(
|
||||
{
|
||||
@@ -124,7 +127,9 @@ async function convertJSONsToPDF() {
|
||||
} catch (error) {
|
||||
console.error('Error reading files:', error);
|
||||
showStatus(
|
||||
`❌ Error reading files: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
||||
t('tools:jsonToPdf.status.readError', {
|
||||
message: error instanceof Error ? error.message : 'Unknown error',
|
||||
}),
|
||||
'error'
|
||||
);
|
||||
convertBtn.disabled = false;
|
||||
@@ -141,7 +146,7 @@ worker.onmessage = async (e: MessageEvent) => {
|
||||
}>;
|
||||
|
||||
try {
|
||||
showStatus('Creating ZIP file...', 'info');
|
||||
showStatus(t('tools:jsonToPdf.status.creatingZip'), 'info');
|
||||
|
||||
const zip = new JSZip();
|
||||
pdfFiles.forEach(({ name, data }) => {
|
||||
@@ -157,10 +162,7 @@ worker.onmessage = async (e: MessageEvent) => {
|
||||
a.download = 'jsons-to-pdf.zip';
|
||||
downloadFile(zipBlob, 'jsons-to-pdf.zip');
|
||||
|
||||
showStatus(
|
||||
'✅ JSONs converted to PDF successfully! ZIP download started.',
|
||||
'success'
|
||||
);
|
||||
showStatus(t('tools:jsonToPdf.status.success'), 'success');
|
||||
|
||||
selectedFiles = [];
|
||||
jsonFilesInput.value = '';
|
||||
@@ -174,14 +176,19 @@ worker.onmessage = async (e: MessageEvent) => {
|
||||
} catch (error) {
|
||||
console.error('Error creating ZIP:', error);
|
||||
showStatus(
|
||||
`❌ Error creating ZIP: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
||||
t('tools:jsonToPdf.status.zipError', {
|
||||
message: error instanceof Error ? error.message : 'Unknown error',
|
||||
}),
|
||||
'error'
|
||||
);
|
||||
}
|
||||
} else if (e.data.status === 'error') {
|
||||
const errorMessage = e.data.message || 'Unknown error occurred in worker.';
|
||||
console.error('Worker Error:', errorMessage);
|
||||
showStatus(`❌ Worker Error: ${errorMessage}`, 'error');
|
||||
showStatus(
|
||||
t('tools:jsonToPdf.status.workerError', { message: errorMessage }),
|
||||
'error'
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -194,5 +201,5 @@ if (backToToolsBtn) {
|
||||
convertBtn.addEventListener('click', convertJSONsToPDF);
|
||||
|
||||
// Initialize
|
||||
showStatus('Select JSON files to get started', 'info');
|
||||
showStatus(t('tools:jsonToPdf.status.getStarted'), 'info');
|
||||
initializeGlobalShortcuts();
|
||||
+22
-15
@@ -12,6 +12,7 @@ import {
|
||||
WasmProvider,
|
||||
} from '../utils/wasm-provider.js';
|
||||
import { batchDecryptIfNeeded } from '../utils/password-prompt.js';
|
||||
import { t } from '../i18n/i18n';
|
||||
|
||||
const worker = new Worker(
|
||||
import.meta.env.BASE_URL + 'workers/pdf-to-json.worker.js'
|
||||
@@ -82,10 +83,12 @@ pdfFilesInput.addEventListener('change', (e) => {
|
||||
updateFileList();
|
||||
|
||||
if (selectedFiles.length === 0) {
|
||||
showStatus('Please select at least 1 PDF file', 'info');
|
||||
showStatus(t('tools:pdfToJson.status.selectAtLeastOne'), 'info');
|
||||
} else {
|
||||
showStatus(
|
||||
`${selectedFiles.length} file(s) selected. Ready to convert!`,
|
||||
t('tools:pdfToJson.status.selectedReady', {
|
||||
count: selectedFiles.length,
|
||||
}),
|
||||
'info'
|
||||
);
|
||||
}
|
||||
@@ -94,7 +97,7 @@ pdfFilesInput.addEventListener('change', (e) => {
|
||||
|
||||
async function convertPDFsToJSON() {
|
||||
if (selectedFiles.length === 0) {
|
||||
showStatus('Please select at least 1 PDF file', 'error');
|
||||
showStatus(t('tools:pdfToJson.status.selectAtLeastOne'), 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -106,17 +109,17 @@ async function convertPDFsToJSON() {
|
||||
|
||||
try {
|
||||
convertBtn.disabled = true;
|
||||
showStatus('Checking for encrypted PDFs...', 'info');
|
||||
showStatus(t('tools:pdfToJson.status.checkingEncrypted'), 'info');
|
||||
|
||||
selectedFiles = await batchDecryptIfNeeded(selectedFiles);
|
||||
|
||||
showStatus('Reading files (Main Thread)...', 'info');
|
||||
showStatus(t('tools:pdfToJson.status.readingFiles'), 'info');
|
||||
|
||||
const fileBuffers = await Promise.all(
|
||||
selectedFiles.map((file) => readFileAsArrayBuffer(file))
|
||||
);
|
||||
|
||||
showStatus('Converting PDFs to JSON..', 'info');
|
||||
showStatus(t('tools:pdfToJson.status.converting'), 'info');
|
||||
|
||||
worker.postMessage(
|
||||
{
|
||||
@@ -130,7 +133,9 @@ async function convertPDFsToJSON() {
|
||||
} catch (error) {
|
||||
console.error('Error reading files:', error);
|
||||
showStatus(
|
||||
`❌ Error reading files: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
||||
t('tools:pdfToJson.status.readError', {
|
||||
message: error instanceof Error ? error.message : 'Unknown error',
|
||||
}),
|
||||
'error'
|
||||
);
|
||||
convertBtn.disabled = false;
|
||||
@@ -147,7 +152,7 @@ worker.onmessage = async (e: MessageEvent) => {
|
||||
}>;
|
||||
|
||||
try {
|
||||
showStatus('Creating ZIP file...', 'info');
|
||||
showStatus(t('tools:pdfToJson.status.creatingZip'), 'info');
|
||||
|
||||
const zip = new JSZip();
|
||||
const usedNames = new Set<string>();
|
||||
@@ -161,10 +166,7 @@ worker.onmessage = async (e: MessageEvent) => {
|
||||
const zipBlob = await zip.generateAsync({ type: 'blob' });
|
||||
downloadFile(zipBlob, 'pdfs-to-json.zip');
|
||||
|
||||
showStatus(
|
||||
'✅ PDFs converted to JSON successfully! ZIP download started.',
|
||||
'success'
|
||||
);
|
||||
showStatus(t('tools:pdfToJson.status.success'), 'success');
|
||||
|
||||
selectedFiles = [];
|
||||
pdfFilesInput.value = '';
|
||||
@@ -178,14 +180,19 @@ worker.onmessage = async (e: MessageEvent) => {
|
||||
} catch (error) {
|
||||
console.error('Error creating ZIP:', error);
|
||||
showStatus(
|
||||
`❌ Error creating ZIP: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
||||
t('tools:pdfToJson.status.zipError', {
|
||||
message: error instanceof Error ? error.message : 'Unknown error',
|
||||
}),
|
||||
'error'
|
||||
);
|
||||
}
|
||||
} else if (e.data.status === 'error') {
|
||||
const errorMessage = e.data.message || 'Unknown error occurred in worker.';
|
||||
console.error('Worker Error:', errorMessage);
|
||||
showStatus(`❌ Worker Error: ${errorMessage}`, 'error');
|
||||
showStatus(
|
||||
t('tools:pdfToJson.status.workerError', { message: errorMessage }),
|
||||
'error'
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -197,5 +204,5 @@ if (backToToolsBtn) {
|
||||
|
||||
convertBtn.addEventListener('click', convertPDFsToJSON);
|
||||
|
||||
showStatus('Select PDF files to get started', 'info');
|
||||
showStatus(t('tools:pdfToJson.status.getStarted'), 'info');
|
||||
initializeGlobalShortcuts();
|
||||
Reference in new issue
Block a user