1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-20 15:18:08 +02:00

[api-minor] Use "data-l10n-id"/"data-l10n-args", rather than manually updating DOM-elements, to trigger translation (PR 17146 follow-up)

This patch changes almost all viewer-components[1] to use "data-l10n-id"/"data-l10n-args" for localization, which means that in many cases we no longer need to pass around the `L10n`-instance any more.

One part of the code-base where the `L10n`-instance is still being used "directly" is the AnnotationEditors, however while it might be possible to convert (most of) that code as well that's not attempted in this patch.

---
[1] The one exception is the `PDFDocumentProperties` dialog, since the way it's currently implemented makes that less straightforward to fix without a lot of code changes.
This commit is contained in:
Jonas Jenwald 2023-10-19 16:30:57 +02:00
parent 898cc2e399
commit 17af706070
17 changed files with 117 additions and 149 deletions

View file

@ -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);
});