From b01df2881044c41cf104d5082f81dd13a5f82cef Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 31 Aug 2024 18:22:47 +0200 Subject: [PATCH] Use "full" localization ids throughout the code-base It was recently brought to my attention that using partial or generated localization ids is bad for maintainability, hence this patch goes through the code-base and replaces any such occurrences. --- src/display/editor/toolbar.js | 20 ++++++++++++++------ web/new_alt_text_manager.js | 4 +++- web/password_prompt.js | 2 +- web/pdf_find_bar.js | 8 ++++++-- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/display/editor/toolbar.js b/src/display/editor/toolbar.js index 131c6c30699c5..93a77e90fd7e6 100644 --- a/src/display/editor/toolbar.js +++ b/src/display/editor/toolbar.js @@ -26,8 +26,17 @@ class EditorToolbar { #altText = null; + static #l10nRemove = null; + constructor(editor) { this.#editor = editor; + + EditorToolbar.#l10nRemove ||= Object.freeze({ + freetext: "pdfjs-editor-remove-freetext-button", + highlight: "pdfjs-editor-remove-highlight-button", + ink: "pdfjs-editor-remove-ink-button", + stamp: "pdfjs-editor-remove-stamp-button", + }); } render() { @@ -105,20 +114,19 @@ class EditorToolbar { } #addDeleteButton() { + const { editorType, _uiManager } = this.#editor; + const button = document.createElement("button"); button.className = "delete"; button.tabIndex = 0; - button.setAttribute( - "data-l10n-id", - `pdfjs-editor-remove-${this.#editor.editorType}-button` - ); + button.setAttribute("data-l10n-id", EditorToolbar.#l10nRemove[editorType]); this.#addListenersToElement(button); button.addEventListener( "click", e => { - this.#editor._uiManager.delete(); + _uiManager.delete(); }, - { signal: this.#editor._uiManager._signal } + { signal: _uiManager._signal } ); this.#buttons.append(button); } diff --git a/web/new_alt_text_manager.js b/web/new_alt_text_manager.js index 42567161cb191..b85eefbbbec9c 100644 --- a/web/new_alt_text_manager.js +++ b/web/new_alt_text_manager.js @@ -177,7 +177,9 @@ class NewAltTextManager { this.#isEditing = isEditing; this.#title.setAttribute( "data-l10n-id", - `pdfjs-editor-new-alt-text-dialog-${isEditing ? "edit" : "add"}-label` + isEditing + ? "pdfjs-editor-new-alt-text-dialog-edit-label" + : "pdfjs-editor-new-alt-text-dialog-add-label" ); } diff --git a/web/password_prompt.js b/web/password_prompt.js index a1f84cdc1537a..6d9f41e2db1be 100644 --- a/web/password_prompt.js +++ b/web/password_prompt.js @@ -84,7 +84,7 @@ class PasswordPrompt { } this.label.setAttribute( "data-l10n-id", - `pdfjs-password-${passwordIncorrect ? "invalid" : "label"}` + passwordIncorrect ? "pdfjs-password-invalid" : "pdfjs-password-label" ); } diff --git a/web/pdf_find_bar.js b/web/pdf_find_bar.js index ebdd817fb3ce4..72147799af567 100644 --- a/web/pdf_find_bar.js +++ b/web/pdf_find_bar.js @@ -123,7 +123,9 @@ class PDFFindBar { status = "notFound"; break; case FindState.WRAPPED: - findMsgId = `pdfjs-find-reached-${previous ? "top" : "bottom"}`; + findMsgId = previous + ? "pdfjs-find-reached-top" + : "pdfjs-find-reached-bottom"; break; } findField.setAttribute("data-status", status); @@ -148,7 +150,9 @@ class PDFFindBar { findResultsCount.setAttribute( "data-l10n-id", - `pdfjs-find-match-count${total > limit ? "-limit" : ""}` + total > limit + ? "pdfjs-find-match-count-limit" + : "pdfjs-find-match-count" ); findResultsCount.setAttribute( "data-l10n-args",