1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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/. */
"use strict";
/* globals Localization */
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const L10N = new Localization([
"branding/brand.ftl",
"browser/branding/brandings.ftl",
"browser/branding/sync-brand.ftl",
"browser/newtab/onboarding.ftl",
]);
const ONBOARDING_MESSAGES = () => [
{
id: "FXA_ACCOUNTS_BADGE",
template: "toolbar_badge",
content: {
delay: 10000, // delay for 10 seconds
target: "fxa-toolbar-menu-button",
},
// Never accessed the FxA panel && doesn't use Firefox sync & has FxA enabled
targeting: `!hasAccessedFxAPanel && !usesFirefoxSync && isFxAEnabled == true`,
trigger: { id: "toolbarBadgeUpdate" },
},
{
id: "PROTECTIONS_PANEL_1",
template: "protections_panel",
content: {
title: { string_id: "cfr-protections-panel-header" },
body: { string_id: "cfr-protections-panel-body" },
link_text: { string_id: "cfr-protections-panel-link-text" },
cta_url: `${Services.urlFormatter.formatURLPref(
"app.support.baseURL"
)}etp-promotions?as=u&utm_source=inproduct`,
cta_type: "OPEN_URL",
},
trigger: { id: "protectionsPanelOpen" },
},
];
const OnboardingMessageProvider = {
async getExtraAttributes() {
const [header, button_label] = await L10N.formatMessages([
{ id: "onboarding-welcome-header" },
{ id: "onboarding-start-browsing-button-label" },
]);
return { header: header.value, button_label: button_label.value };
},
async getMessages() {
const messages = await this.translateMessages(await ONBOARDING_MESSAGES());
return messages;
},
async getUntranslatedMessages() {
// This is helpful for jsonSchema testing - since we are localizing in the provider
const messages = await ONBOARDING_MESSAGES();
return messages;
},
async translateMessages(messages) {
let translatedMessages = [];
for (const msg of messages) {
let translatedMessage = { ...msg };
// If the message has no content, do not attempt to translate it
if (!translatedMessage.content) {
translatedMessages.push(translatedMessage);
continue;
}
// Translate any secondary buttons separately
if (msg.content.secondary_button) {
const [secondary_button_string] = await L10N.formatMessages([
{ id: msg.content.secondary_button.label.string_id },
]);
translatedMessage.content.secondary_button.label =
secondary_button_string.value;
}
if (msg.content.header) {
const [header_string] = await L10N.formatMessages([
{ id: msg.content.header.string_id },
]);
translatedMessage.content.header = header_string.value;
}
translatedMessages.push(translatedMessage);
}
return translatedMessages;
},
};
this.OnboardingMessageProvider = OnboardingMessageProvider;
const EXPORTED_SYMBOLS = ["OnboardingMessageProvider"];
|