lue); } el.setAttribute("fluent-remote-id", content.string_id); } else { el.textContent = content; } } get cfrFluentFileDir() { return PathUtils.join( Services.dirsvc.get("ProfLD", Ci.nsIFile).path, "settings", "main", "ms-language-packs" ); } get cfrFluentFilePath() { return PathUtils.join( this.cfrFluentFileDir, "browser", "newtab", "asrouter.ftl" ); } /** * Creates a new DOMLocalization instance with the Fluent file from Remote Settings. * * Note: it will use the local Fluent file in any of following cases: * * the remote Fluent file is not available * * it was told to use the local Fluent file */ _createDOML10n() { /* istanbul ignore next */ let useRemoteL10n = Services.prefs.getBoolPref(USE_REMOTE_L10N_PREF, true); if (useRemoteL10n && !L10nRegistry.getInstance().hasSource("cfr")) { const appLocale = Services.locale.appLocaleAsBCP47; let cfrIndexedFileSource = new L10nFileSource( "cfr", "app", [appLocale], `${PathUtils.toFileURI(this.cfrFluentFileDir)}/`, { addResourceOptions: { allowOverrides: true, }, }, [PathUtils.toFileURI(this.cfrFluentFilePath)] ); L10nRegistry.getInstance().registerSources([cfrIndexedFileSource]); } else if (!useRemoteL10n && L10nRegistry.getInstance().hasSource("cfr")) { L10nRegistry.getInstance().removeSources(["cfr"]); } return new DOMLocalization( [ "branding/brand.ftl", "browser/defaultBrowserNotification.ftl", "browser/newtab/asrouter.ftl", "browser/profiles.ftl", "browser/termsofuse.ftl", "toolkit/branding/brandings.ftl", ], false ); } get l10n() { if (!this._l10n) { this._l10n = this._createDOML10n(); } return this._l10n; } reloadL10n() { this._l10n = null; } isLocaleSupported(locale) { return locale === "en-US" || ALL_LOCALES.has(locale); } /** * Format given `localizableText`. * * Format `localizableText` if it is an object using any `string_id` field, * otherwise return `localizableText` unmodified. * * @param {object|string} `localizableText` to format. * @return {string} formatted text. */ async formatLocalizableText(localizableText) { if (typeof localizableText !== "string") { // It's more useful to get an error than passing through an object without // a `string_id` field. let value = await this.l10n.formatValue(localizableText.string_id); return value; } return localizableText; } } export const RemoteL10n = new _RemoteL10n(); PK