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

[Editor] Utilize Fluent "better" when localizing the resizer DOM-elements #18649

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
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
24 changes: 16 additions & 8 deletions l10n/en-US/viewer.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -379,14 +379,22 @@ pdfjs-editor-alt-text-textarea =
## Editor resizers
## This is used in an aria label to help to understand the role of the resizer.

pdfjs-editor-resizer-label-top-left = Top left corner — resize
pdfjs-editor-resizer-label-top-middle = Top middle — resize
pdfjs-editor-resizer-label-top-right = Top right corner — resize
pdfjs-editor-resizer-label-middle-right = Middle right — resize
pdfjs-editor-resizer-label-bottom-right = Bottom right corner — resize
pdfjs-editor-resizer-label-bottom-middle = Bottom middle — resize
pdfjs-editor-resizer-label-bottom-left = Bottom left corner — resize
pdfjs-editor-resizer-label-middle-left = Middle left — resize
pdfjs-editor-resizer-top-left =
.aria-label = Top left corner — resize
pdfjs-editor-resizer-top-middle =
.aria-label = Top middle — resize
pdfjs-editor-resizer-top-right =
.aria-label = Top right corner — resize
pdfjs-editor-resizer-middle-right =
.aria-label = Middle right — resize
pdfjs-editor-resizer-bottom-right =
.aria-label = Bottom right corner — resize
pdfjs-editor-resizer-bottom-middle =
.aria-label = Bottom middle — resize
pdfjs-editor-resizer-bottom-left =
.aria-label = Bottom left corner — resize
pdfjs-editor-resizer-middle-left =
.aria-label = Middle left — resize

## Color picker

Expand Down
36 changes: 17 additions & 19 deletions src/display/editor/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ class AnnotationEditor {

_focusEventsAllowed = true;

_l10nPromise = null;
static _l10nPromise = null;

static _l10nResizer = null;

#isDraggable = false;

Expand Down Expand Up @@ -206,6 +208,17 @@ class AnnotationEditor {
* @param {Object} l10n
*/
static initialize(l10n, _uiManager, options) {
AnnotationEditor._l10nResizer ||= Object.freeze({
topLeft: "pdfjs-editor-resizer-top-left",
topMiddle: "pdfjs-editor-resizer-top-middle",
topRight: "pdfjs-editor-resizer-top-right",
middleRight: "pdfjs-editor-resizer-middle-right",
bottomRight: "pdfjs-editor-resizer-bottom-right",
bottomMiddle: "pdfjs-editor-resizer-bottom-middle",
bottomLeft: "pdfjs-editor-resizer-bottom-left",
middleLeft: "pdfjs-editor-resizer-middle-left",
});

AnnotationEditor._l10nPromise ||= new Map(
[
"pdfjs-editor-alt-text-button-label",
Expand All @@ -214,18 +227,7 @@ class AnnotationEditor {
"pdfjs-editor-new-alt-text-added-button-label",
"pdfjs-editor-new-alt-text-missing-button-label",
"pdfjs-editor-new-alt-text-to-review-button-label",
"pdfjs-editor-resizer-label-topLeft",
"pdfjs-editor-resizer-label-topMiddle",
"pdfjs-editor-resizer-label-topRight",
"pdfjs-editor-resizer-label-middleRight",
"pdfjs-editor-resizer-label-bottomRight",
"pdfjs-editor-resizer-label-bottomMiddle",
"pdfjs-editor-resizer-label-bottomLeft",
"pdfjs-editor-resizer-label-middleLeft",
].map(str => [
str,
l10n.get(str.replaceAll(/([A-Z])/g, c => `-${c.toLowerCase()}`)),
])
].map(str => [str, l10n.get(str)])
);

// The string isn't in the above list because the string has a parameter
Expand Down Expand Up @@ -1480,9 +1482,7 @@ class AnnotationEditor {
div.addEventListener("focus", this.#resizerFocus.bind(this, name), {
signal,
});
AnnotationEditor._l10nPromise
.get(`pdfjs-editor-resizer-label-${name}`)
.then(msg => div.setAttribute("aria-label", msg));
div.setAttribute("data-l10n-id", AnnotationEditor._l10nResizer[name]);
}
}

Expand Down Expand Up @@ -1517,9 +1517,7 @@ class AnnotationEditor {
for (const child of children) {
const div = this.#allResizerDivs[i++];
const name = div.getAttribute("data-resizer-name");
AnnotationEditor._l10nPromise
.get(`pdfjs-editor-resizer-label-${name}`)
.then(msg => child.setAttribute("aria-label", msg));
child.setAttribute("data-l10n-id", AnnotationEditor._l10nResizer[name]);
}
}

Expand Down