Skip to content

Build your personal knowledge base with Trilium Notes

feat(ckeditor5): move the copy URL button off the translation-key bridge

Elian Doranc4af97100ee4
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 9d359498f8..8307f26ff0 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -2682,8 +2682,7 @@
"copy_image_to_clipboard": "Copy image to clipboard"
},
"link": {
- "failed_to_open": "Failed to open link '{{- href}}': {{- message}}",
- "copy_url": "Copy URL"
+ "failed_to_open": "Failed to open link '{{- href}}': {{- message}}"
},
"link_embed": {
"play_video": "Play video",
@@ -3594,6 +3593,7 @@
"collapsible-block": "Collapsible block",
"copy-formatting": "Copy formatting",
"copy-image-to-clipboard": "Copy image to clipboard",
+ "copy-url": "Copy URL",
"create-a-bulleted-list": "Create a bulleted list",
"create-a-new-footnote-and-reference-it-here": "Create a new footnote and reference it here",
"create-a-numbered-list": "Create a numbered list",
diff --git a/packages/ckeditor5/src/plugins/copy_link_url.spec.ts b/packages/ckeditor5/src/plugins/copy_link_url.spec.ts
index bf730f4415..e9f277bbb6 100644
--- a/packages/ckeditor5/src/plugins/copy_link_url.spec.ts
+++ b/packages/ckeditor5/src/plugins/copy_link_url.spec.ts
@@ -137,23 +137,24 @@ describe("CopyLinkUrlButton", () => {
});
});
- describe("_translate", () => {
- it("uses the translate function from config when provided", async () => {
- const translateFn = vi.fn((key: string) => `translated:${key}`);
+ describe("label", () => {
+ it("comes from the editor's dictionary when one is configured", async () => {
+ // Keyed by `en`, the language the editor resolves messages under when none is configured.
editor = await createEditor({
- translate: translateFn
+ translations: [ {}, { en: { dictionary: { "Copy URL": "Copiază adresa" } } } ]
});
const button = editor.ui.componentFactory.create("copyLinkUrl") as { label: string };
- expect(translateFn).toHaveBeenCalledWith("link.copy_url");
- expect(button.label).toBe("translated:link.copy_url");
+ expect(button.label).toBe("Copiază adresa");
});
- it("returns the key as-is when no translate function is in config", async () => {
+ // No dictionary is configured here, so `t()` renders the message id, which is the English
+ // label — never a raw `link.…` key, as the retired host bridge would have shown.
+ it("is the English message id when no dictionary is configured", async () => {
editor = await createEditor();
const button = editor.ui.componentFactory.create("copyLinkUrl") as { label: string };
- expect(button.label).toBe("link.copy_url");
+ expect(button.label).toBe("Copy URL");
});
});
});
diff --git a/packages/ckeditor5/src/plugins/copy_link_url.ts b/packages/ckeditor5/src/plugins/copy_link_url.ts
index 4148c35130..9c500680be 100644
--- a/packages/ckeditor5/src/plugins/copy_link_url.ts
+++ b/packages/ckeditor5/src/plugins/copy_link_url.ts
@@ -9,7 +9,7 @@ import copyIcon from "../icons/copy.svg?raw";
export function createCopyUrlButton(editor: Editor, locale: Locale, getUrl: () => string | null | undefined): ButtonView {
const button = new ButtonView(locale);
button.set({
- label: translate(editor, "link.copy_url"),
+ label: editor.t("Copy URL"),
icon: copyIcon,
tooltip: true
});
@@ -24,11 +24,6 @@ export function createCopyUrlButton(editor: Editor, locale: Locale, getUrl: () =
return button;
}
-function translate(editor: Editor, key: string) {
- const translateFn = editor.config.get("translate") as ((key: string) => string) | undefined;
- return translateFn ? translateFn(key) : key;
-}
-
/**
* Adds a "Copy URL" button to the link balloon toolbar, placed right after the URL preview.
* Copies the selected link's href to the clipboard via the host-provided `clipboard.copy`
diff --git a/packages/ckeditor5/src/plugins/link_embed/link_embed_toolbar.spec.ts b/packages/ckeditor5/src/plugins/link_embed/link_embed_toolbar.spec.ts
index c17d698817..634ad7de6d 100644
--- a/packages/ckeditor5/src/plugins/link_embed/link_embed_toolbar.spec.ts
+++ b/packages/ckeditor5/src/plugins/link_embed/link_embed_toolbar.spec.ts
@@ -625,11 +625,11 @@ describe("LinkEmbedToolbar", () => {
beforeEach(async () => {
copy = vi.fn();
- // The copy button reaches the host through these two config entries, which the editor
- // config type does not declare (the host sets them the same way, via a cast).
+ // The copy button reaches the host through `clipboard`, which the editor config type
+ // does not declare (the host sets it the same way, via a cast). Its label comes from
+ // the editor's own dictionary, not from the host.
const hostConfig = {
- clipboard: { copy },
- translate: (key: string) => `translated:${key}`
+ clipboard: { copy }
} as unknown as Parameters<typeof createTestEditor>[1];
editor = await createTestEditor([Essentials, Paragraph, LinkEmbed, LinkEmbedToolbar], hostConfig);
@@ -669,7 +669,7 @@ describe("LinkEmbedToolbar", () => {
it("linkEmbedCopyUrl copies the selected widget's URL through the host clipboard", () => {
const button = createButton("linkEmbedCopyUrl");
- expect(button.label).toBe("translated:link.copy_url");
+ expect(button.label).toBe("Copy URL");
// With nothing selected there is no URL, so nothing is copied.
button.fire("execute");