Skip to content

Commit e9a319b

Browse files
Merge pull request #18649 from Snuffleupagus/resizers-fluent
[Editor] Utilize Fluent "better" when localizing the resizer DOM-elements
2 parents b58c24a + ac75a05 commit e9a319b

File tree

2 files changed

+33
-27
lines changed

2 files changed

+33
-27
lines changed

l10n/en-US/viewer.ftl

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -379,14 +379,22 @@ pdfjs-editor-alt-text-textarea =
379379
## Editor resizers
380380
## This is used in an aria label to help to understand the role of the resizer.
381381

382-
pdfjs-editor-resizer-label-top-left = Top left corner — resize
383-
pdfjs-editor-resizer-label-top-middle = Top middle — resize
384-
pdfjs-editor-resizer-label-top-right = Top right corner — resize
385-
pdfjs-editor-resizer-label-middle-right = Middle right — resize
386-
pdfjs-editor-resizer-label-bottom-right = Bottom right corner — resize
387-
pdfjs-editor-resizer-label-bottom-middle = Bottom middle — resize
388-
pdfjs-editor-resizer-label-bottom-left = Bottom left corner — resize
389-
pdfjs-editor-resizer-label-middle-left = Middle left — resize
382+
pdfjs-editor-resizer-top-left =
383+
.aria-label = Top left corner — resize
384+
pdfjs-editor-resizer-top-middle =
385+
.aria-label = Top middle — resize
386+
pdfjs-editor-resizer-top-right =
387+
.aria-label = Top right corner — resize
388+
pdfjs-editor-resizer-middle-right =
389+
.aria-label = Middle right — resize
390+
pdfjs-editor-resizer-bottom-right =
391+
.aria-label = Bottom right corner — resize
392+
pdfjs-editor-resizer-bottom-middle =
393+
.aria-label = Bottom middle — resize
394+
pdfjs-editor-resizer-bottom-left =
395+
.aria-label = Bottom left corner — resize
396+
pdfjs-editor-resizer-middle-left =
397+
.aria-label = Middle left — resize
390398
391399
## Color picker
392400

src/display/editor/editor.js

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ class AnnotationEditor {
8686

8787
_focusEventsAllowed = true;
8888

89-
_l10nPromise = null;
89+
static _l10nPromise = null;
90+
91+
static _l10nResizer = null;
9092

9193
#isDraggable = false;
9294

@@ -206,6 +208,17 @@ class AnnotationEditor {
206208
* @param {Object} l10n
207209
*/
208210
static initialize(l10n, _uiManager, options) {
211+
AnnotationEditor._l10nResizer ||= Object.freeze({
212+
topLeft: "pdfjs-editor-resizer-top-left",
213+
topMiddle: "pdfjs-editor-resizer-top-middle",
214+
topRight: "pdfjs-editor-resizer-top-right",
215+
middleRight: "pdfjs-editor-resizer-middle-right",
216+
bottomRight: "pdfjs-editor-resizer-bottom-right",
217+
bottomMiddle: "pdfjs-editor-resizer-bottom-middle",
218+
bottomLeft: "pdfjs-editor-resizer-bottom-left",
219+
middleLeft: "pdfjs-editor-resizer-middle-left",
220+
});
221+
209222
AnnotationEditor._l10nPromise ||= new Map(
210223
[
211224
"pdfjs-editor-alt-text-button-label",
@@ -214,18 +227,7 @@ class AnnotationEditor {
214227
"pdfjs-editor-new-alt-text-added-button-label",
215228
"pdfjs-editor-new-alt-text-missing-button-label",
216229
"pdfjs-editor-new-alt-text-to-review-button-label",
217-
"pdfjs-editor-resizer-label-topLeft",
218-
"pdfjs-editor-resizer-label-topMiddle",
219-
"pdfjs-editor-resizer-label-topRight",
220-
"pdfjs-editor-resizer-label-middleRight",
221-
"pdfjs-editor-resizer-label-bottomRight",
222-
"pdfjs-editor-resizer-label-bottomMiddle",
223-
"pdfjs-editor-resizer-label-bottomLeft",
224-
"pdfjs-editor-resizer-label-middleLeft",
225-
].map(str => [
226-
str,
227-
l10n.get(str.replaceAll(/([A-Z])/g, c => `-${c.toLowerCase()}`)),
228-
])
230+
].map(str => [str, l10n.get(str)])
229231
);
230232

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

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

0 commit comments

Comments
 (0)