Load DTD strings lazily (#4664)

This commit is contained in:
Abe Jellinek 2024-09-03 10:17:42 -04:00 committed by Dan Stillman
parent dbeb1f167c
commit af3602124b

View file

@ -79,17 +79,6 @@ Zotero.Intl = new function () {
Zotero.arrowPreviousKey = Zotero.rtl ? 'ArrowRight' : 'ArrowLeft';
Zotero.arrowNextKey = Zotero.rtl ? 'ArrowLeft' : 'ArrowRight';
this.strings = {};
const intlFiles = ['zotero.dtd', 'preferences.dtd', 'mozilla/editMenuOverlay.dtd'];
for (let intlFile of intlFiles) {
let localeXML = Zotero.File.getContentsFromURL(`chrome://zotero/locale/${intlFile}`);
let regexp = /<!ENTITY ([^\s]+)\s+"([^"]+)/g;
let regexpResult;
while (regexpResult = regexp.exec(localeXML)) {
this.strings[regexpResult[1]] = regexpResult[2];
}
}
// Provide synchronous access to Fluent strings for getString()
ftl = new Localization([
'branding/brand.ftl',
@ -101,6 +90,22 @@ Zotero.Intl = new function () {
};
ChromeUtils.defineLazyGetter(this, 'strings', () => {
const intlFiles = ['zotero.dtd', 'preferences.dtd', 'mozilla/editMenuOverlay.dtd'];
let strings = [];
for (let intlFile of intlFiles) {
let localeXML = Zotero.File.getContentsFromURL(`chrome://zotero/locale/${intlFile}`);
let regexp = /<!ENTITY ([^\s]+)\s+"([^"]+)/g;
let regexpResult;
while ((regexpResult = regexp.exec(localeXML))) {
strings[regexpResult[1]] = regexpResult[2];
}
}
return strings;
});
/**
* @param {String} name
* @param {String[]} [params=[]] - Strings to substitute for placeholders