From 26e4decaece24a6916c37fef68dbd320d2ef4557 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 20 Oct 2024 02:19:47 +0300 Subject: [PATCH] i18n: Translate toast errors --- src/public/app/components/entrypoints.js | 2 +- src/public/app/services/branches.js | 6 +++--- .../app/services/frontend_script_api.js | 6 ++---- src/public/app/services/import.js | 2 +- src/public/app/services/protected_session.js | 2 +- src/public/app/services/ws.js | 6 +++--- src/public/translations/en/translation.json | 21 ++++++++++++++++--- src/public/translations/ro/translation.json | 21 ++++++++++++++++--- 8 files changed, 47 insertions(+), 19 deletions(-) diff --git a/src/public/app/components/entrypoints.js b/src/public/app/components/entrypoints.js index 3d6c2c2f1..c5fd96e28 100644 --- a/src/public/app/components/entrypoints.js +++ b/src/public/app/components/entrypoints.js @@ -172,7 +172,7 @@ export default class Entrypoints extends Component { const resp = await server.post(`sql/execute/${note.noteId}`); if (!resp.success) { - toastService.showError(`Error occurred while executing SQL query: ${resp.error}`); + toastService.showError(t("entrypoints.sql-error", { message: resp.error })); } await appContext.triggerEvent('sqlQueryResults', {ntxId: ntxId, results: resp.results}); diff --git a/src/public/app/services/branches.js b/src/public/app/services/branches.js index 64281d361..1f70556ed 100644 --- a/src/public/app/services/branches.js +++ b/src/public/app/services/branches.js @@ -13,7 +13,7 @@ async function moveBeforeBranch(branchIdsToMove, beforeBranchId) { const beforeBranch = froca.getBranch(beforeBranchId); if (['root', '_lbRoot', '_lbAvailableLaunchers', '_lbVisibleLaunchers'].includes(beforeBranch.noteId)) { - toastService.showError('Cannot move notes here.'); + toastService.showError(t("branches.cannot-move-notes-here")); return; } @@ -42,7 +42,7 @@ async function moveAfterBranch(branchIdsToMove, afterBranchId) { ]; if (forbiddenNoteIds.includes(afterNote.noteId)) { - toastService.showError('Cannot move notes here.'); + toastService.showError(t("branches.cannot-move-notes-here")); return; } @@ -62,7 +62,7 @@ async function moveToParentNote(branchIdsToMove, newParentBranchId) { const newParentBranch = froca.getBranch(newParentBranchId); if (newParentBranch.noteId === '_lbRoot') { - toastService.showError('Cannot move notes here.'); + toastService.showError(t("branches.cannot-move-notes-here")); return; } diff --git a/src/public/app/services/frontend_script_api.js b/src/public/app/services/frontend_script_api.js index 1cc79e10f..5af37876a 100644 --- a/src/public/app/services/frontend_script_api.js +++ b/src/public/app/services/frontend_script_api.js @@ -217,8 +217,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain */ this.runOnBackend = async (func, params = []) => { if (func?.constructor.name === "AsyncFunction" || func?.startsWith?.("async ")) { - toastService.showError("You're passing an async function to api.runOnBackend() which will likely not work as you intended. " - + "Either make the function synchronous (by removing 'async' keyword), or use api.runAsyncOnBackendWithManualTransactionHandling()"); + toastService.showError(t("frontend_script_api.async_warning")); } return await this.__runOnBackendInner(func, params, true); @@ -240,8 +239,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain */ this.runAsyncOnBackendWithManualTransactionHandling = async (func, params = []) => { if (func?.constructor.name === "Function" || func?.startsWith?.("function")) { - toastService.showError("You're passing a synchronous function to api.runAsyncOnBackendWithManualTransactionHandling(), " + - "while you should likely use api.runOnBackend() instead."); + toastService.showError(t("frontend_script_api.sync_warning")); } return await this.__runOnBackendInner(func, params, false); diff --git a/src/public/app/services/import.js b/src/public/app/services/import.js index 85f197a58..715380ed8 100644 --- a/src/public/app/services/import.js +++ b/src/public/app/services/import.js @@ -36,7 +36,7 @@ export async function uploadFiles(entityType, parentNoteId, files, options) { type: 'POST', timeout: 60 * 60 * 1000, error: function (xhr) { - toastService.showError(`Import failed: ${xhr.responseText}`); + toastService.showError(t("import.failed", { message: xhr.responseText })); }, contentType: false, // NEEDED, DON'T REMOVE THIS processData: false, // NEEDED, DON'T REMOVE THIS diff --git a/src/public/app/services/protected_session.js b/src/public/app/services/protected_session.js index 24422638d..cf52639b4 100644 --- a/src/public/app/services/protected_session.js +++ b/src/public/app/services/protected_session.js @@ -50,7 +50,7 @@ async function setupProtectedSession(password) { const response = await server.post('login/protected', { password: password }); if (!response.success) { - toastService.showError("Wrong password.", 3000); + toastService.showError(t("protected_session.wrong_password"), 3000); return; } diff --git a/src/public/app/services/ws.js b/src/public/app/services/ws.js index a5fbe60a3..de79632ca 100644 --- a/src/public/app/services/ws.js +++ b/src/public/app/services/ws.js @@ -114,10 +114,10 @@ async function handleMessage(event) { await executeFrontendUpdate(message.data.entityChanges); } else if (message.type === 'sync-hash-check-failed') { - toastService.showError("Sync check failed!", 60000); + toastService.showError(t("ws.sync-check-failed"), 60000); } else if (message.type === 'consistency-checks-failed') { - toastService.showError("Consistency checks failed! See logs for details.", 50 * 60000); + toastService.showError(t("ws.consistency-checks-failed"), 50 * 60000); } else if (message.type === 'api-log-messages') { appContext.triggerEvent("apiLogMessages", {noteId: message.noteId, messages: message.messages}); @@ -189,7 +189,7 @@ async function consumeFrontendUpdateData() { else { console.log("nonProcessedEntityChanges causing the timeout", nonProcessedEntityChanges); - toastService.showError(`Encountered error "${e.message}", check out the console.`); + toastService.showError(t("ws.encountered-error", { message: e.message })); } } diff --git a/src/public/translations/en/translation.json b/src/public/translations/en/translation.json index fe5990dc5..8f35f177b 100644 --- a/src/public/translations/en/translation.json +++ b/src/public/translations/en/translation.json @@ -166,7 +166,8 @@ "textImportedAsText": "Import HTML, Markdown and TXT as text notes if it's unclear from metadata", "codeImportedAsCode": "Import recognized code files (e.g. .json) as code notes if it's unclear from metadata", "replaceUnderscoresWithSpaces": "Replace underscores with spaces in imported note names", - "import": "Import" + "import": "Import", + "failed": "Import failed: {{message}}." }, "include_note": { "dialog_title": "Include note", @@ -924,7 +925,8 @@ "protected_session": { "enter_password_instruction": "Showing protected note requires entering your password:", "start_session_button": "Start protected session", - "started": "Protected session has been started." + "started": "Protected session has been started.", + "wrong_password": "Wrong password." }, "relation_map": { "open_in_new_tab": "Open in new tab", @@ -1446,6 +1448,19 @@ }, "entrypoints": { "note-revision-created": "Note revision has been created.", - "note-executed": "Note executed." + "note-executed": "Note executed.", + "sql-error": "Error occurred while executing SQL query: {{message}}" + }, + "branches": { + "cannot-move-notes-here": "Cannot move notes here." + }, + "frontend_script_api": { + "async_warning": "You're passing an async function to `api.runOnBackend()` which will likely not work as you intended.\\nEither make the function synchronous (by removing `async` keyword), or use `api.runAsyncOnBackendWithManualTransactionHandling()`.", + "sync_warning": "You're passing a synchronous function to `api.runAsyncOnBackendWithManualTransactionHandling()`,\\nwhile you should likely use `api.runOnBackend()` instead." + }, + "ws": { + "sync-check-failed": "Sync check failed!", + "consistency-checks-failed": "Consistency checks failed! See logs for details.", + "encountered-error": "Encountered error \"{{message}}\", check out the console." } } diff --git a/src/public/translations/ro/translation.json b/src/public/translations/ro/translation.json index 8df347a83..de59c8c50 100644 --- a/src/public/translations/ro/translation.json +++ b/src/public/translations/ro/translation.json @@ -685,7 +685,8 @@ "safeImportTooltip": "Fișierele de Trilium exportate în format .zip pot conține scripturi executabile ce pot avea un comportament malițios. Importarea sigură va dezactiva execuția automată a tuturor scripturilor importate. Debifați „Importare sigură” dacă arhiva importată conține scripturi executabile dorite și aveți încredere deplină în conținutul acestora.", "shrinkImages": "Micșorare imagini", "shrinkImagesTooltip": "

Dacă bifați această opțiune, Trilium va încerca să micșoreze imaginea importată prin scalarea și importarea ei, aspect ce poate afecta calitatea aparentă a imaginii. Dacă nu este bifat, imaginile vor fi importate fără nicio modificare.

Acest lucru nu se aplică la importuri de tip .zip cu metainformații deoarece se asumă că aceste fișiere sunt deja optimizate.

", - "textImportedAsText": "Importă HTML, Markdown și TXT ca notițe de tip text dacă este neclar din metainformații" + "textImportedAsText": "Importă HTML, Markdown și TXT ca notițe de tip text dacă este neclar din metainformații", + "failed": "Eroare la importare: {{message}}." }, "include_archived_notes": { "include_archived_notes": "Include notițele arhivate" @@ -906,7 +907,8 @@ "protected_session": { "enter_password_instruction": "Afișarea notițelor protejate necesită introducerea parolei:", "start_session_button": "Deschide sesiunea protejată", - "started": "Sesiunea protejată este activă." + "started": "Sesiunea protejată este activă.", + "wrong_password": "Parolă greșită." }, "protected_session_password": { "close_label": "Închide", @@ -1439,7 +1441,8 @@ }, "entrypoints": { "note-executed": "Notița a fost executată.", - "note-revision-created": "S-a creat o revizie a notiței." + "note-revision-created": "S-a creat o revizie a notiței.", + "sql-error": "A apărut o eroare la executarea interogării SQL: {{message}}" }, "image": { "cannot-copy": "Nu s-a putut copia în clipboard referința către imagine.", @@ -1447,5 +1450,17 @@ }, "note_create": { "duplicated": "Notița „{{title}}” a fost dublificată." + }, + "branches": { + "cannot-move-notes-here": "Nu se pot muta notițe aici." + }, + "frontend_script_api": { + "async_warning": "Ați trimis o funcție asincronă metodei `api.runOnBackend()` și este posibil să nu se comporte așa cum vă așteptați.\\nFie faceți metoda sincronă (prin ștergerea cuvântului-cheie `async`), sau folosiți `api.runAsyncOnBackendWithManualTransactionHandling()`.", + "sync_warning": "Ați trimis o funcție sincronă funcției `api.runAsyncOnBackendWithManualTransactionHandling()`,\\ndar cel mai probabil trebuie folosit `api.runOnBackend()` în schimb." + }, + "ws": { + "consistency-checks-failed": "Au fost identificate erori de consistență! Vedeți mai multe detalii în loguri.", + "encountered-error": "A fost întâmpinată o eroare: „{{message}}”. Vedeți în loguri pentru mai multe detalii.", + "sync-check-failed": "Verificările de sincronizare au eșuat!" } }