diff --git a/l10n/en-US/viewer.ftl b/l10n/en-US/viewer.ftl index a0106b506..2193f51c6 100644 --- a/l10n/en-US/viewer.ftl +++ b/l10n/en-US/viewer.ftl @@ -218,11 +218,13 @@ pdfjs-additional-layers = Additional Layers # Variables: # $page (Number) - the page number -pdfjs-thumb-page-title = Page { $page } +pdfjs-thumb-page-title = + .title = Page { $page } # Variables: # $page (Number) - the page number -pdfjs-thumb-page-canvas = Thumbnail of Page { $page } +pdfjs-thumb-page-canvas = + .aria-label = Thumbnail of Page { $page } ## Find panel button title and messages @@ -276,7 +278,8 @@ pdfjs-page-scale-percent = { $scale }% # Variables: # $page (Number) - the page number -pdfjs-page-landmark = Page { $page } +pdfjs-page-landmark = + .aria-label = Page { $page } ## Loading indicator messages diff --git a/src/display/annotation_layer.js b/src/display/annotation_layer.js index 49651d7eb..d00863d70 100644 --- a/src/display/annotation_layer.js +++ b/src/display/annotation_layer.js @@ -983,8 +983,11 @@ class TextAnnotationElement extends AnnotationElement { "annotation-" + this.data.name.toLowerCase() + ".svg"; - image.dataset.l10nId = "pdfjs-text-annotation-type"; - image.dataset.l10nArgs = JSON.stringify({ type: this.data.name }); + image.setAttribute("data-l10n-id", "pdfjs-text-annotation-type"); + image.setAttribute( + "data-l10n-args", + JSON.stringify({ type: this.data.name }) + ); if (!this.data.popupRef && this.hasPopupData) { this._createPopup(); @@ -2158,11 +2161,17 @@ class PopupElement { if (this.#dateObj) { const modificationDate = document.createElement("span"); modificationDate.classList.add("popupDate"); - modificationDate.dataset.l10nId = "pdfjs-annotation-date-string"; - modificationDate.dataset.l10nArgs = JSON.stringify({ - date: this.#dateObj.toLocaleDateString(), - time: this.#dateObj.toLocaleTimeString(), - }); + modificationDate.setAttribute( + "data-l10n-id", + "pdfjs-annotation-date-string" + ); + modificationDate.setAttribute( + "data-l10n-args", + JSON.stringify({ + date: this.#dateObj.toLocaleDateString(), + time: this.#dateObj.toLocaleTimeString(), + }) + ); header.append(modificationDate); } @@ -2889,14 +2898,12 @@ class AnnotationLayer { div, accessibilityManager, annotationCanvasMap, - l10n, page, viewport, }) { this.div = div; this.#accessibilityManager = accessibilityManager; this.#annotationCanvasMap = annotationCanvasMap; - this.l10n = l10n; this.page = page; this.viewport = viewport; this.zIndex = 0; diff --git a/test/driver.js b/test/driver.js index bc4c5f693..e91ee9cc9 100644 --- a/test/driver.js +++ b/test/driver.js @@ -25,8 +25,7 @@ const { shadow, XfaLayer, } = pdfjsLib; -const { GenericL10n, NullL10n, parseQueryString, SimpleLinkService } = - pdfjsViewer; +const { GenericL10n, parseQueryString, SimpleLinkService } = pdfjsViewer; const WAITING_TIME = 100; // ms const CMAP_URL = "/build/generic/web/cmaps/"; @@ -215,8 +214,7 @@ class Rasterize { annotationCanvasMap, page, imageResourcesPath, - renderForms = false, - l10n = NullL10n + renderForms = false ) { try { const { svg, foreignObject, style, div } = this.createContainer(viewport); @@ -248,7 +246,6 @@ class Rasterize { div, annotationCanvasMap: annotationImageMap, page, - l10n, viewport: annotationViewport, }); await annotationLayer.render(parameters); @@ -356,6 +353,8 @@ class Driver { // Configure the global worker options. GlobalWorkerOptions.workerSrc = WORKER_SRC; + // We only need to initialize the `L10n`-instance here, since translation is + // triggered by a `MutationObserver`; see e.g. `Rasterize.annotationLayer`. this._l10n = new GenericL10n(VIEWER_LOCALE); // Set the passed options @@ -879,8 +878,7 @@ class Driver { annotationCanvasMap, page, IMAGE_RESOURCES_PATH, - renderForms, - this._l10n + renderForms ).then(() => { completeRender(false); }); diff --git a/web/annotation_layer_builder.js b/web/annotation_layer_builder.js index 43cb1d9c5..ca0c824d3 100644 --- a/web/annotation_layer_builder.js +++ b/web/annotation_layer_builder.js @@ -19,13 +19,11 @@ // eslint-disable-next-line max-len /** @typedef {import("../src/display/annotation_storage").AnnotationStorage} AnnotationStorage */ /** @typedef {import("./interfaces").IDownloadManager} IDownloadManager */ -/** @typedef {import("./interfaces").IL10n} IL10n */ /** @typedef {import("./interfaces").IPDFLinkService} IPDFLinkService */ // eslint-disable-next-line max-len /** @typedef {import("./text_accessibility.js").TextAccessibilityManager} TextAccessibilityManager */ import { AnnotationLayer } from "pdfjs-lib"; -import { NullL10n } from "web-l10n_utils"; import { PresentationModeState } from "./ui_utils.js"; /** @@ -38,7 +36,6 @@ import { PresentationModeState } from "./ui_utils.js"; * @property {boolean} renderForms * @property {IPDFLinkService} linkService * @property {IDownloadManager} [downloadManager] - * @property {IL10n} l10n - Localization service. * @property {boolean} [enableScripting] * @property {Promise} [hasJSActionsPromise] * @property {Promise> | null>} @@ -61,7 +58,6 @@ class AnnotationLayerBuilder { annotationStorage = null, imageResourcesPath = "", renderForms = true, - l10n = NullL10n, enableScripting = false, hasJSActionsPromise = null, fieldObjectsPromise = null, @@ -74,7 +70,6 @@ class AnnotationLayerBuilder { this.downloadManager = downloadManager; this.imageResourcesPath = imageResourcesPath; this.renderForms = renderForms; - this.l10n = l10n; this.annotationStorage = annotationStorage; this.enableScripting = enableScripting; this._hasJSActionsPromise = hasJSActionsPromise || Promise.resolve(false); @@ -131,7 +126,6 @@ class AnnotationLayerBuilder { div, accessibilityManager: this._accessibilityManager, annotationCanvasMap: this._annotationCanvasMap, - l10n: this.l10n, page: this.pdfPage, viewport: viewport.clone({ dontFlip: true }), }); diff --git a/web/app.js b/web/app.js index 8c69dc245..216a49b04 100644 --- a/web/app.js +++ b/web/app.js @@ -521,7 +521,6 @@ const PDFViewerApplication = { eventBus, renderingQueue: pdfRenderingQueue, linkService: pdfLinkService, - l10n, pageColors, }); pdfRenderingQueue.setThumbnailViewer(this.pdfThumbnailViewer); @@ -538,7 +537,7 @@ const PDFViewerApplication = { } if (!this.supportsIntegratedFind && appConfig.findBar) { - this.findBar = new PDFFindBar(appConfig.findBar, eventBus, l10n); + this.findBar = new PDFFindBar(appConfig.findBar, eventBus); } if (appConfig.annotationEditorParams) { @@ -587,11 +586,10 @@ const PDFViewerApplication = { this.toolbar = new Toolbar( appConfig.toolbar, eventBus, - l10n, await this._nimbusDataPromise ); } else { - this.toolbar = new Toolbar(appConfig.toolbar, eventBus, l10n); + this.toolbar = new Toolbar(appConfig.toolbar, eventBus); } } @@ -617,7 +615,6 @@ const PDFViewerApplication = { this.passwordPrompt = new PasswordPrompt( appConfig.passwordOverlay, this.overlayManager, - l10n, this.isViewerEmbedded ); } @@ -643,7 +640,6 @@ const PDFViewerApplication = { this.pdfLayerViewer = new PDFLayerViewer({ container: appConfig.sidebar.layersView, eventBus, - l10n, }); } @@ -1848,8 +1844,7 @@ const PDFViewerApplication = { printContainer, printResolution, optionalContentConfigPromise, - this._printAnnotationStoragePromise, - this.l10n + this._printAnnotationStoragePromise ); this.printService = printService; this.forceRendering(); diff --git a/web/l10n_utils.js b/web/l10n_utils.js index 92e17b5f0..940c68c8f 100644 --- a/web/l10n_utils.js +++ b/web/l10n_utils.js @@ -18,13 +18,12 @@ import { FluentBundle, FluentResource } from "fluent-bundle"; import { DOMLocalization } from "fluent-dom"; import { L10n } from "./l10n.js"; +import { shadow } from "pdfjs-lib"; /** * @implements {IL10n} */ class ConstL10n extends L10n { - static #instance; - constructor(lang) { super({ lang }); this.setL10n( @@ -51,7 +50,7 @@ class ConstL10n extends L10n { } static get instance() { - return (this.#instance ||= new ConstL10n("en-US")); + return shadow(this, "instance", new ConstL10n("en-US")); } } diff --git a/web/password_prompt.js b/web/password_prompt.js index e3e8b01d1..864307152 100644 --- a/web/password_prompt.js +++ b/web/password_prompt.js @@ -37,18 +37,16 @@ class PasswordPrompt { /** * @param {PasswordPromptOptions} options * @param {OverlayManager} overlayManager - Manager for the viewer overlays. - * @param {IL10n} l10n - Localization service. * @param {boolean} [isViewerEmbedded] - If the viewer is embedded, in e.g. * an