зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1733623 - Add remote localization to Spotlight component r=Mardak
Differential Revision: https://phabricator.services.mozilla.com/D127281
This commit is contained in:
Родитель
ece5495dbe
Коммит
b68969bcf3
|
@ -6,13 +6,14 @@
|
|||
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Security-Policy" content="default-src chrome:; object-src 'none'">
|
||||
<meta http-equiv="Content-Security-Policy" content="default-src resource: chrome:; object-src 'none'">
|
||||
<meta name="referrer" content="no-referrer">
|
||||
<link rel="stylesheet" type="text/css" href="chrome://global/skin/in-content/common.css">
|
||||
<link rel="stylesheet" type="text/css" href="chrome://browser/skin/spotlight.css">
|
||||
<link rel="localization" href="branding/brand.ftl">
|
||||
<link rel="localization" href="browser/branding/brandings.ftl">
|
||||
<link rel="localization" href="browser/newtab/asrouter.ftl">
|
||||
<script defer src="resource://activity-stream/data/custom-elements/paragraph.js"></script>
|
||||
</head>
|
||||
<body role="dialog" aria-labelledby="title" aria-describedby="content">
|
||||
<template id="logo-and-content">
|
||||
|
|
|
@ -2,7 +2,13 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
const { document: gDoc } = window.docShell.chromeEventHandler.ownerGlobal;
|
||||
const {
|
||||
document: gDoc,
|
||||
ChromeUtils,
|
||||
} = window.docShell.chromeEventHandler.ownerGlobal;
|
||||
const { RemoteL10n } = ChromeUtils.import(
|
||||
"resource://activity-stream/lib/RemoteL10n.jsm"
|
||||
);
|
||||
|
||||
function renderSpotlight() {
|
||||
const [content, params] = window.arguments[0];
|
||||
|
@ -20,11 +26,11 @@ function renderSpotlight() {
|
|||
el.remove();
|
||||
continue;
|
||||
}
|
||||
if (content.body[textProp].label.string_id) {
|
||||
document.l10n.setAttributes(el, content.body[textProp].label.string_id);
|
||||
} else {
|
||||
el.textContent = content.body[textProp].label;
|
||||
}
|
||||
el.appendChild(
|
||||
RemoteL10n.createElement(this.window.document, "span", {
|
||||
content: content.body[textProp].label,
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
document.body.appendChild(clone);
|
||||
|
|
|
@ -160,3 +160,51 @@ add_task(async function test_secondaryButton() {
|
|||
|
||||
specialActionStub.restore();
|
||||
});
|
||||
|
||||
add_task(async function test_remoteL10n_content() {
|
||||
let message = (await PanelTestProvider.getMessages()).find(
|
||||
m => m.id === "SPOTLIGHT_MESSAGE_93"
|
||||
);
|
||||
|
||||
// Modify the message to mix translated and un-translated content
|
||||
message = {
|
||||
content: {
|
||||
secondary: {
|
||||
label: "Now Now",
|
||||
...message.content.secondary,
|
||||
},
|
||||
...content,
|
||||
},
|
||||
...message,
|
||||
};
|
||||
|
||||
let dispatchStub = sinon.stub();
|
||||
let browser = BrowserWindowTracker.getTopWindow().gBrowser.selectedBrowser;
|
||||
|
||||
await showAndWaitForDialog({ message, browser, dispatchStub }, async win => {
|
||||
let primaryBtn = win.document.getElementById("primary");
|
||||
let secondaryBtn = win.document.getElementById("secondary");
|
||||
Assert.ok(
|
||||
primaryBtn.getElementsByTagName("remote-text").length,
|
||||
"Should have a remote l10n element"
|
||||
);
|
||||
Assert.ok(
|
||||
secondaryBtn.getElementsByTagName("remote-text").length,
|
||||
"Should have a remote l10n element"
|
||||
);
|
||||
Assert.equal(
|
||||
primaryBtn.getElementsByTagName("remote-text")[0].shadowRoot.textContent,
|
||||
"Stay private with Mozilla VPN",
|
||||
"Should have expected strings for primary btn"
|
||||
);
|
||||
Assert.equal(
|
||||
secondaryBtn.getElementsByTagName("remote-text")[0].shadowRoot
|
||||
.textContent,
|
||||
"Not Now",
|
||||
"Should have expected strings for primary btn"
|
||||
);
|
||||
|
||||
// Dismiss
|
||||
win.document.getElementById("secondary").click();
|
||||
});
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче