Skip to content

Build your personal knowledge base with Trilium Notes

feat(ckeditor5): localize the internal link button through editor.t()

Elian Doranca1c48e31d4b
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index e73ae75b84..1a14a309a1 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -3613,6 +3613,7 @@
"important": "Important",
"include-note": "Include note",
"insert-footnote-0": "Insert footnote %0",
+ "internal-trilium-link": "Internal Trilium link",
"keyboard-shortcut": "Keyboard shortcut",
"link-preview": "Link preview",
"new-footnote": "New footnote",
diff --git a/packages/ckeditor5/src/plugins/internallink.spec.ts b/packages/ckeditor5/src/plugins/internallink.spec.ts
index ca4dc5217d..54c65498b2 100644
--- a/packages/ckeditor5/src/plugins/internallink.spec.ts
+++ b/packages/ckeditor5/src/plugins/internallink.spec.ts
@@ -29,6 +29,16 @@ describe("InternalLinkPlugin", () => {
expect(triggerCommand).toHaveBeenCalledWith("addLinkToText");
});
+ it("labels the button without the shortcut, leaving that to the keystroke", () => {
+ const view = editor.ui.componentFactory.create("internalLink") as { label?: string; keystroke?: string };
+
+ // No dictionary is configured here, so `t()` renders the message id, which is the English
+ // label. The shortcut is not part of it — CKEditor appends the keystroke to the tooltip,
+ // localized per platform.
+ expect(view.label).toBe("Internal Trilium link");
+ expect(view.keystroke).toBe("CTRL+L");
+ });
+
it("wires the button to the command (enablement and execution)", () => {
const view = editor.ui.componentFactory.create("internalLink") as { isEnabled: boolean; fire(name: string): void };
const command = editor.commands.get(COMMAND_NAME);
diff --git a/packages/ckeditor5/src/plugins/internallink.ts b/packages/ckeditor5/src/plugins/internallink.ts
index b80591fe56..3a7aa3ad4f 100644
--- a/packages/ckeditor5/src/plugins/internallink.ts
+++ b/packages/ckeditor5/src/plugins/internallink.ts
@@ -12,15 +12,20 @@ export default class InternalLinkPlugin extends Plugin {
init() {
const editor = this.editor;
+ const t = editor.t;
editor.commands.add(COMMAND_NAME, new InsertInternalLinkCommand(editor));
editor.ui.componentFactory.add('internalLink', locale => {
const view = new ButtonView( locale );
+ // The shortcut is a `keystroke` rather than part of the label, so CKEditor appends it to
+ // the tooltip itself — rendered as ⌘L on macOS, where the binding really is
+ // `CommandOrControl+L`, and left out of the string translators see.
view.set( {
- label: 'Internal Trilium link (CTRL-L)',
+ label: t('Internal Trilium link'),
icon: internalLinkIcon,
+ keystroke: 'CTRL+L',
tooltip: true
} );