Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use "full" localization ids in the AltText class (PR 18674 follow-up) #18706

Merged
merged 1 commit into from
Sep 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions src/display/editor/alt_text.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,19 @@ class AltText {

#useNewAltTextFlow = false;

static #l10nNewButton = null;

static _l10nPromise = null;

constructor(editor) {
this.#editor = editor;
this.#useNewAltTextFlow = editor._uiManager.useNewAltTextFlow;

AltText.#l10nNewButton ||= Object.freeze({
added: "pdfjs-editor-new-alt-text-added-button-label",
missing: "pdfjs-editor-new-alt-text-missing-button-label",
review: "pdfjs-editor-new-alt-text-to-review-button-label",
});
}

static initialize(l10nPromise) {
Expand All @@ -55,9 +63,7 @@ class AltText {
let msg;
if (this.#useNewAltTextFlow) {
altText.classList.add("new");
msg = await AltText._l10nPromise.get(
"pdfjs-editor-new-alt-text-missing-button-label"
);
msg = await AltText._l10nPromise.get(AltText.#l10nNewButton.missing);
} else {
msg = await AltText._l10nPromise.get(
"pdfjs-editor-alt-text-button-label"
Expand Down Expand Up @@ -235,16 +241,9 @@ class AltText {
}

if (this.#useNewAltTextFlow) {
// If we've an alt text, we get an "added".
// If we've a guessed text and the alt text has never been set, we get a
// "to-review" been set.
// Otherwise, we get a "missing".
const label = this.#label;
// TODO: Update the l10n keys to avoid this.
const type = label === "review" ? "to-review" : label;
button.classList.toggle("done", !!this.#altText);
AltText._l10nPromise
.get(`pdfjs-editor-new-alt-text-${type}-button-label`)
.get(AltText.#l10nNewButton[this.#label])
.then(msg => {
button.setAttribute("aria-label", msg);
// We can't just use button.textContent here, because it would remove
Expand Down