From 7d1453ffbdb9e6bdd2ac8be68cd58e38e21d2102 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sun, 16 Nov 2025 17:49:55 +0200 Subject: [PATCH] feat(canvas): add support for locales --- .../widgets/type_widgets/canvas/Canvas.tsx | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/apps/client/src/widgets/type_widgets/canvas/Canvas.tsx b/apps/client/src/widgets/type_widgets/canvas/Canvas.tsx index 79f7f3795..968c5c994 100644 --- a/apps/client/src/widgets/type_widgets/canvas/Canvas.tsx +++ b/apps/client/src/widgets/type_widgets/canvas/Canvas.tsx @@ -1,7 +1,7 @@ import { Excalidraw } from "@excalidraw/excalidraw"; import { TypeWidgetProps } from "../type_widget"; import "@excalidraw/excalidraw/index.css"; -import { useNoteLabelBoolean } from "../../react/hooks"; +import { useNoteLabelBoolean, useTriliumOption } from "../../react/hooks"; import { useCallback, useMemo, useRef } from "preact/hooks"; import { type ExcalidrawImperativeAPI, type AppState } from "@excalidraw/excalidraw/types"; import options from "../../../services/options"; @@ -9,11 +9,30 @@ import "./Canvas.css"; import { NonDeletedExcalidrawElement } from "@excalidraw/excalidraw/element/types"; import { goToLinkExt } from "../../../services/link"; import useCanvasPersistence from "./persistence"; +import { DISPLAYABLE_LOCALE_IDS } from "@triliumnext/commons"; // currently required by excalidraw, in order to allows self-hosting fonts locally. // this avoids making excalidraw load the fonts from an external CDN. window.EXCALIDRAW_ASSET_PATH = `${window.location.pathname}/node_modules/@excalidraw/excalidraw/dist/prod`; +const LANGUAGE_MAPPINGS: Record = { + ar: "ar-SA", + cn: "zh-CN", + de: "de-DE", + en: "en", + en_rtl: "en", + es: "es-ES", + fr: "fr-FR", + it: "it-IT", + ja: "ja-JP", + pt: "pt-PT", + pt_br: "pt-BR", + ro: "ro-RO", + ru: "ru-RU", + tw: "zh-TW", + uk: "uk-UA" +}; + export default function Canvas({ note, noteContext }: TypeWidgetProps) { const apiRef = useRef(null); const [ isReadOnly ] = useNoteLabelBoolean(note, "readOnly"); @@ -21,6 +40,7 @@ export default function Canvas({ note, noteContext }: TypeWidgetProps) { const documentStyle = window.getComputedStyle(document.documentElement); return documentStyle.getPropertyValue("--theme-style")?.trim() as AppState["theme"]; }, []); + const [ locale ] = useTriliumOption("locale"); const persistence = useCanvasPersistence(note, noteContext, apiRef, themeStyle, isReadOnly); /** Use excalidraw's native zoom instead of the global zoom. */ @@ -58,6 +78,7 @@ export default function Canvas({ note, noteContext }: TypeWidgetProps) { detectScroll={false} handleKeyboardGlobally={false} autoFocus={false} + langCode={LANGUAGE_MAPPINGS[locale]} UIOptions={{ canvasActions: { saveToActiveFile: false,