From bde157b0850d0b8723a917f5b2c1142f2d86e901 Mon Sep 17 00:00:00 2001 From: Abe Jellinek Date: Tue, 11 Oct 2022 11:59:33 -0400 Subject: [PATCH] fx-compat: Automatically register plugin l10n sources (#2863) Fixes #2837 --- chrome/content/zotero/xpcom/intl.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/chrome/content/zotero/xpcom/intl.js b/chrome/content/zotero/xpcom/intl.js index a09560ae19..31f73a47c3 100644 --- a/chrome/content/zotero/xpcom/intl.js +++ b/chrome/content/zotero/xpcom/intl.js @@ -85,6 +85,30 @@ Zotero.Intl = new function () { this.strings[regexpResult[1]] = regexpResult[2]; } } + + // Automatically register l10n sources for enabled plugins. + + // A Fluent file located at + // [plugin root]/locale/en-US/make-it-red.ftl + // could be included in an XHTML file as + // + + // If a plugin doesn't have a subdirectory for the active locale, en-US strings + // will be used as a fallback. + Zotero.Plugins.addObserver({ + startup({ id: pluginID, rootURI }) { + let source = new L10nFileSource( + pluginID, 'app', + Services.locale.availableLocales, + rootURI + 'locale/{locale}/', + ); + L10nRegistry.getInstance().registerSources([source]); + }, + + shutdown({ id: pluginID }) { + L10nRegistry.getInstance().removeSources([pluginID]); + } + }); };