From 07c9bbd8edec1ba9b7d1acc181308049a7729819 Mon Sep 17 00:00:00 2001 From: pseudoacacial Date: Fri, 15 Aug 2025 23:31:18 +0200 Subject: [PATCH] More translations for user-visible strings User-visible hungarian strings are now i18n keys. For download statuses, instead of just the string, an object with an i18n key is sent, so that it can be translated in the renderer. Note: download-error event left untranslated as download-error is not currently used in renderer. Also: for temporarily invisible elements (table and status on the search page) `element.hidden = true` is used instead of `element.style.display = "none"` --- locales/en/translation.json | 8 +++++++- locales/hu/translation.json | 8 +++++++- main.js | 15 ++++++++------- pages/settingsSite.html | 2 +- renderer.js | 16 +++++++++++----- 5 files changed, 34 insertions(+), 15 deletions(-) diff --git a/locales/en/translation.json b/locales/en/translation.json index b8d44bb..d15bed0 100644 --- a/locales/en/translation.json +++ b/locales/en/translation.json @@ -11,6 +11,7 @@ "helloWorld": "Hello World", "appTitle": "LibGen Book Search", "search": "Search", + "searching": "Searching...", "noResults": "No results.", "publisher": "Publisher", "language": "Language", @@ -32,5 +33,10 @@ "libgenServerSelection": "Libgen server selection", "libgenPingDescription": "This feature pings the following servers and automatically selects the fastest one:", "selectFastestServer": "Select fastest server", - "pingStatus": "" + "pingStatus": "", + "downloadLink": "Download link", + "noContentLength": "Warning: No content-length header was received.", + "opening": "Opening", + "downloadComplete": "Download complete!", + "downloading": "Downloading" } diff --git a/locales/hu/translation.json b/locales/hu/translation.json index 75bc9d5..3693065 100644 --- a/locales/hu/translation.json +++ b/locales/hu/translation.json @@ -11,6 +11,7 @@ "helloWorld": "Hello Világ", "appTitle": "LibGen Könyv Kereső", "search": "Keresés", + "searching": "Keresés...", "noResults": "Nincs találat.", "publisher": "Kiadó", "language": "Nyelv", @@ -32,5 +33,10 @@ "libgenServerSelection": "Libgen szerver kiválasztása", "libgenPingDescription": "Ez a funkció megpingeli a következő szervereket, és automatikusan kiválasztja a leggyorsabbat:", "selectFastestServer": "Leggyorsabb szerver kiválasztása", - "pingStatus": "" + "pingStatus": "", + "downloadLink": "Letöltési link", + "noContentLength": "Figyelmeztetés: Nem érkezett content-length fejléc.", + "opening": "Megnyitás", + "downloadComplete": "Letöltés kész!", + "downloading": "Letöltés" } diff --git a/main.js b/main.js index 7ff6bc9..1568999 100644 --- a/main.js +++ b/main.js @@ -181,7 +181,7 @@ ipcMain.handle('start-download', async (event, md5, extension) => { const detailUrl = `https://${libgenServer}/ads.php?md5=${md5}`; try { - event.sender.send('download-status', 'Megnyitás: ' + detailUrl); + event.sender.send('download-status', { key: 'opening', value: detailUrl }); const detailResponse = await axios.get(detailUrl); const $ = require('cheerio').load(detailResponse.data); @@ -193,7 +193,7 @@ ipcMain.handle('start-download', async (event, md5, extension) => { } const fullLink = getLink.startsWith('http') ? getLink : `https://${libgenServer}/${getLink}`; - event.sender.send('download-status', 'Letöltési link: ' + fullLink); + event.sender.send('download-status', { key: 'downloadLink', value: fullLink }); const downloadsDir = path.join(downloadDir); if (!fs.existsSync(downloadsDir)) { @@ -210,7 +210,7 @@ ipcMain.handle('start-download', async (event, md5, extension) => { const totalLength = parseInt(response.headers['content-length'], 10) || 0; if (!totalLength) { - event.sender.send('download-status', 'Figyelmeztetés: Nem érkezett content-length fejléc.'); + event.sender.send('download-status', { key: 'noContentLength' }); } const writer = fs.createWriteStream(filePath); @@ -223,9 +223,10 @@ ipcMain.handle('start-download', async (event, md5, extension) => { return; } const downloadedLength = stats.size; - event.sender.send('download-status', - `Letöltés: ${(downloadedLength / 1024 / 1024).toFixed(2)} MB / ${(totalLength / 1024 / 1024).toFixed(2)} MB` - ); + event.sender.send('download-status', { + key: 'downloading', + value: `${(downloadedLength / 1024 / 1024).toFixed(2)} MB / ${(totalLength / 1024 / 1024).toFixed(2)} MB` + }); }); }, 1500); // in millisecond @@ -235,7 +236,7 @@ ipcMain.handle('start-download', async (event, md5, extension) => { }); clearInterval(intervalId); - event.sender.send('download-status', 'Letöltés kész!'); + event.sender.send('download-status', { key: 'downloadComplete' }); event.sender.send('download-done', filePath); return { success: true, filePath }; diff --git a/pages/settingsSite.html b/pages/settingsSite.html index 808460d..8b4a7b6 100644 --- a/pages/settingsSite.html +++ b/pages/settingsSite.html @@ -8,7 +8,7 @@

Beállítások

- +

Libgen szerver kiválasztása

diff --git a/renderer.js b/renderer.js index 18bbac4..84a039c 100644 --- a/renderer.js +++ b/renderer.js @@ -75,7 +75,13 @@ async function showPage(page) { if (page === 'downloadProgress') { window.electronAPI.onDownloadStatus((event, status) => { const statusDiv = document.getElementById('downloadStatus'); - if (statusDiv) { + if (!statusDiv) return; + if (typeof status === 'object' && status.key && status.value) { + statusDiv.textContent = i18next.t(status.key) + ": " + status.value; + } + else if (typeof status === 'object' && status.key) { + statusDiv.textContent = i18next.t(status.key); + } else { statusDiv.textContent = status; } }); @@ -139,7 +145,7 @@ async function showPage(page) { const newPath = dirInput.value; const result = await window.electronAPI.setConfig(newPath); if (result.success) { - status.style.display= 'block'; + status.hidden = false; savePath.textContent = `${result.path}`; status.style.color = 'green'; currentDirText.textContent = result.path; @@ -211,8 +217,8 @@ async function performSearch() { const table = document.getElementById('resultsTable'); const tbody = table.querySelector('tbody'); - status.textContent = 'Keresés...'; - table.style.display = 'none'; + status.textContent = i18next.t('searching'); + table.hidden = true; tbody.innerHTML = ''; const results = await window.electronAPI.fetchLibgen(query); @@ -227,7 +233,7 @@ async function performSearch() { } status.textContent = `${results.length} results.`; - table.style.display = 'table'; + table.hidden = false; results.forEach(book => { const row = document.createElement('tr');