mirror of
https://github.com/zadam/trilium.git
synced 2025-11-17 14:04:30 +01:00
feat(canvas): add support for locales
This commit is contained in:
parent
89228f264f
commit
7d1453ffbd
@ -1,7 +1,7 @@
|
|||||||
import { Excalidraw } from "@excalidraw/excalidraw";
|
import { Excalidraw } from "@excalidraw/excalidraw";
|
||||||
import { TypeWidgetProps } from "../type_widget";
|
import { TypeWidgetProps } from "../type_widget";
|
||||||
import "@excalidraw/excalidraw/index.css";
|
import "@excalidraw/excalidraw/index.css";
|
||||||
import { useNoteLabelBoolean } from "../../react/hooks";
|
import { useNoteLabelBoolean, useTriliumOption } from "../../react/hooks";
|
||||||
import { useCallback, useMemo, useRef } from "preact/hooks";
|
import { useCallback, useMemo, useRef } from "preact/hooks";
|
||||||
import { type ExcalidrawImperativeAPI, type AppState } from "@excalidraw/excalidraw/types";
|
import { type ExcalidrawImperativeAPI, type AppState } from "@excalidraw/excalidraw/types";
|
||||||
import options from "../../../services/options";
|
import options from "../../../services/options";
|
||||||
@ -9,11 +9,30 @@ import "./Canvas.css";
|
|||||||
import { NonDeletedExcalidrawElement } from "@excalidraw/excalidraw/element/types";
|
import { NonDeletedExcalidrawElement } from "@excalidraw/excalidraw/element/types";
|
||||||
import { goToLinkExt } from "../../../services/link";
|
import { goToLinkExt } from "../../../services/link";
|
||||||
import useCanvasPersistence from "./persistence";
|
import useCanvasPersistence from "./persistence";
|
||||||
|
import { DISPLAYABLE_LOCALE_IDS } from "@triliumnext/commons";
|
||||||
|
|
||||||
// currently required by excalidraw, in order to allows self-hosting fonts locally.
|
// currently required by excalidraw, in order to allows self-hosting fonts locally.
|
||||||
// this avoids making excalidraw load the fonts from an external CDN.
|
// this avoids making excalidraw load the fonts from an external CDN.
|
||||||
window.EXCALIDRAW_ASSET_PATH = `${window.location.pathname}/node_modules/@excalidraw/excalidraw/dist/prod`;
|
window.EXCALIDRAW_ASSET_PATH = `${window.location.pathname}/node_modules/@excalidraw/excalidraw/dist/prod`;
|
||||||
|
|
||||||
|
const LANGUAGE_MAPPINGS: Record<DISPLAYABLE_LOCALE_IDS, string | null> = {
|
||||||
|
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) {
|
export default function Canvas({ note, noteContext }: TypeWidgetProps) {
|
||||||
const apiRef = useRef<ExcalidrawImperativeAPI>(null);
|
const apiRef = useRef<ExcalidrawImperativeAPI>(null);
|
||||||
const [ isReadOnly ] = useNoteLabelBoolean(note, "readOnly");
|
const [ isReadOnly ] = useNoteLabelBoolean(note, "readOnly");
|
||||||
@ -21,6 +40,7 @@ export default function Canvas({ note, noteContext }: TypeWidgetProps) {
|
|||||||
const documentStyle = window.getComputedStyle(document.documentElement);
|
const documentStyle = window.getComputedStyle(document.documentElement);
|
||||||
return documentStyle.getPropertyValue("--theme-style")?.trim() as AppState["theme"];
|
return documentStyle.getPropertyValue("--theme-style")?.trim() as AppState["theme"];
|
||||||
}, []);
|
}, []);
|
||||||
|
const [ locale ] = useTriliumOption("locale");
|
||||||
const persistence = useCanvasPersistence(note, noteContext, apiRef, themeStyle, isReadOnly);
|
const persistence = useCanvasPersistence(note, noteContext, apiRef, themeStyle, isReadOnly);
|
||||||
|
|
||||||
/** Use excalidraw's native zoom instead of the global zoom. */
|
/** Use excalidraw's native zoom instead of the global zoom. */
|
||||||
@ -58,6 +78,7 @@ export default function Canvas({ note, noteContext }: TypeWidgetProps) {
|
|||||||
detectScroll={false}
|
detectScroll={false}
|
||||||
handleKeyboardGlobally={false}
|
handleKeyboardGlobally={false}
|
||||||
autoFocus={false}
|
autoFocus={false}
|
||||||
|
langCode={LANGUAGE_MAPPINGS[locale]}
|
||||||
UIOptions={{
|
UIOptions={{
|
||||||
canvasActions: {
|
canvasActions: {
|
||||||
saveToActiveFile: false,
|
saveToActiveFile: false,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user