Skip to content

Commit

Permalink
Use "full" localization ids throughout the code-base
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Snuffleupagus committed Aug 31, 2024
1 parent 7494dbc commit b01df28
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
20 changes: 14 additions & 6 deletions src/display/editor/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 3 additions & 1 deletion web/new_alt_text_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);
}

Expand Down
2 changes: 1 addition & 1 deletion web/password_prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class PasswordPrompt {
}
this.label.setAttribute(
"data-l10n-id",
`pdfjs-password-${passwordIncorrect ? "invalid" : "label"}`
passwordIncorrect ? "pdfjs-password-invalid" : "pdfjs-password-label"
);
}

Expand Down
8 changes: 6 additions & 2 deletions web/pdf_find_bar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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",
Expand Down

0 comments on commit b01df28

Please sign in to comment.