Merge pull request #17140 from Snuffleupagus/l10n-move-init
Initialize the `L10n`-instance as soon as possible in Firefox (PR 17115 follow-up)
This commit is contained in:
commit
5f0e560949
39
web/app.js
39
web/app.js
@ -112,7 +112,7 @@ class DefaultExternalServices {
|
|||||||
throw new Error("Not implemented: createPreferences");
|
throw new Error("Not implemented: createPreferences");
|
||||||
}
|
}
|
||||||
|
|
||||||
static async createL10n(options) {
|
static async createL10n() {
|
||||||
throw new Error("Not implemented: createL10n");
|
throw new Error("Not implemented: createL10n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,6 +234,12 @@ const PDFViewerApplication = {
|
|||||||
|
|
||||||
// Called once when the document is loaded.
|
// Called once when the document is loaded.
|
||||||
async initialize(appConfig) {
|
async initialize(appConfig) {
|
||||||
|
let l10nPromise;
|
||||||
|
// In the (various) extension builds, where the locale is set automatically,
|
||||||
|
// initialize the `L10n`-instance as soon as possible.
|
||||||
|
if (typeof PDFJSDev !== "undefined" && !PDFJSDev.test("GENERIC")) {
|
||||||
|
l10nPromise = this.externalServices.createL10n();
|
||||||
|
}
|
||||||
this.appConfig = appConfig;
|
this.appConfig = appConfig;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
@ -255,7 +261,18 @@ const PDFViewerApplication = {
|
|||||||
await this._parseHashParams();
|
await this._parseHashParams();
|
||||||
}
|
}
|
||||||
this._forceCssTheme();
|
this._forceCssTheme();
|
||||||
await this._initializeL10n();
|
|
||||||
|
// Ensure that the `L10n`-instance has been initialized before creating
|
||||||
|
// e.g. the various viewer components.
|
||||||
|
if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
||||||
|
l10nPromise = this.externalServices.createL10n();
|
||||||
|
}
|
||||||
|
this.l10n = await l10nPromise;
|
||||||
|
document.getElementsByTagName("html")[0].dir = this.l10n.getDirection();
|
||||||
|
// Connect Fluent, when necessary, and translate what we already have.
|
||||||
|
if (typeof PDFJSDev === "undefined" || !PDFJSDev.test("MOZCENTRAL")) {
|
||||||
|
this.l10n.translate(appConfig.appContainer || document.documentElement);
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
this.isViewerEmbedded &&
|
this.isViewerEmbedded &&
|
||||||
@ -357,24 +374,6 @@ const PDFViewerApplication = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
|
||||||
* @private
|
|
||||||
*/
|
|
||||||
async _initializeL10n() {
|
|
||||||
this.l10n = await this.externalServices.createL10n(
|
|
||||||
typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")
|
|
||||||
? { locale: AppOptions.get("locale") }
|
|
||||||
: 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);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
|
@ -435,7 +435,7 @@ class ChromeExternalServices extends DefaultExternalServices {
|
|||||||
return new ChromePreferences();
|
return new ChromePreferences();
|
||||||
}
|
}
|
||||||
|
|
||||||
static async createL10n(options) {
|
static async createL10n() {
|
||||||
return new GenericL10n(navigator.language);
|
return new GenericL10n(navigator.language);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -422,7 +422,7 @@ class FirefoxExternalServices extends DefaultExternalServices {
|
|||||||
FirefoxCom.request("updateEditorStates", data);
|
FirefoxCom.request("updateEditorStates", data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async createL10n(_options) {
|
static async createL10n() {
|
||||||
const [localeProperties] = await Promise.all([
|
const [localeProperties] = await Promise.all([
|
||||||
FirefoxCom.requestAsync("getLocaleProperties", null),
|
FirefoxCom.requestAsync("getLocaleProperties", null),
|
||||||
document.l10n.ready,
|
document.l10n.ready,
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { DefaultExternalServices, PDFViewerApplication } from "./app.js";
|
import { DefaultExternalServices, PDFViewerApplication } from "./app.js";
|
||||||
|
import { AppOptions } from "./app_options.js";
|
||||||
import { BasePreferences } from "./preferences.js";
|
import { BasePreferences } from "./preferences.js";
|
||||||
import { DownloadManager } from "./download_manager.js";
|
import { DownloadManager } from "./download_manager.js";
|
||||||
import { GenericL10n } from "./genericl10n.js";
|
import { GenericL10n } from "./genericl10n.js";
|
||||||
@ -46,8 +47,8 @@ class GenericExternalServices extends DefaultExternalServices {
|
|||||||
return new GenericPreferences();
|
return new GenericPreferences();
|
||||||
}
|
}
|
||||||
|
|
||||||
static async createL10n({ locale = "en-US" }) {
|
static async createL10n() {
|
||||||
return new GenericL10n(locale);
|
return new GenericL10n(AppOptions.get("locale") || "en-US");
|
||||||
}
|
}
|
||||||
|
|
||||||
static createScripting({ sandboxBundleSrc }) {
|
static createScripting({ sandboxBundleSrc }) {
|
||||||
|
Loading…
Reference in New Issue
Block a user