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(ckeditor5): translate the heading titles in the slash palette
Elian Doranc504c03f76ba
diff --git a/packages/ckeditor5/src/plugins/mention/slash_commands.spec.ts b/packages/ckeditor5/src/plugins/mention/slash_commands.spec.tsindex 567787eb03..ab28f91b3b 100644--- a/packages/ckeditor5/src/plugins/mention/slash_commands.spec.ts+++ b/packages/ckeditor5/src/plugins/mention/slash_commands.spec.ts@@ -148,6 +148,23 @@ describe("TriliumSlashCommands", () => {expect(defaults).not.toContain("heading1");});+ // The configured titles are English message ids, and CKEditor's own catalogs translate them+ // — its heading dropdown does the same. Without this the palette showed English titles+ // beside descriptions that were translated, since those went through `t()` already.+ it("translates the heading titles rather than using the configured English verbatim", async () => {+ editor = await createTestEditor(+ [ Essentials, Paragraph, Heading, BlockQuote, MentionEditing, TriliumMentionUI, TriliumSlashCommands ],+ {+ heading: { options: HEADING_OPTIONS },+ translations: [ {}, { en: { dictionary: { "Paragraph": "Paragraf", "Heading 2": "Titlu 2" } } } ]+ }+ );++ const titles = buildDefaultSlashCommands(editor).slice(0, 3).map((definition) => definition.title);++ expect(titles).toEqual([ "Paragraf", "Titlu 2", "Heading 3" ]);+ });+it("falls back to a heading-free palette in an editor that configures neither headings nor slash commands", async () => {editor = await createTestEditor([ Essentials, Paragraph, BlockQuote, MentionEditing, TriliumMentionUI, TriliumSlashCommands ]diff --git a/packages/ckeditor5/src/plugins/mention/slash_commands.ts b/packages/ckeditor5/src/plugins/mention/slash_commands.tsindex 678fe6101f..c0a343341e 100644--- a/packages/ckeditor5/src/plugins/mention/slash_commands.ts+++ b/packages/ckeditor5/src/plugins/mention/slash_commands.ts@@ -306,12 +306,17 @@ function buildHeadingSlashCommands(editor: Editor): SlashCommandDefinition[] {heading6: IconHeading6};+ // The configured titles are English message ids ("Paragraph", "Heading 2"), which CKEditor's own+ // catalogs translate — its heading dropdown runs them through `t()` for exactly this reason. The+ // palette has to do the same, or it shows English titles beside translated descriptions.+ const t = editor.locale.t;+return options.map((option) => {if (option.model === "paragraph") {return {id: "paragraph",- title: option.title,- description: editor.locale.t("Turn the current block into a paragraph."),+ title: t(option.title),+ description: t("Turn the current block into a paragraph."),aliases: [ "text", "body" ],icon: IconParagraph,commandName: "paragraph"@@ -320,7 +325,7 @@ function buildHeadingSlashCommands(editor: Editor): SlashCommandDefinition[] {return {id: option.model,- title: option.title,+ title: t(option.title),description: editor.locale.t("Turn the current block into a heading."),aliases: [ "title", option.model.replace("heading", "h") ],icon: icons[option.model] ?? IconHeading2,