From 50e053a355052f8a2b2e05d065936462fce14257 Mon Sep 17 00:00:00 2001 From: Calixte Denizet Date: Thu, 19 Oct 2023 18:00:16 +0200 Subject: [PATCH] [L10n] Don't try to connect the root element when it has already been done In Firefox debug builds, there is an assertion to check that we don't connect a subelement of an already connected root. Thanks to this assertion, we can see that the root has already been added to Fluent, hence we don't need to do it a second time. We don't need to await anymore on the translation in order to update the toolbar: it'll be done by Fluent, so we can safely remove the "localized" event and avoid to wait for it. --- web/app.js | 14 ++++++-------- web/plop.html | 9 +++++++++ web/toolbar.js | 11 ----------- 3 files changed, 15 insertions(+), 19 deletions(-) create mode 100644 web/plop.html diff --git a/web/app.js b/web/app.js index d05e769312762a..65a9a2e92ab7a4 100644 --- a/web/app.js +++ b/web/app.js @@ -272,14 +272,6 @@ const PDFViewerApplication = { this.bindEvents(); this.bindWindowEvents(); - // We can start UI localization now. - const appContainer = appConfig.appContainer || document.documentElement; - this.l10n.translate(appContainer).then(() => { - // Dispatch the 'localized' event on the `eventBus` once the viewer - // has been fully initialized and translated. - this.eventBus.dispatch("localized", { source: this }); - }); - this._initializedCapability.resolve(); }, @@ -375,6 +367,12 @@ const PDFViewerApplication = { : null ); document.getElementsByTagName("html")[0].dir = this.l10n.getDirection(); + if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) { + const appContainer = + this.appConfig.appContainer || document.documentElement; + // Connect Fluent and translate what we already have. + this.l10n.translate(appContainer); + } }, /** diff --git a/web/plop.html b/web/plop.html new file mode 100644 index 00000000000000..b92552d3fe2a7b --- /dev/null +++ b/web/plop.html @@ -0,0 +1,9 @@ + + + + \ No newline at end of file diff --git a/web/toolbar.js b/web/toolbar.js index d0a058ebf090dc..80567e96d0181e 100644 --- a/web/toolbar.js +++ b/web/toolbar.js @@ -46,8 +46,6 @@ const PAGE_NUMBER_LOADING_INDICATOR = "visiblePageIsLoading"; */ class Toolbar { - #wasLocalized = false; - /** * @param {ToolbarOptions} options * @param {EventBus} eventBus @@ -206,11 +204,6 @@ class Toolbar { // Suppress context menus for some controls. scaleSelect.oncontextmenu = noContextMenu; - this.eventBus._on("localized", () => { - this.#wasLocalized = true; - this.#updateUIState(true); - }); - this.#bindEditorToolsListener(options); } @@ -254,10 +247,6 @@ class Toolbar { } #updateUIState(resetNumPages = false) { - if (!this.#wasLocalized) { - // Don't update the UI state until we localize the toolbar. - return; - } const { pageNumber, pagesCount, pageScaleValue, pageScale, items } = this; if (resetNumPages) {