Skip to content

Commit cf26dda

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 f9a88d5 commit cf26dda

37 files changed

+163
-188
lines changed

browser/base/content/browser-places.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1223,7 +1223,7 @@ var PlacesToolbarHelper = {
12231223
if (entry.name) {
12241224
submenu.setAttribute("label", entry.name);
12251225
} else {
1226-
submenu.setAttribute("data-l10n-id", "managed-bookmarks-subfolder");
1226+
document.l10n.setAttributes(submenu, "managed-bookmarks-subfolder");
12271227
}
12281228
submenu.setAttribute("container", "true");
12291229
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(

0 commit comments

Comments
 (0)