fx-compat: Automatically register plugin l10n sources (#2863)

Fixes #2837
This commit is contained in:
Abe Jellinek 2022-10-11 11:59:33 -04:00 committed by GitHub
parent 367090614d
commit bde157b085
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -85,6 +85,30 @@ Zotero.Intl = new function () {
this.strings[regexpResult[1]] = regexpResult[2]; 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
// <link rel="localization" href="make-it-red.ftl"/>
// 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]);
}
});
}; };