diff --git a/plugins/koinsight.koplugin/call_api.lua b/plugins/koinsight.koplugin/call_api.lua index eae089a..76d675f 100644 --- a/plugins/koinsight.koplugin/call_api.lua +++ b/plugins/koinsight.koplugin/call_api.lua @@ -6,7 +6,7 @@ local http = require("socket.http") local UIManager = require("ui/uimanager") local JSON = require("json") local InfoMessage = require("ui/widget/infomessage") -local _ = require("gettext") +local _ = require("koinsight_l10n") function response_not_valid(content) logger.err("[KoInsight] callApi: response was not valid JSON", content) @@ -65,7 +65,7 @@ return function(method, url, headers, body, filepath, quiet) if not quiet then logger.err("[KoInsight] callApi: HTTP error", status or code, resp_headers, result) UIManager:show(InfoMessage:new({ - text = _("Server error" .. (result and ": " .. result["error"] or "")), + text = _("Server error") .. (result and ": " .. result["error"] or ""), })) end diff --git a/plugins/koinsight.koplugin/koinsight_l10n.lua b/plugins/koinsight.koplugin/koinsight_l10n.lua new file mode 100644 index 0000000..7d52e85 --- /dev/null +++ b/plugins/koinsight.koplugin/koinsight_l10n.lua @@ -0,0 +1,68 @@ +-- Plugin-local translations for KoInsight. +-- KOReader's gettext catalog only covers core strings, so plugin strings are +-- looked up here first and fall back to KOReader's gettext (i.e. English). +local gettext = require("gettext") + +local translations = { + sk = { + ["About KoInsight"] = "O doplnku KoInsight", + ["Aggressive suspend sync disabled"] = "Agresívna synchronizácia pri uspaní vypnutá", + ["Aggressive suspend sync enabled"] = "Agresívna synchronizácia pri uspaní zapnutá", + ["Aggressive sync on suspend (auto Wi-Fi)"] = "Agresívna synchronizácia pri uspaní (automatické Wi-Fi)", + ["Apply"] = "Použiť", + ["Cancel"] = "Zrušiť", + ["Data upload failed."] = "Odoslanie údajov zlyhalo.", + ["Data uploaded."] = "Údaje boli odoslané.", + ["Enter the location of your KoInsight server"] = "Zadajte adresu vášho servera KoInsight", + ["Error during auto sync: "] = "Chyba pri automatickej synchronizácii: ", + ["Error toggling aggressive sync setting"] = "Chyba pri prepínaní agresívnej synchronizácie", + ["Error toggling sync setting"] = "Chyba pri prepínaní nastavenia synchronizácie", + ["Error:"] = "Chyba:", + ["Info"] = "Informácie", + ["KoInsight is a sync plugin for KoInsight instances.\n\nPlugin version: %s\n\nSee https://github.com/GeorgeSG/koinsight."] = "KoInsight je synchronizačný doplnok pre inštancie KoInsight.\n\nVerzia doplnku: %s\n\nViac na https://github.com/GeorgeSG/koinsight.", + ["KoInsight server URL is not configured."] = "URL servera KoInsight nie je nastavená.", + ["KoInsight settings saved."] = "Nastavenia KoInsight boli uložené.", + ["KoInsight settings"] = "Nastavenia KoInsight", + ["KoInsight: Sync all books"] = "KoInsight: Synchronizovať všetky knihy", + ["No books with annotations found in reading history."] = "V histórii čítania sa nenašli žiadne knihy s poznámkami.", + ["Please configure the server URL first."] = "Najprv nastavte URL servera.", + ["Please enter a server URL."] = "Zadajte URL servera.", + ["Server URL:"] = "URL servera:", + ["Server error"] = "Chyba servera", + ["Server response is not valid."] = "Odpoveď servera nie je platná.", + ["Set server URL"] = "Nastaviť URL servera", + ["Set suspend connect timeout…"] = "Nastaviť časový limit pripojenia pri uspaní…", + ["Starting sync..\nScanning reading history for books with annotations."] = "Spúšťam synchronizáciu…\nPrehľadávam históriu čítania a hľadám knihy s poznámkami.", + ["Success:"] = "Úspech:", + ["Suspend connect timeout (seconds)"] = "Časový limit pripojenia pri uspaní (sekundy)", + ["Sync complete!\n%d/%d books synced successfully\n%d failed"] = "Synchronizácia dokončená!\n%d/%d kníh úspešne synchronizovaných\nNeúspešné: %d", + ["Sync failed: "] = "Synchronizácia zlyhala: ", + ["Sync on suspend disabled"] = "Synchronizácia pri uspaní vypnutá", + ["Sync on suspend enabled"] = "Synchronizácia pri uspaní zapnutá", + ["Sync on suspend"] = "Synchronizovať pri uspaní", + ["Synchronize data"] = "Synchronizovať údaje", + ["Syncing: %d/%d books\n%d annotations for current book"] = "Synchronizácia: %d/%d kníh\n%d poznámok v aktuálnej knihe", + ["The server URL must start with 'http://' or 'https://'.\n\n"] = "URL servera musí začínať na 'http://' alebo 'https://'.\n\n", + ["Timeout (3..60):"] = "Limit (3..60):", + ["Timeout saved."] = "Časový limit bol uložený.", + ["Unable to register device."] = "Zariadenie sa nepodarilo zaregistrovať.", + ["http://example.com:port"] = "http://priklad.sk:port", + }, +} + +local function currentLanguage() + local lang = gettext.current_lang + if (not lang or lang == "C") and G_reader_settings then + lang = G_reader_settings:readSetting("language") + end + if not lang then + return nil + end + -- "sk_SK" / "sk-SK" -> "sk" + return lang:match("^(%a+)") +end + +return function(msgid) + local catalog = translations[currentLanguage()] + return (catalog and catalog[msgid]) or gettext(msgid) +end diff --git a/plugins/koinsight.koplugin/main.lua b/plugins/koinsight.koplugin/main.lua index 1f3c33c..ad93fa2 100644 --- a/plugins/koinsight.koplugin/main.lua +++ b/plugins/koinsight.koplugin/main.lua @@ -1,4 +1,4 @@ -local _ = require("gettext") +local _ = require("koinsight_l10n") local Dispatcher = require("dispatcher") -- luacheck:ignore local InfoMessage = require("ui/widget/infomessage") local logger = require("logger") @@ -89,9 +89,10 @@ function koinsight:addToMainMenu(menu_items) callback = function() local const = require("./const") UIManager:show(InfoMessage:new({ - text = "KoInsight is a sync plugin for KoInsight instances.\n\nPlugin version: " - .. const.VERSION - .. "\n\nSee https://github.com/GeorgeSG/koinsight.", + text = string.format( + _("KoInsight is a sync plugin for KoInsight instances.\n\nPlugin version: %s\n\nSee https://github.com/GeorgeSG/koinsight."), + const.VERSION + ), })) end, }, @@ -171,7 +172,7 @@ function koinsight:performFullSync() if not ok then UIManager:close(progress_info) logger.err("[KoInsight] Full sync failed: " .. tostring(err)) - UIManager:show(InfoMessage:new({ text = _("Sync failed: " .. tostring(err)), timeout = 5 })) + UIManager:show(InfoMessage:new({ text = _("Sync failed: ") .. tostring(err), timeout = 5 })) end end) end @@ -244,10 +245,10 @@ function koinsight:performSyncOnSuspend() end) if not success then - message = "Error during auto sync: " .. tostring(error_msg) + local message = "Error during auto sync: " .. tostring(error_msg) logger.err("[KoInsight] " .. message) UIManager:show(InfoMessage:new({ - text = _(message), + text = _("Error during auto sync: ") .. tostring(error_msg), })) else logger.info("[KoInsight] Suspend sync completed successfully") diff --git a/plugins/koinsight.koplugin/settings.lua b/plugins/koinsight.koplugin/settings.lua index 5c1febd..8444f67 100644 --- a/plugins/koinsight.koplugin/settings.lua +++ b/plugins/koinsight.koplugin/settings.lua @@ -1,4 +1,4 @@ -local _ = require("gettext") +local _ = require("koinsight_l10n") local BD = require("ui/bidi") local DataStorage = require("datastorage") local InfoMessage = require("ui/widget/infomessage") diff --git a/plugins/koinsight.koplugin/upload.lua b/plugins/koinsight.koplugin/upload.lua index 912bc95..8091886 100644 --- a/plugins/koinsight.koplugin/upload.lua +++ b/plugins/koinsight.koplugin/upload.lua @@ -1,4 +1,4 @@ -local _ = require("gettext") +local _ = require("koinsight_l10n") local callApi = require("call_api") local InfoMessage = require("ui/widget/infomessage") local JSON = require("json") @@ -30,7 +30,7 @@ function render_response_message(response, prefix, default_text) end UIManager:show(InfoMessage:new({ - text = _(text), + text = text, })) end @@ -46,7 +46,7 @@ function send_device_data(server_url, silent) local ok, response = callApi("POST", url, get_headers(body), body) if ok ~= true and not silent then - render_response_message(response, "Error:", "Unable to register device.") + render_response_message(response, _("Error:"), _("Unable to register device.")) end end @@ -78,9 +78,9 @@ function send_statistics_data(server_url, silent) if not silent then if ok then - render_response_message(response, "Success:", "Data uploaded.") + render_response_message(response, _("Success:"), _("Data uploaded.")) else - render_response_message(response, "Error:", "Data upload failed.") + render_response_message(response, _("Error:"), _("Data upload failed.")) end end end