Skip to content

Commit d6ff8a9

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,Gijs,willdurand,extension-reviewers,settings-reviewers,search-reviewers,devtools-reviewers,fxview-reviewers,mconley,Standard8,jdescottes,kcochrane,tabbrowser-reviewers
Differential Revision: https://phabricator.services.mozilla.com/D176791
1 parent 962a843 commit d6ff8a9

38 files changed

+165
-190
lines changed

browser/base/content/browser-places.js

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

browser/base/content/browser-sitePermissionPanel.js

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

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

browser/base/content/browser-sync.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ var gSync = {
526526
? "syncing-data-l10n-id"
527527
: "sync-now-data-l10n-id"
528528
);
529-
syncNowBtn.setAttribute("data-l10n-id", l10nId);
529+
document.l10n.setAttributes(syncNowBtn, l10nId);
530530

531531
// This needs to exist because if the user is signed in
532532
// but the user disabled or disconnected sync we should not show the button
@@ -1615,7 +1615,7 @@ var gSync = {
16151615

16161616
document.querySelectorAll(".syncnow-label").forEach(el => {
16171617
let l10nId = el.getAttribute("syncing-data-l10n-id");
1618-
el.setAttribute("data-l10n-id", l10nId);
1618+
document.l10n.setAttributes(el, l10nId);
16191619
});
16201620

16211621
document.querySelectorAll(".syncNowBtn").forEach(el => {
@@ -1638,7 +1638,7 @@ var gSync = {
16381638

16391639
document.querySelectorAll(".syncnow-label").forEach(el => {
16401640
let l10nId = el.getAttribute("sync-now-data-l10n-id");
1641-
el.setAttribute("data-l10n-id", l10nId);
1641+
document.l10n.setAttributes(el, l10nId);
16421642
});
16431643

16441644
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
@@ -1532,8 +1532,8 @@ var gBrowserInit = {
15321532
if (!toolbarMenubar.hasAttribute("autohide")) {
15331533
toolbarMenubar.setAttribute("autohide", true);
15341534
}
1535-
toolbarMenubar.setAttribute(
1536-
"data-l10n-id",
1535+
document.l10n.setAttributes(
1536+
toolbarMenubar,
15371537
"toolbar-context-menu-menu-bar-cmd"
15381538
);
15391539
toolbarMenubar.setAttribute("data-l10n-attrs", "toolbarname");
@@ -1987,8 +1987,8 @@ var gBrowserInit = {
19871987
toplevel.toplevel_name
19881988
);
19891989
} else {
1990-
managedBookmarksButton.setAttribute(
1991-
"data-l10n-id",
1990+
document.l10n.setAttributes(
1991+
managedBookmarksButton,
19921992
"managed-bookmarks"
19931993
);
19941994
}

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
@@ -558,6 +558,7 @@
558558
} else {
559559
tooltipEl.removeAttribute("data-l10n-id");
560560
}
561+
// TODO(Itiel): Maybe simplify this when bug 1830989 lands
561562
}
562563

563564
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.sys.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1940,15 +1940,15 @@ var CustomizableUIInternal = {
19401940
}
19411941

19421942
if (aWidget.l10nId) {
1943-
node.setAttribute("data-l10n-id", aWidget.l10nId);
1943+
aDocument.l10n.setAttributes(node, aWidget.l10nId);
19441944
if (button != node) {
19451945
// This is probably a "button-and-view" widget, such as the Profiler
19461946
// button. In that case, "node" is the "toolbaritem" container, and
19471947
// "button" the main button (see above).
19481948
// In this case, the values on the "node" is used in the Customize
19491949
// view, as well as the tooltips over both buttons; the values on the
19501950
// "button" are used in the overflow menu.
1951-
button.setAttribute("data-l10n-id", aWidget.l10nId);
1951+
aDocument.l10n.setAttributes(button, aWidget.l10nId);
19521952
}
19531953

19541954
if (shortcut) {
@@ -4837,7 +4837,7 @@ export var CustomizableUI = {
48374837
// Sentence case in the AppMenu / panels.
48384838
let l10nId = menuChild.getAttribute("appmenu-data-l10n-id");
48394839
if (l10nId) {
4840-
subviewItem.setAttribute("data-l10n-id", l10nId);
4840+
doc.l10n.setAttributes(subviewItem, l10nId);
48414841
}
48424842

48434843
fragment.appendChild(subviewItem);

browser/components/customizableui/CustomizableWidgets.sys.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ if (Services.prefs.getBoolPref("identity.fxaccounts.enabled")) {
457457
? "syncing-data-l10n-id"
458458
: "sync-now-data-l10n-id"
459459
);
460-
syncNowBtn.setAttribute("data-l10n-id", l10nId);
460+
doc.l10n.setAttributes(syncNowBtn, l10nId);
461461

462462
let SyncedTabsPanelList = doc.defaultView.SyncedTabsPanelList;
463463
panelview.syncedTabsPanelList = new SyncedTabsPanelList(

browser/components/customizableui/content/panelUI.js

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

650650
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
@@ -237,8 +237,8 @@ this.browserAction = class extends ExtensionAPIPersistent {
237237
"unified-extensions-item-message",
238238
"unified-extensions-item-message-hover-menu-button"
239239
);
240-
messageHoverForMenuButton.setAttribute(
241-
"data-l10n-id",
240+
document.l10n.setAttributes(
241+
messageHoverForMenuButton,
242242
"unified-extensions-item-message-manage"
243243
);
244244
deck.appendChild(messageHoverForMenuButton);
@@ -253,8 +253,8 @@ this.browserAction = class extends ExtensionAPIPersistent {
253253
"unified-extensions-item-menu-button"
254254
);
255255

256-
menuButton.setAttribute(
257-
"data-l10n-id",
256+
document.l10n.setAttributes(
257+
menuButton,
258258
"unified-extensions-item-open-menu"
259259
);
260260
// Allow the users to quickly move between extension items using
@@ -324,9 +324,10 @@ this.browserAction = class extends ExtensionAPIPersistent {
324324
const menuButton = node.querySelector(
325325
".unified-extensions-item-menu-button"
326326
);
327-
menuButton.setAttribute(
328-
"data-l10n-args",
329-
JSON.stringify({ extensionName: this.extension.name })
327+
node.ownerDocument.l10n.setAttributes(
328+
menuButton,
329+
"unified-extensions-item-open-menu",
330+
{ extensionName: this.extension.name }
330331
);
331332

332333
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
@@ -300,7 +300,7 @@ class SortedItemSelectList {
300300
* reverted with `enableWithMessageId()`.
301301
*/
302302
disableWithMessageId(messageId) {
303-
this.menulist.setAttribute("data-l10n-id", messageId);
303+
document.l10n.setAttributes(this.menulist, messageId);
304304
this.menulist.setAttribute(
305305
"image",
306306
"chrome://browser/skin/tabbrowser/tab-connecting.png"
@@ -314,7 +314,7 @@ class SortedItemSelectList {
314314
* reverted with `disableWithMessageId()`.
315315
*/
316316
enableWithMessageId(messageId) {
317-
this.menulist.setAttribute("data-l10n-id", messageId);
317+
document.l10n.setAttributes(this.menulist, messageId);
318318
this.menulist.removeAttribute("image");
319319
this.menulist.disabled = this.menulist.itemCount == 0;
320320
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)