mirror of
https://github.com/alam00000/bentopdf.git
synced 2026-11-07 00:28:39 +01:00
fix: add missing localization to wasm settings
This commit is contained in:
@@ -3,6 +3,7 @@ import { showAlert, showLoader, hideLoader } from '../ui.js';
|
||||
import { WasmProvider, type WasmPackage } from '../utils/wasm-provider.js';
|
||||
import { clearPyMuPDFCache } from '../utils/pymupdf-loader.js';
|
||||
import { clearGhostscriptCache } from '../utils/ghostscript-dynamic-loader.js';
|
||||
import { initI18n, t } from '../i18n/index.js';
|
||||
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', initializePage);
|
||||
@@ -10,9 +11,15 @@ if (document.readyState === 'loading') {
|
||||
initializePage();
|
||||
}
|
||||
|
||||
function initializePage() {
|
||||
async function initializePage() {
|
||||
createIcons({ icons });
|
||||
|
||||
try {
|
||||
await initI18n();
|
||||
} catch (error) {
|
||||
console.warn('WASM settings i18n initialization failed:', error);
|
||||
}
|
||||
|
||||
document.querySelectorAll('.copy-btn').forEach((btn) => {
|
||||
btn.addEventListener('click', async () => {
|
||||
const url = btn.getAttribute('data-copy');
|
||||
@@ -90,7 +97,7 @@ function initializePage() {
|
||||
input.value = url;
|
||||
} else {
|
||||
input.value = '';
|
||||
input.placeholder = `Using default: ${url}`;
|
||||
input.placeholder = t('tools:wasmSettings.usingDefault', { url });
|
||||
}
|
||||
updateStatus(name, true);
|
||||
}
|
||||
@@ -111,19 +118,19 @@ function initializePage() {
|
||||
if (!statusEl) return;
|
||||
|
||||
if (testing) {
|
||||
statusEl.textContent = 'Testing...';
|
||||
statusEl.textContent = t('tools:wasmSettings.status.testing');
|
||||
statusEl.className =
|
||||
'text-xs px-2 py-1 rounded-full bg-yellow-600/30 text-yellow-300';
|
||||
} else if (configured && WasmProvider.isUserConfigured(packageName)) {
|
||||
statusEl.textContent = 'Custom Override';
|
||||
statusEl.textContent = t('tools:wasmSettings.status.customOverride');
|
||||
statusEl.className =
|
||||
'text-xs px-2 py-1 rounded-full bg-blue-600/30 text-blue-300';
|
||||
} else if (configured || WasmProvider.hasEnvDefault(packageName)) {
|
||||
statusEl.textContent = 'Pre-configured';
|
||||
statusEl.textContent = t('tools:wasmSettings.status.preConfigured');
|
||||
statusEl.className =
|
||||
'text-xs px-2 py-1 rounded-full bg-green-600/30 text-green-300';
|
||||
} else {
|
||||
statusEl.textContent = 'Not Configured';
|
||||
statusEl.textContent = t('tools:wasmSettings.status.notConfigured');
|
||||
statusEl.className =
|
||||
'text-xs px-2 py-1 rounded-full bg-gray-600 text-gray-300';
|
||||
}
|
||||
@@ -131,7 +138,10 @@ function initializePage() {
|
||||
|
||||
async function testConnection(packageName: WasmPackage, url: string) {
|
||||
if (!url.trim()) {
|
||||
showAlert('Empty URL', 'Please enter a URL to test.');
|
||||
showAlert(
|
||||
t('tools:wasmSettings.emptyUrlTitle'),
|
||||
t('tools:wasmSettings.emptyUrlMessage')
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -142,15 +152,17 @@ function initializePage() {
|
||||
if (result.valid) {
|
||||
updateStatus(packageName, true);
|
||||
showAlert(
|
||||
'Success',
|
||||
`Connection to ${WasmProvider.getPackageDisplayName(packageName)} successful!`,
|
||||
t('tools:wasmSettings.testSuccessTitle'),
|
||||
t('tools:wasmSettings.connectionSuccess', {
|
||||
package: WasmProvider.getPackageDisplayName(packageName),
|
||||
}),
|
||||
'success'
|
||||
);
|
||||
} else {
|
||||
updateStatus(packageName, false);
|
||||
showAlert(
|
||||
'Connection Failed',
|
||||
result.error || 'Could not connect to the URL.'
|
||||
t('tools:wasmSettings.connectionFailedTitle'),
|
||||
result.error || t('tools:wasmSettings.connectionFailedMessage')
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -168,7 +180,7 @@ function initializePage() {
|
||||
});
|
||||
|
||||
saveBtn?.addEventListener('click', async () => {
|
||||
showLoader('Saving configuration...');
|
||||
showLoader(t('tools:wasmSettings.savingConfiguration'));
|
||||
|
||||
try {
|
||||
if (pymupdfUrl.value.trim()) {
|
||||
@@ -196,11 +208,19 @@ function initializePage() {
|
||||
}
|
||||
|
||||
hideLoader();
|
||||
showAlert('Saved', 'Configuration saved successfully!', 'success');
|
||||
showAlert(
|
||||
t('tools:wasmSettings.savedTitle'),
|
||||
t('tools:wasmSettings.savedMessage'),
|
||||
'success'
|
||||
);
|
||||
} catch (e: unknown) {
|
||||
hideLoader();
|
||||
const errorMessage = e instanceof Error ? e.message : 'Unknown error';
|
||||
showAlert('Error', `Failed to save configuration: ${errorMessage}`);
|
||||
const errorMessage =
|
||||
e instanceof Error ? e.message : t('tools:wasmSettings.unknownError');
|
||||
showAlert(
|
||||
t('tools:wasmSettings.errorTitle'),
|
||||
t('tools:wasmSettings.failedSave', { message: errorMessage })
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -225,10 +245,10 @@ function initializePage() {
|
||||
WasmProvider.hasEnvDefault('cpdf');
|
||||
|
||||
showAlert(
|
||||
'Reset',
|
||||
t('tools:wasmSettings.resetTitle'),
|
||||
hasDefaults
|
||||
? 'Custom overrides cleared. Pre-configured defaults are active.'
|
||||
: 'All configurations and cached modules have been cleared.',
|
||||
? t('tools:wasmSettings.resetWithDefaults')
|
||||
: t('tools:wasmSettings.resetNoDefaults'),
|
||||
'success'
|
||||
);
|
||||
});
|
||||
|
||||
@@ -134,7 +134,7 @@
|
||||
<span
|
||||
id="pymupdf-status"
|
||||
class="text-xs px-2 py-1 rounded-full bg-gray-600 text-gray-300"
|
||||
data-i18n="tools:wasmSettings.notConfigured"
|
||||
data-i18n="tools:wasmSettings.status.notConfigured"
|
||||
>
|
||||
Not Configured
|
||||
</span>
|
||||
@@ -197,7 +197,7 @@
|
||||
<span
|
||||
id="ghostscript-status"
|
||||
class="text-xs px-2 py-1 rounded-full bg-gray-600 text-gray-300"
|
||||
data-i18n="tools:wasmSettings.notConfigured"
|
||||
data-i18n="tools:wasmSettings.status.notConfigured"
|
||||
>
|
||||
Not Configured
|
||||
</span>
|
||||
@@ -259,7 +259,7 @@
|
||||
<span
|
||||
id="cpdf-status"
|
||||
class="text-xs px-2 py-1 rounded-full bg-gray-600 text-gray-300"
|
||||
data-i18n="tools:wasmSettings.notConfigured"
|
||||
data-i18n="tools:wasmSettings.status.notConfigured"
|
||||
>
|
||||
Not Configured
|
||||
</span>
|
||||
@@ -375,13 +375,18 @@
|
||||
<div
|
||||
class="bg-gray-800 rounded-lg shadow-xl p-6 max-w-sm w-full border border-gray-700"
|
||||
>
|
||||
<h3 id="alert-title" class="text-xl font-bold text-white mb-2">
|
||||
<h3
|
||||
id="alert-title"
|
||||
class="text-xl font-bold text-white mb-2"
|
||||
data-i18n="alert.title"
|
||||
>
|
||||
Alert
|
||||
</h3>
|
||||
<p id="alert-message" class="text-gray-300 mb-6"></p>
|
||||
<button
|
||||
id="alert-ok"
|
||||
class="w-full bg-indigo-600 hover:bg-indigo-700 text-white font-semibold py-2 px-4 rounded-lg transition-colors duration-200"
|
||||
data-i18n="common.ok"
|
||||
>
|
||||
OK
|
||||
</button>
|
||||
|
||||
Reference in New Issue
Block a user