Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(i18n): stop escaping the sector list in the sync divergence toast
Elian Doranc51ca56df3d5
diff --git a/apps/client/src/services/i18n.spec.ts b/apps/client/src/services/i18n.spec.tsindex d2b7e9a8c0..0e6a4f52c6 100644--- a/apps/client/src/services/i18n.spec.ts+++ b/apps/client/src/services/i18n.spec.ts@@ -1,6 +1,7 @@import { MESSAGE_KEY_PREFIX, MESSAGE_OVERRIDES, slugify } from "@triliumnext/ckeditor5";import { dayjs, findDuplicateJsonKeys, findPluralKeyConflicts, LOCALES } from "@triliumnext/commons";import { readdirSync, readFileSync } from "fs";+import i18next from "i18next";import { join } from "path";import { afterEach, describe, expect, it, vi } from "vitest";@@ -63,6 +64,21 @@ describe("i18n", () => {}});+ // i18next HTML-escapes interpolated values by default, so a value carrying a slash, an+ // apostrophe or a quote reaches the user as `blobs/9`. Almost everything we interpolate is+ // rendered as text (a Preact child, a title attribute), where that escaping only produces+ // gibberish, which is what the unescaped `{{- value}}` form is for. There is no way to tell+ // from a catalog entry alone which one it should use, so this only covers the messages whose+ // values are known to carry such characters.+ it("interpolates values carrying special characters unescaped", async () => {+ const catalog = JSON.parse(readFileSync(join(__dirname, "..", "translations", "en", "translation.json"), { encoding: "utf-8" }));+ const i18n = i18next.createInstance();+ await i18n.init({ lng: "en", resources: { en: { translation: catalog } } });++ // Diverged sync sectors are formatted `entityName/sector`.+ expect(i18n.t("ws.sync-hash-check-failed", { sectors: "blobs/9" })).toContain("blobs/9");+ });+// The text editor localizes by passing the English text itself to the editor's translation// function, and that text resolves to `text-editor.ck.<slug>`. A string with no entry there// silently renders its English id in every locale — it is invisible to Weblate, so nodiff --git a/apps/client/src/services/ws.ts b/apps/client/src/services/ws.tsindex 19e8a52fa7..686021ffb7 100644--- a/apps/client/src/services/ws.ts+++ b/apps/client/src/services/ws.ts@@ -100,6 +100,9 @@ export async function dispatchMessage(message: WebSocketMessage) {} else if (messageType === "sync-hash-check-failed") {// Not auto-dismissed after the usual few seconds: syncing stays broken until the user acts,// and the backend only reports it once (it would otherwise recur with every sync attempt).+ // The sector list is interpolated unescaped ({{- }}) — the toast renders its message as+ // text, so i18next's HTML escaping would only turn the `entityName/sector` slash into a+ // literal `/`.toastService.showError(t("ws.sync-hash-check-failed", { sectors: (msg.sectors ?? []).join(", ") }), 50 * 60000);} else if (messageType === "consistency-checks-failed") {toastService.showError(t("ws.consistency-checks-failed"), 50 * 60000);diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex aff5120442..110073c503 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -2748,7 +2748,7 @@"backend_scripting_disabled_more_info": "More info"},"ws": {- "sync-hash-check-failed": "Sync stopped: this database and the sync server disagree on {{sectors}} and re-syncing did not resolve it. See the logs for details.",+ "sync-hash-check-failed": "Sync stopped: this database and the sync server hold data that could not be reconciled by re-syncing it ({{- sectors}}). Syncing will keep failing until this is resolved — see the logs for details.","consistency-checks-failed": "Consistency checks failed! See logs for details.","encountered-error": "Encountered error \"{{message}}\", check out the console.","lost-websocket-connection-title": "Lost connection to the server",