Skip to content

Build your personal knowledge base with Trilium Notes

feat(ckeditor5): localize the copy and upload cancel buttons

Elian Doran5c22acef4a09
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index 87e53d3c95..842a9d1b4f 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -3582,6 +3582,7 @@
"copy-anchor-reference-link": "Copy anchor reference link",
"copy-formatting": "Copy formatting",
"copy-image-to-clipboard": "Copy image to clipboard",
+ "copy-to-clipboard": "Copy 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",
diff --git a/packages/ckeditor5/src/plugins/copy_to_clipboard_button.spec.ts b/packages/ckeditor5/src/plugins/copy_to_clipboard_button.spec.ts
index 523e671493..4d7983d79f 100644
--- a/packages/ckeditor5/src/plugins/copy_to_clipboard_button.spec.ts
+++ b/packages/ckeditor5/src/plugins/copy_to_clipboard_button.spec.ts
@@ -17,9 +17,12 @@ describe("CopyToClipboardButton", () => {
expect(editor.ui.componentFactory.has("copyToClipboard")).toBe(true);
});
- it("creates a button with the correct tooltip", () => {
- const button = editor.ui.componentFactory.create("copyToClipboard") as { tooltip: string; fire(name: string): void };
- expect(button.tooltip).toBe("Copy to clipboard");
+ // No dictionary is configured here, so `t()` renders the message id, which is the English
+ // label. The label doubles as the tooltip and as the icon-only button's accessible name.
+ it("creates a button labelled for the tooltip and for screen readers", () => {
+ const button = editor.ui.componentFactory.create("copyToClipboard") as { label: string; tooltip: boolean };
+ expect(button.label).toBe("Copy to clipboard");
+ expect(button.tooltip).toBe(true);
});
it("wires the button to execute the copyToClipboard command", () => {
diff --git a/packages/ckeditor5/src/plugins/copy_to_clipboard_button.ts b/packages/ckeditor5/src/plugins/copy_to_clipboard_button.ts
index 8f82d15e75..6ca9fd5e9b 100644
--- a/packages/ckeditor5/src/plugins/copy_to_clipboard_button.ts
+++ b/packages/ckeditor5/src/plugins/copy_to_clipboard_button.ts
@@ -10,8 +10,11 @@ export default class CopyToClipboardButton extends Plugin {
const componentFactory = editor.ui.componentFactory;
componentFactory.add("copyToClipboard", locale => {
const button = new ButtonView(locale);
+ // A `label` rather than a literal `tooltip` string: the tooltip reads the same, and the
+ // icon-only button gains the accessible name it had no way to expose before.
button.set({
- tooltip: "Copy to clipboard",
+ label: editor.t("Copy to clipboard"),
+ tooltip: true,
icon: copyIcon
});
diff --git a/packages/ckeditor5/src/plugins/file_upload/progressbarview.ts b/packages/ckeditor5/src/plugins/file_upload/progressbarview.ts
index 115e91c528..3c59e53bf5 100644
--- a/packages/ckeditor5/src/plugins/file_upload/progressbarview.ts
+++ b/packages/ckeditor5/src/plugins/file_upload/progressbarview.ts
@@ -56,7 +56,9 @@ export default class ProgressBarView extends View {
view.set({
icon: IconCancel,
tooltip: true,
- label: 'Cancel',
+ // An upstream message, so CKEditor's own catalog translates it — the editor package
+ // deliberately declares no entry of its own for it.
+ label: locale.t('Cancel'),
//@ts-expect-error Object literal may only specify known properties, and 'attributes' does not exist in type
attributes: {
class: ['ck', 'ck-button', 'ck-off', 'ck-button-cancel', 'ck-uploading-cancel']