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

[api-minor] Re-factor NullL10n and remove the hard-coded l10n strings (PR 17115 follow-up)

*Please note:* These changes only affect the GENERIC build, since `NullL10n` is only a stub elsewhere (see PR 17135).

After the changes in PR 17115, which modernized and improved l10n-handling, the `NullL10n`-implementation is no longer a good fallback for the "proper" `L10n`-classes.
To improve this situation, especially for the *standalone* viewer-components, this patch makes the following changes:
 - Let the `NullL10n`-implementation extend an actual `L10n`-class, which is constant and lazily initialized, to ensure that it works *exactly* like the "proper" ones.

 - Automatically bundle the "en-US" l10n-strings in the build, via the pre-processor, such that we don't need to remember to manually update them.

 - Ensure that the *standalone* viewer-components register their DOM-elements for translation, similar to the default viewer, since this will allow future code improvements by using "data-l10n-id"/"data-l10n-args" in most (if not all) parts of the viewer.

 - Remove the `NullL10n` from the `AnnotationLayer`, to avoid affecting bundle size too much.
   For third-party users that access the `AnnotationLayer`, as exposed in the main PDF.js library, they'll now need to *manually* register it for translation. (However, the *standalone* viewer-components still works given the point above.)
This commit is contained in:
Jonas Jenwald 2023-10-19 22:12:46 +02:00
parent a4cd2ef1db
commit f07675a6a8
11 changed files with 72 additions and 125 deletions

View file

@ -41,7 +41,6 @@ import {
} from "./display_utils.js";
import { AnnotationStorage } from "./annotation_storage.js";
import { ColorConverters } from "../shared/scripting_utils.js";
import { NullL10n } from "display-l10n_utils";
import { XfaLayer } from "./xfa_layer.js";
const DEFAULT_TAB_INDEX = 1000;
@ -2902,12 +2901,6 @@ class AnnotationLayer {
this.viewport = viewport;
this.zIndex = 0;
if (
typeof PDFJSDev !== "undefined" &&
PDFJSDev.test("GENERIC && !TESTING")
) {
this.l10n ||= NullL10n;
}
if (typeof PDFJSDev !== "undefined" && PDFJSDev.test("TESTING")) {
// For testing purposes.
Object.defineProperty(this, "showPopups", {
@ -3008,14 +3001,6 @@ class AnnotationLayer {
}
this.#setAnnotationCanvasMap();
if (
typeof PDFJSDev !== "undefined" &&
PDFJSDev.test("GENERIC && !TESTING") &&
this.l10n instanceof NullL10n
) {
await this.l10n.translate(layer);
}
}
/**

View file

@ -17,7 +17,6 @@ const NodeCanvasFactory = null;
const NodeCMapReaderFactory = null;
const NodeFilterFactory = null;
const NodeStandardFontDataFactory = null;
const NullL10n = null;
const PDFFetchStream = null;
const PDFNetworkStream = null;
const PDFNodeStream = null;
@ -27,7 +26,6 @@ export {
NodeCMapReaderFactory,
NodeFilterFactory,
NodeStandardFontDataFactory,
NullL10n,
PDFFetchStream,
PDFNetworkStream,
PDFNodeStream,