mirror of
https://github.com/zadam/trilium.git
synced 2025-11-17 14:04:30 +01:00
test(canvas): test all languages are mapped correctly
This commit is contained in:
parent
7d1453ffbd
commit
497bb35209
@ -9,30 +9,12 @@ 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";
|
import { LANGUAGE_MAPPINGS } from "./i18n";
|
||||||
|
|
||||||
// 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");
|
||||||
|
|||||||
29
apps/client/src/widgets/type_widgets/canvas/i18n.spec.ts
Normal file
29
apps/client/src/widgets/type_widgets/canvas/i18n.spec.ts
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import { LOCALES } from "@triliumnext/commons";
|
||||||
|
import { readdirSync } from "fs";
|
||||||
|
import { join } from "path";
|
||||||
|
import { describe, expect, it } from "vitest";
|
||||||
|
import { LANGUAGE_MAPPINGS } from "./i18n.js";
|
||||||
|
|
||||||
|
const localeDir = join(__dirname, "../../../../../../node_modules/@excalidraw/excalidraw/dist/prod/locales");
|
||||||
|
|
||||||
|
describe("Canvas i18n", () => {
|
||||||
|
it("all languages are mapped correctly", () => {
|
||||||
|
// Read the node_modules dir to obtain all the supported locales.
|
||||||
|
const supportedLanguageCodes = new Set<string>();
|
||||||
|
for (const file of readdirSync(localeDir)) {
|
||||||
|
if (file.startsWith("percentages")) continue;
|
||||||
|
const match = file.match("^[a-z]{2,3}(?:-[A-Z]{2,3})?");
|
||||||
|
if (!match) continue;
|
||||||
|
supportedLanguageCodes.add(match[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cross-check the locales.
|
||||||
|
for (const locale of LOCALES) {
|
||||||
|
if (locale.contentOnly || locale.devOnly) continue;
|
||||||
|
const languageCode = LANGUAGE_MAPPINGS[locale.id];
|
||||||
|
if (!supportedLanguageCodes.has(languageCode)) {
|
||||||
|
expect.fail(`Unable to find locale for ${locale.id} -> ${languageCode}.`)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
19
apps/client/src/widgets/type_widgets/canvas/i18n.ts
Normal file
19
apps/client/src/widgets/type_widgets/canvas/i18n.ts
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
import type { DISPLAYABLE_LOCALE_IDS } from "@triliumnext/commons";
|
||||||
|
|
||||||
|
export 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"
|
||||||
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user