[Editor] Avoid "generating" the l10n-ids used for the a11yAlert

In the `DrawingEditor.prototype.#createDrawOutlines` method the l10n-id was being "generated", which is bad for maintainability since searching for l10n-id becomes more difficult and the `gulp check_l10n` script actually warns about this.

Hence, similar to e.g. the resizer localization, let's define the `a11yAlert` l10n-ids *once* and provide shorthands for accessing them.
This commit is contained in:
Jonas Jenwald 2026-05-12 16:31:00 +02:00
parent 0c66063cd4
commit 4072d3f835
5 changed files with 15 additions and 5 deletions

View File

@ -113,7 +113,7 @@ class DrawingEditor extends AnnotationEditor {
this.#drawOutlines = drawOutlines;
this._drawingOptions ||= drawingOptions;
if (!this.annotationElementId) {
this._uiManager.a11yAlert(`pdfjs-editor-${this.editorType}-added-alert`);
this._uiManager.a11yAlert(AnnotationEditor._l10nAlert[this.editorType]);
}
if (drawId >= 0) {

View File

@ -109,6 +109,8 @@ class AnnotationEditor {
static _l10n = null;
static _l10nAlert = null;
static _l10nResizer = null;
#isDraggable = false;
@ -247,7 +249,15 @@ class AnnotationEditor {
static initialize(l10n, _uiManager) {
AnnotationEditor._l10n ??= l10n;
AnnotationEditor._l10nResizer ||= Object.freeze({
AnnotationEditor._l10nAlert ??= Object.freeze({
highlight: "pdfjs-editor-highlight-added-alert",
freetext: "pdfjs-editor-freetext-added-alert",
ink: "pdfjs-editor-ink-added-alert",
stamp: "pdfjs-editor-stamp-added-alert",
signature: "pdfjs-editor-signature-added-alert",
});
AnnotationEditor._l10nResizer ??= Object.freeze({
topLeft: "pdfjs-editor-resizer-top-left",
topMiddle: "pdfjs-editor-resizer-top-middle",
topRight: "pdfjs-editor-resizer-top-right",

View File

@ -133,7 +133,7 @@ class FreeTextEditor extends AnnotationEditor {
AnnotationEditor._defaultLineColor;
this.#fontSize = params.fontSize || FreeTextEditor._defaultFontSize;
if (!this.annotationElementId) {
this._uiManager.a11yAlert("pdfjs-editor-freetext-added-alert");
this._uiManager.a11yAlert(AnnotationEditor._l10nAlert.freetext);
}
this.canAddComment = false;
}

View File

@ -128,7 +128,7 @@ class HighlightEditor extends AnnotationEditor {
}
if (!this.annotationElementId) {
this._uiManager.a11yAlert("pdfjs-editor-highlight-added-alert");
this._uiManager.a11yAlert(AnnotationEditor._l10nAlert.highlight);
}
}

View File

@ -483,7 +483,7 @@ class StampEditor extends AnnotationEditor {
this.div.setAttribute("aria-description", this.#bitmapFileName);
}
if (!this.annotationElementId) {
this._uiManager.a11yAlert("pdfjs-editor-stamp-added-alert");
this._uiManager.a11yAlert(AnnotationEditor._l10nAlert.stamp);
}
}