Skip to content

Commit 076aaf6

Browse files
committed
Bug 1830679 - Convert element.setAttribute(data-l10n-{id,args}) uses in the codebase to document.l10n.setAttributes(element, id, args) r=eemeli,willdurand,extension-reviewers,settings-reviewers,search-reviewers,devtools-reviewers,fxview-reviewers,mconley,Standard8,jdescottes,kcochrane
Differential Revision: https://phabricator.services.mozilla.com/D176791
1 parent 7dc1e63 commit 076aaf6

39 files changed

+177
-196
lines changed

browser/base/content/browser-places.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,7 @@ var PlacesToolbarHelper = {
12431243
if (entry.name) {
12441244
submenu.setAttribute("label", entry.name);
12451245
} else {
1246-
submenu.setAttribute("data-l10n-id", "managed-bookmarks-subfolder");
1246+
document.l10n.setAttributes(submenu, "managed-bookmarks-subfolder");
12471247
}
12481248
submenu.setAttribute("container", "true");
12491249
submenu.setAttribute(

browser/base/content/browser-sitePermissionPanel.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -990,11 +990,9 @@ var gPermissionPanel = {
990990
MozXULElement.insertFTLIfNeeded("browser/sitePermissions.ftl");
991991
let text = document.createXULElement("label", { is: "text-link" });
992992
text.setAttribute("class", "permission-popup-permission-label");
993-
text.setAttribute("data-l10n-id", "site-permissions-open-blocked-popups");
994-
text.setAttribute(
995-
"data-l10n-args",
996-
JSON.stringify({ count: aTotalBlockedPopups })
997-
);
993+
document.l10n.setAttributes(text, "site-permissions-open-blocked-popups", {
994+
count: aTotalBlockedPopups,
995+
});
998996

999997
text.addEventListener("click", () => {
1000998
gBrowser.selectedBrowser.popupBlocker.unblockAllPopups();

browser/base/content/browser-sync.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ var gSync = {
535535
? "syncing-data-l10n-id"
536536
: "sync-now-data-l10n-id"
537537
);
538-
syncNowBtn.setAttribute("data-l10n-id", l10nId);
538+
document.l10n.setAttributes(syncNowBtn, l10nId);
539539

540540
// This needs to exist because if the user is signed in
541541
// but the user disabled or disconnected sync we should not show the button
@@ -1633,7 +1633,7 @@ var gSync = {
16331633

16341634
document.querySelectorAll(".syncnow-label").forEach(el => {
16351635
let l10nId = el.getAttribute("syncing-data-l10n-id");
1636-
el.setAttribute("data-l10n-id", l10nId);
1636+
document.l10n.setAttributes(el, l10nId);
16371637
});
16381638

16391639
document.querySelectorAll(".syncNowBtn").forEach(el => {
@@ -1656,7 +1656,7 @@ var gSync = {
16561656

16571657
document.querySelectorAll(".syncnow-label").forEach(el => {
16581658
let l10nId = el.getAttribute("sync-now-data-l10n-id");
1659-
el.setAttribute("data-l10n-id", l10nId);
1659+
document.l10n.setAttributes(el, l10nId);
16601660
});
16611661

16621662
document.querySelectorAll(".syncNowBtn").forEach(el => {

browser/base/content/browser-unified-extensions.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,10 @@ customElements.define(
194194
// The data-extensionid attribute is used by context menu handlers
195195
// to identify the extension being manipulated by the context menu.
196196
this._menuButton.dataset.extensionid = this.extension.id;
197-
this._menuButton.setAttribute(
198-
"data-l10n-args",
199-
JSON.stringify({ extensionName: this.extension.name })
197+
this.ownerDocument.l10n.setAttributes(
198+
this._menuButton,
199+
"unified-extensions-item-open-menu",
200+
{ extensionName: this.extension.name }
200201
);
201202

202203
this.#setStateMessage();

browser/base/content/browser.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,8 +1524,8 @@ var gBrowserInit = {
15241524
if (!toolbarMenubar.hasAttribute("autohide")) {
15251525
toolbarMenubar.setAttribute("autohide", true);
15261526
}
1527-
toolbarMenubar.setAttribute(
1528-
"data-l10n-id",
1527+
document.l10n.setAttributes(
1528+
toolbarMenubar,
15291529
"toolbar-context-menu-menu-bar-cmd"
15301530
);
15311531
toolbarMenubar.setAttribute("data-l10n-attrs", "toolbarname");
@@ -1980,8 +1980,8 @@ var gBrowserInit = {
19801980
toplevel.toplevel_name
19811981
);
19821982
} else {
1983-
managedBookmarksButton.setAttribute(
1984-
"data-l10n-id",
1983+
document.l10n.setAttributes(
1984+
managedBookmarksButton,
19851985
"managed-bookmarks"
19861986
);
19871987
}

browser/base/content/nsContextMenu.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,14 +1155,14 @@ class nsContextMenu {
11551155
// Set the correct label for the fill menu
11561156
let fillMenu = document.getElementById("fill-login");
11571157
if (onPasswordLikeField) {
1158-
fillMenu.setAttribute(
1159-
"data-l10n-id",
1158+
document.l10n.setAttributes(
1159+
fillMenu,
11601160
"main-context-menu-use-saved-password"
11611161
);
11621162
} else {
11631163
// On a username field
1164-
fillMenu.setAttribute(
1165-
"data-l10n-id",
1164+
document.l10n.setAttributes(
1165+
fillMenu,
11661166
"main-context-menu-use-saved-login"
11671167
);
11681168
}

browser/base/content/tabbrowser-tab.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@
542542
} else {
543543
tooltipEl.removeAttribute("data-l10n-id");
544544
}
545+
// TODO(Itiel): Maybe simplify this when bug 1830989 lands
545546
}
546547

547548
startUnselectedTabHoverTimer() {

browser/base/content/unified-extensions-viewcache.inc.xhtml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,5 @@
3535
<toolbarbutton class="unified-extensions-item-menu-button subviewbutton subviewbutton-iconic"
3636
closemenu="none"
3737
context="unified-extensions-context-menu"
38-
data-l10n-id="unified-extensions-item-open-menu"
3938
data-navigable-with-tab-only="true" />
4039
</html:template>

browser/components/customizableui/CustomizableUI.jsm

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1951,15 +1951,15 @@ var CustomizableUIInternal = {
19511951
}
19521952

19531953
if (aWidget.l10nId) {
1954-
node.setAttribute("data-l10n-id", aWidget.l10nId);
1954+
aDocument.l10n.setAttributes(node, aWidget.l10nId);
19551955
if (button != node) {
19561956
// This is probably a "button-and-view" widget, such as the Profiler
19571957
// button. In that case, "node" is the "toolbaritem" container, and
19581958
// "button" the main button (see above).
19591959
// In this case, the values on the "node" is used in the Customize
19601960
// view, as well as the tooltips over both buttons; the values on the
19611961
// "button" are used in the overflow menu.
1962-
button.setAttribute("data-l10n-id", aWidget.l10nId);
1962+
aDocument.l10n.setAttributes(button, aWidget.l10nId);
19631963
}
19641964

19651965
if (shortcut) {
@@ -4849,7 +4849,7 @@ var CustomizableUI = {
48494849
// Sentence case in the AppMenu / panels.
48504850
let l10nId = menuChild.getAttribute("appmenu-data-l10n-id");
48514851
if (l10nId) {
4852-
subviewItem.setAttribute("data-l10n-id", l10nId);
4852+
doc.l10n.setAttributes(subviewItem, l10nId);
48534853
}
48544854

48554855
fragment.appendChild(subviewItem);

browser/components/customizableui/CustomizableWidgets.sys.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ if (Services.prefs.getBoolPref("identity.fxaccounts.enabled")) {
468468
? "syncing-data-l10n-id"
469469
: "sync-now-data-l10n-id"
470470
);
471-
syncNowBtn.setAttribute("data-l10n-id", l10nId);
471+
doc.l10n.setAttributes(syncNowBtn, l10nId);
472472

473473
let SyncedTabsPanelList = doc.defaultView.SyncedTabsPanelList;
474474
panelview.syncedTabsPanelList = new SyncedTabsPanelList(

browser/components/customizableui/content/panelUI.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ const PanelUI = {
648648
// their localization IDs are set on "appmenu-data-l10n-id" attributes.
649649
let l10nId = node.getAttribute("appmenu-data-l10n-id");
650650
if (l10nId) {
651-
button.setAttribute("data-l10n-id", l10nId);
651+
document.l10n.setAttributes(button, l10nId);
652652
}
653653

654654
if (node.id) {

browser/components/enterprisepolicies/content/aboutPolicies.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ function generateDocumentation() {
308308
row.appendChild(link(policyName));
309309
let descriptionColumn = col("");
310310
let stringID = string_mapping[policyName] || policyName;
311-
descriptionColumn.setAttribute("data-l10n-id", `policy-${stringID}`);
311+
document.l10n.setAttributes(descriptionColumn, `policy-${stringID}`);
312312
row.appendChild(descriptionColumn);
313313
main_tbody.appendChild(row);
314314
let sec_tbody = document.createElement("tbody");

browser/components/extensions/parent/ext-browserAction.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,8 @@ this.browserAction = class extends ExtensionAPIPersistent {
253253
"unified-extensions-item-message",
254254
"unified-extensions-item-message-hover-menu-button"
255255
);
256-
messageHoverForMenuButton.setAttribute(
257-
"data-l10n-id",
256+
document.l10n.setAttributes(
257+
messageHoverForMenuButton,
258258
"unified-extensions-item-message-manage"
259259
);
260260
deck.appendChild(messageHoverForMenuButton);
@@ -269,8 +269,8 @@ this.browserAction = class extends ExtensionAPIPersistent {
269269
"unified-extensions-item-menu-button"
270270
);
271271

272-
menuButton.setAttribute(
273-
"data-l10n-id",
272+
document.l10n.setAttributes(
273+
menuButton,
274274
"unified-extensions-item-open-menu"
275275
);
276276
// Allow the users to quickly move between extension items using
@@ -340,9 +340,10 @@ this.browserAction = class extends ExtensionAPIPersistent {
340340
const menuButton = node.querySelector(
341341
".unified-extensions-item-menu-button"
342342
);
343-
menuButton.setAttribute(
344-
"data-l10n-args",
345-
JSON.stringify({ extensionName: this.extension.name })
343+
node.ownerDocument.l10n.setAttributes(
344+
menuButton,
345+
"unified-extensions-item-open-menu",
346+
{ extensionName: this.extension.name }
346347
);
347348

348349
menuButton.onblur = event => this.handleMenuButtonEvent(event);

browser/components/firefoxview/helpers.mjs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,13 @@ export function getImageUrl(icon, targetURI) {
5757
}
5858

5959
export function onToggleContainer(detailsContainer) {
60+
const doc = detailsContainer.ownerDocument;
6061
// Ignore early `toggle` events, which may either be fired because the
6162
// UI sections update visibility on component connected (based on persisted
6263
// UI state), or because <details> elements fire `toggle` events when added
6364
// to the DOM with the "open" attribute set. In either case, we don't want
6465
// to record telemetry as these events aren't the result of user action.
65-
if (detailsContainer.ownerDocument.readyState != "complete") {
66+
if (doc.readyState != "complete") {
6667
return;
6768
}
6869

@@ -73,9 +74,10 @@ export function onToggleContainer(detailsContainer) {
7374
? "firefoxview-collapse-button-hide"
7475
: "firefoxview-collapse-button-show";
7576

76-
detailsContainer
77-
.querySelector(".twisty")
78-
.setAttribute("data-l10n-id", newFluentString);
77+
doc.l10n.setAttributes(
78+
detailsContainer.querySelector(".twisty"),
79+
newFluentString
80+
);
7981

8082
if (isTabPickup) {
8183
Services.telemetry.recordEvent(

browser/components/preferences/dialogs/browserLanguages.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ class SortedItemSelectList {
308308
* reverted with `enableWithMessageId()`.
309309
*/
310310
disableWithMessageId(messageId) {
311-
this.menulist.setAttribute("data-l10n-id", messageId);
311+
document.l10n.setAttributes(this.menulist, messageId);
312312
this.menulist.setAttribute(
313313
"image",
314314
"chrome://browser/skin/tabbrowser/tab-connecting.png"
@@ -322,7 +322,7 @@ class SortedItemSelectList {
322322
* reverted with `disableWithMessageId()`.
323323
*/
324324
enableWithMessageId(messageId) {
325-
this.menulist.setAttribute("data-l10n-id", messageId);
325+
document.l10n.setAttributes(this.menulist, messageId);
326326
this.menulist.removeAttribute("image");
327327
this.menulist.disabled = this.menulist.itemCount == 0;
328328
this.button.disabled = !this.menulist.selectedItem;

browser/components/preferences/moreFromMozilla.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,10 @@ var gMoreFromMozillaPane = {
159159
let title = template.querySelector(".product-title");
160160
let desc = template.querySelector(".description");
161161

162-
title.setAttribute("data-l10n-id", product.title_string_id);
162+
document.l10n.setAttributes(title, product.title_string_id);
163163
title.id = product.id;
164164

165-
desc.setAttribute("data-l10n-id", product.description_string_id);
165+
document.l10n.setAttributes(desc, product.description_string_id);
166166

167167
let isLink = product.button.type === "link";
168168
let actionElement = template.querySelector(
@@ -202,8 +202,8 @@ var gMoreFromMozillaPane = {
202202
qrcode.setAttribute("hidden", "false");
203203

204204
let qrcode_title = template.querySelector(".qr-code-box-title");
205-
qrcode_title.setAttribute(
206-
"data-l10n-id",
205+
document.l10n.setAttributes(
206+
qrcode_title,
207207
product.qrcode.title.string_id
208208
);
209209

@@ -222,8 +222,8 @@ var gMoreFromMozillaPane = {
222222
}` +
223223
".svg";
224224
// Add image a11y attributes
225-
img.setAttribute(
226-
"data-l10n-id",
225+
document.l10n.setAttributes(
226+
img,
227227
"more-from-moz-qr-code-firefox-mobile-img"
228228
);
229229

@@ -235,8 +235,8 @@ var gMoreFromMozillaPane = {
235235
// For supported locales, this link allows users to send themselves a
236236
// download link by email. It should be hidden for unsupported locales.
237237
if (BrowserUtils.sendToDeviceEmailsSupported()) {
238-
qrc_link.setAttribute(
239-
"data-l10n-id",
238+
document.l10n.setAttributes(
239+
qrc_link,
240240
product.qrcode.button.label.string_id
241241
);
242242
qrc_link.href = this.getURL(

browser/components/protections/content/lockwise-card.mjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,17 @@ export default class LockwiseCard {
7474
if (hasLogins) {
7575
lockwiseCard.classList.remove("no-logins");
7676
lockwiseCard.classList.add("has-logins");
77-
title.setAttribute("data-l10n-id", "passwords-title-logged-in");
78-
headerContent.setAttribute(
79-
"data-l10n-id",
77+
document.l10n.setAttributes(title, "passwords-title-logged-in");
78+
document.l10n.setAttributes(
79+
headerContent,
8080
"lockwise-header-content-logged-in"
8181
);
8282
this.renderContentForLoggedInUser(numLogins, potentiallyBreachedLogins);
8383
} else {
8484
lockwiseCard.classList.remove("has-logins");
8585
lockwiseCard.classList.add("no-logins");
86-
title.setAttribute("data-l10n-id", "lockwise-title");
87-
headerContent.setAttribute("data-l10n-id", "passwords-header-content");
86+
document.l10n.setAttributes(title, "lockwise-title");
87+
document.l10n.setAttributes(headerContent, "passwords-header-content");
8888
}
8989

9090
const lockwiseUI = document.querySelector(".card.lockwise-card.loading");

0 commit comments

Comments
 (0)