Don't show string "PLACEHOLDER" in menu while localization runs

Ideally we should cache these/not recreate the menuitems every time, or
something like that, so that localization pop-in doesn't happen at all. But a
brief flash of an empty menuitem is better than a brief flash of placeholder
text.
This commit is contained in:
Abe Jellinek 2024-01-11 15:51:19 -05:00 committed by Dan Stillman
parent f44cc548f9
commit 9a0a15abbe

View file

@ -121,14 +121,22 @@ var Zotero_LocateMenu = new function() {
}); });
function _addViewOption(selectedItems, optionName, optionObject, showIcons) { function _addViewOption(selectedItems, optionName, optionObject, showIcons) {
var menuitem = _createMenuItem(optionObject.label || Zotero.getString(`locate.${optionName}.label`), var menuitem;
if (optionObject.l10nKey) {
menuitem = _createMenuItem('', null, null); // Set by Fluent
menuitem.setAttribute("data-l10n-id", optionObject.l10nKey);
if (optionObject.l10nArgs) {
menuitem.setAttribute("data-l10n-args", optionObject.l10nArgs);
}
}
else {
menuitem = _createMenuItem(optionObject.label || Zotero.getString(`locate.${optionName}.label`),
null, null); null, null);
}
if (optionObject.className && showIcons) { if (optionObject.className && showIcons) {
menuitem.setAttribute("class", `menuitem-iconic ${optionObject.className}`); menuitem.setAttribute("class", `menuitem-iconic ${optionObject.className}`);
} }
menuitem.setAttribute("zotero-locate", "true"); menuitem.setAttribute("zotero-locate", "true");
optionObject.l10nKey && menuitem.setAttribute("data-l10n-id", optionObject.l10nKey);
optionObject.l10nArgs && menuitem.setAttribute("data-l10n-args", optionObject.l10nArgs);
menuitem.addEventListener("command", function (event) { menuitem.addEventListener("command", function (event) {
optionObject.handleItems(selectedItems, event); optionObject.handleItems(selectedItems, event);
@ -377,8 +385,6 @@ var Zotero_LocateMenu = new function() {
// "in New Tab" when it's true) in toolbar Locate menu // "in New Tab" when it's true) in toolbar Locate menu
this.hideInToolbar = alternateWindowBehavior; this.hideInToolbar = alternateWindowBehavior;
// Must have a label, otherwise an error is thrown in `Zotero.getString`
this.label = "PLACEHOLDER";
this.l10nKey = "item-menu-viewAttachment"; this.l10nKey = "item-menu-viewAttachment";
Object.defineProperty(this, "l10nArgs", { Object.defineProperty(this, "l10nArgs", {
get: () => JSON.stringify({ get: () => JSON.stringify({