Move various item pane strings to Fluent (#4329)

And:

- Accept Fluent l10nId/l10nArgs in ItemMessagePane#render()
- Reuse existing <description> tag to eliminate l10n flickering
This commit is contained in:
Abe Jellinek 2024-07-09 04:00:19 -04:00 committed by GitHub
parent 006c6e890a
commit f79a59f56a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 38 additions and 37 deletions

View file

@ -27,7 +27,7 @@
class DuplicatesMergePane extends XULElementBase {
content = MozXULElement.parseXULToFragment(`
<groupbox>
<button id="zotero-duplicates-merge-button" />
<button id="zotero-duplicates-merge-button" data-l10n-id="item-pane-duplicates-merge-items" />
</groupbox>
<groupbox id="zotero-duplicates-merge-version-select">
@ -84,7 +84,7 @@
if (itemTypeID != item.itemTypeID) {
let msg;
if (displayNumItemsOnTypeError) {
msg = Zotero.getString('pane.item.selected.multiple', items.length);
msg = { l10nId: 'item-pane-message-items-selected', l10nArgs: { count: items.length } };
}
else {
msg = Zotero.getString('pane.item.duplicates.onlySameItemType');
@ -136,7 +136,7 @@
}, 0);
}
button.label = Zotero.getString('pane.item.duplicates.mergeItems', (otherItems.length + 1));
document.l10n.setArgs(button, { count: otherItems.length + 1 });
versionSelect.hidden = fieldSelect.hidden = !alternatives;
itembox.hiddenFields = alternatives ? [] : ['dateAdded', 'dateModified'];
// Since the header of the collapsible section is hidden, the section has to be opened

View file

@ -37,8 +37,8 @@
}
render(content) {
this._messageBox.textContent = '';
if (typeof content == 'string') {
this._messageBox.replaceChildren();
let contentParts = content.split("\n\n");
for (let part of contentParts) {
let desc = document.createXULElement('description');
@ -46,8 +46,18 @@
this._messageBox.appendChild(desc);
}
}
else if (typeof content === 'object' && 'l10nId' in content) {
let { l10nId, l10nArgs } = content;
if (this._messageBox.firstElementChild?.localName === 'description') {
this._messageBox.replaceChildren(this._messageBox.firstElementChild);
}
else {
this._messageBox.appendChild(content);
this._messageBox.replaceChildren(document.createXULElement('description'));
}
document.l10n.setAttributes(this._messageBox.firstElementChild, l10nId, l10nArgs);
}
else {
this._messageBox.replaceChildren(content);
}
}

View file

@ -202,7 +202,7 @@
msg = Zotero.getString('pane.item.duplicates.writeAccessRequired');
}
else {
msg = Zotero.getString('pane.item.selected.zero');
msg = { l10nId: 'item-pane-message-items-selected', l10nArgs: { count: 0 } };
}
this.setItemPaneMessage(msg);
}
@ -227,7 +227,6 @@
let key;
// In the trash, we have to check the object type
if (this.collectionTreeRow.isTrash()) {
let _obj = this.data[0];
if (this.data.every(x => x instanceof Zotero.Collection)) {
key = 'item-pane-message-collections-selected';
}
@ -244,26 +243,11 @@
else {
key = 'item-pane-message-items-selected';
}
// TODO: Add mechanism for this to setItemPaneMessage()
let elem = document.createXULElement('description');
document.l10n.setAttributes(elem, key, { count });
msg = elem;
msg = { l10nId: key, l10nArgs: { count } };
}
else {
let rowCount = this.itemsView.rowCount;
let str = 'pane.item.unselected.';
switch (rowCount) {
case 0:
str += 'zero';
break;
case 1:
str += 'singular';
break;
default:
str += 'plural';
break;
}
msg = Zotero.getString(str, [rowCount]);
let count = this.itemsView.rowCount;
msg = { l10nId: 'item-pane-message-unselected', l10nArgs: { count } };
}
this.setItemPaneMessage(msg);

View file

@ -50,9 +50,11 @@ var Zotero_LocateMenu = new function() {
if(availableEngines.length) {
Zotero_LocateMenu.addLocateEngines(locateMenu, availableEngines, null, true);
}
} else {
}
else {
// add "no items selected"
menuitem = _createMenuItem(Zotero.getString("pane.item.selected.zero"), "no-items-selected");
menuitem = document.createXULElement("menuitem");
document.l10n.setAttributes(menuitem, "item-pane-message-items-selected", { count: 0 });
locateMenu.appendChild(menuitem);
menuitem.disabled = true;
}

View file

@ -585,6 +585,7 @@ item-pane-header-more-options =
.label = More Options
item-pane-message-items-selected = { $count ->
[0] No items selected
[one] { $count } item selected
*[other] { $count } items selected
}
@ -601,6 +602,17 @@ item-pane-message-objects-selected = { $count ->
*[other] { $count } objects selected
}
item-pane-message-unselected = { $count ->
[0] No items in this view
[one] { $count } item in this view
*[other] { $count } items in this view
}
item-pane-duplicates-merge-items =
.label = { $count ->
[one] Merge { $count } item
*[other] Merge { $count } items
}
locate-library-lookup-no-resolver = You must choose a resolver from the { $pane } pane of the { -app-name } settings.

View file

@ -384,14 +384,7 @@ pane.items.interview.twoParticipants = Interview by %S and %S
pane.items.interview.threeParticipants = Interview by %S, %S, and %S
pane.items.interview.manyParticipants = Interview by %S et al.
pane.item.selected.zero = No items selected
pane.item.selected.multiple = %S items selected
pane.item.unselected.zero = No items in this view
pane.item.unselected.singular = %S item in this view
pane.item.unselected.plural = %S items in this view
pane.item.duplicates.selectToMerge = Select items to merge
pane.item.duplicates.mergeItems = Merge %S items
pane.item.duplicates.writeAccessRequired = Library write access is required to merge items.
pane.item.duplicates.onlyTopLevel = Only top-level full items can be merged.
pane.item.duplicates.onlySameItemType = Merged items must all be of the same item type.

View file

@ -131,7 +131,7 @@ describe("ZoteroPane", function() {
// Unselected, with no items in view
assert.equal(
doc.getElementById('zotero-item-pane-message-box').textContent,
Zotero.getString('pane.item.unselected.zero', 0)
yield doc.l10n.formatValue('item-pane-message-unselected', { count: 0 })
);
// Unselected, with one item in view
@ -142,7 +142,7 @@ describe("ZoteroPane", function() {
});
assert.equal(
doc.getElementById('zotero-item-pane-message-box').textContent,
Zotero.getString('pane.item.unselected.singular', 1)
yield doc.l10n.formatValue('item-pane-message-unselected', { count: 1 })
);
// Unselected, with multiple items in view
@ -153,7 +153,7 @@ describe("ZoteroPane", function() {
});
assert.equal(
doc.getElementById('zotero-item-pane-message-box').textContent,
Zotero.getString('pane.item.unselected.plural', 2)
yield doc.l10n.formatValue('item-pane-message-unselected', { count: 2 })
);
// Multiple items selected