Skip to content

Commit

Permalink
Merge pull request #2209 from mozilla/2194-vpn-banner-update
Browse files Browse the repository at this point in the history
Fix #2194 - Remove VPN Pricing Update Copy (EN-only)
  • Loading branch information
maxxcrawford committed Jul 13, 2021
2 parents d433bd6 + 8897a8c commit 0a68ccd
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 26 deletions.
23 changes: 23 additions & 0 deletions locale-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,29 @@ const LocaleUtils = {
}
return id;
},

fluentFormatWithFallback (supportedLocales, id, fallbackId, args=null, errors=null) {
if (!fallbackId) {
log.error("fluentFormatWithFallback: No fallbackId");
return false;
}

for (const locale of supportedLocales) {
const bundle = fluentBundles[locale];
if (bundle.hasMessage(id)) {
const message = bundle.getMessage(id);
return bundle.format(message, args);
}

// If first message id doesn't have translation, use fallback id
if (fallbackId && bundle.hasMessage(fallbackId)) {
const message = bundle.getMessage(fallbackId);
return bundle.format(message, args);
}
}
return id;
},

};

module.exports = {
Expand Down
3 changes: 3 additions & 0 deletions locales/en/app.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -795,3 +795,6 @@ steps-to-resolve-headline = Steps to resolve this breach
vpn-promo-headline = Now’s the time to boost your safety online.
vpn-promo-copy = { -brand-Mozilla }’s Virtual Private Network helps shield your internet connection from hackers and spies.
vpn-promo-cta = Get { -brand-mozilla-vpn }
vpn-promo-headline-new = Save 50% with a full year subscription
vpn-promo-copy-new = Protect your online data—and choose a VPN subscription plan that works for you.
27 changes: 3 additions & 24 deletions public/js/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ function addWaitlistObservers() {
}
}

function vpnBannerLogic(options) {
function vpnBannerLogic() {

// Check if element exists at all
const vpnPromoBanner = document.getElementById("vpnPromoBanner");
Expand All @@ -422,23 +422,6 @@ function vpnBannerLogic(options) {
return;
}

if (options && options.isEnglish) {
const vpnPromoCopy = document.querySelector(".vpn-promo-copy");
vpnPromoCopy.innerHTML = "";
const vpnPromoCopyStrongTag = document.createElement("strong");
const vpnPromoCopySpanTag = document.createElement("span");
const vpnPromoCopySmallTag = document.createElement("small");
vpnPromoCopyStrongTag.textContent = "Introductory offer ends soon: $4.99/month for Mozilla VPN";
vpnPromoCopySpanTag.textContent = "Now's the time to protect your device against hackers and prying eyes.";
vpnPromoCopySmallTag.textContent = "Offer only available in the United States, United Kingdom, Canada, New Zealand, Malaysia, and Singapore";
vpnPromoCopy.appendChild(vpnPromoCopyStrongTag);
vpnPromoCopy.appendChild(vpnPromoCopySpanTag);
vpnPromoCopy.appendChild(vpnPromoCopySmallTag);

const vpnPromoButton = document.querySelector(".vpn-promo-cta");
vpnPromoButton.href = "https://www.mozilla.org/products/vpn/?utm_source=monitor&utm_medium=monitor&utm_campaign=intro-pricing";
}

// Check for dismissal cookie
const vpnBannerDismissedCookie = document.cookie.split("; ").some((item) => item.trim().startsWith("vpnBannerDismissed="));

Expand Down Expand Up @@ -547,15 +530,11 @@ function vpnBannerLogic(options) {
return;
}

// Only show banner if users first language is some English-locale variant
if (["de", "fr"].some(lang=>preferredLanguages[0].includes(lang))) {
// Only show banner if users first language is English, Germand or French variant
if (["en", "de", "fr"].some(lang=>preferredLanguages[0].includes(lang))) {
vpnBannerLogic();
}

if (["en"].some(lang=>preferredLanguages[0].includes(lang))) {
vpnBannerLogic({isEnglish: true});
}

if (document.getElementById("fxaCheckbox")) {
document.getElementById("fxaCheckbox").style.display = "block";
}
Expand Down
5 changes: 5 additions & 0 deletions template-helpers/hbs-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ function getString (id, args) {
return LocaleUtils.fluentFormat(supportedLocales, id, args.hash);
}

function getStringWithFallback (id, fallbackId, args) {
const supportedLocales = getSupportedLocales(args);
return LocaleUtils.fluentFormatWithFallback(supportedLocales, id, fallbackId, args.hash);
}

function getStrings(stringArr, locales) {
stringArr.forEach(string => {
Expand Down Expand Up @@ -281,6 +285,7 @@ module.exports = {
microsurveyBanner,
englishInAcceptLanguages,
getString,
getStringWithFallback,
getStrings,
fluentFxa,
getStringID,
Expand Down
4 changes: 2 additions & 2 deletions views/partials/vpn-promo.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<div class="vpn-promo-banner-wrapper">
<img alt="Mozilla VPN" class="vpn-promo-logo" src="/img/svg/logos/mozilla-vpn.svg"/>
<div class="vpn-promo-copy">
<strong>{{ getString "vpn-promo-headline" }}</strong>
<span>{{ getString "vpn-promo-copy" }}</span>
<strong>{{ getStringWithFallback "vpn-promo-headline-new" "vpn-promo-headline" }}</strong>
<span>{{ getStringWithFallback "vpn-promo-copy-new" "vpn-promo-copy" }}</span>
</div>
<a class="vpn-promo-cta" href="https://www.mozilla.org/products/vpn/?utm_source=monitor&utm_medium=monitor&utm_campaign=mozillavpn-monitor-top-banner">{{ getString "vpn-promo-cta" }}</a>
<button id="vpnPromoCloseButton" type="button" name="button" data-event-category="vpn-promo-close"><img src="/img/svg/x-close-black.svg"/></button>
Expand Down

0 comments on commit 0a68ccd

Please sign in to comment.