diff --git a/src/public/app/services/i18n.ts b/src/public/app/services/i18n.ts index 939fea000..80a9d6458 100644 --- a/src/public/app/services/i18n.ts +++ b/src/public/app/services/i18n.ts @@ -35,8 +35,9 @@ export function getAvailableLocales() { * @param localeId the locale ID to search for. * @returns the corresponding {@link Locale} or `null` if it was not found. */ -export function getLocaleById(localeId: string ) { - return locales?.find((l) => l.id === localeId); +export function getLocaleById(localeId: string | null | undefined) { + if (!localeId) return null; + return locales?.find((l) => l.id === localeId) ?? null; } export const t = i18next.t; diff --git a/src/public/app/widgets/type_widgets/read_only_text.ts b/src/public/app/widgets/type_widgets/read_only_text.ts index 20e12fd63..3aecf9764 100644 --- a/src/public/app/widgets/type_widgets/read_only_text.ts +++ b/src/public/app/widgets/type_widgets/read_only_text.ts @@ -4,6 +4,7 @@ import { applySyntaxHighlight } from "../../services/syntax_highlight.js"; import { getMermaidConfig } from "../mermaid.js"; import type FNote from "../../entities/fnote.js"; import type { EventData } from "../../components/app_context.js"; +import { getLocaleById } from "../../services/i18n.js"; const TPL = `
@@ -100,6 +101,11 @@ export default class ReadOnlyTextTypeWidget extends AbstractTextTypeWidget { // (see https://github.com/zadam/trilium/issues/1590 for example of such conflict) await libraryLoader.requireLibrary(libraryLoader.CKEDITOR); + const languageCode = note.getLabelValue("language"); + const correspondingLocale = getLocaleById(languageCode); + const isRtl = correspondingLocale?.rtl; + this.$content.attr("dir", isRtl ? "rtl" : "ltr"); + const blob = await note.getBlob(); this.$content.html(blob?.content ?? "");