fix #547: fix locale args to hbs helpers
This commit is contained in:
Родитель
c8120cdf59
Коммит
ffd6f9b778
|
@ -21,4 +21,4 @@ RUN npm run build:all
|
|||
RUN chown app:app /app
|
||||
|
||||
USER app
|
||||
CMD node server.js
|
||||
CMD NODE_ICU_DATA=./node_modules/full-icu node server.js
|
||||
|
|
|
@ -57,8 +57,6 @@ async function notify (req, res) {
|
|||
{defaultLocale: "en"}
|
||||
);
|
||||
|
||||
// const buttonValue = LocaleUtils.fluentFormat(supportedLocales, "report-scan-another-email");
|
||||
|
||||
if (!notifiedSubscribers.includes(email)) {
|
||||
await EmailUtils.sendEmail(
|
||||
email,
|
||||
|
@ -67,7 +65,7 @@ async function notify (req, res) {
|
|||
{
|
||||
email,
|
||||
supportedLocales,
|
||||
date: HBSHelpers.prettyDate(new Date()),
|
||||
date: HBSHelpers.prettyDate(supportedLocales, new Date()),
|
||||
breachAlert,
|
||||
SERVER_URL: req.app.locals.SERVER_URL,
|
||||
buttonValue: LocaleUtils.fluentFormat(supportedLocales, "report-scan-another-email"),
|
||||
|
|
|
@ -29,12 +29,15 @@ function localizedBreachDataClasses(supportedLocales, dataClasses, args) {
|
|||
|
||||
function prettyDate(supportedLocales, date) {
|
||||
const jsDate = new Date(date);
|
||||
return jsDate.toLocaleDateString(supportedLocales, {year: "numeric", month: "long", day: "numeric"});
|
||||
const options = {year: "numeric", month: "long", day: "numeric"};
|
||||
const intlDateTimeFormatter = new Intl.DateTimeFormat(supportedLocales, options);
|
||||
return intlDateTimeFormatter.format(jsDate);
|
||||
}
|
||||
|
||||
|
||||
function localeString(input) {
|
||||
return input.toLocaleString();
|
||||
function localeString(supportedLocales, numericInput) {
|
||||
const intlNumberFormatter = new Intl.NumberFormat(supportedLocales);
|
||||
return intlNumberFormatter.format(numericInput);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -3850,6 +3850,11 @@
|
|||
}
|
||||
}
|
||||
},
|
||||
"full-icu": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/full-icu/-/full-icu-1.2.1.tgz",
|
||||
"integrity": "sha512-E2s1b4GVbt8PyG+iaRN6ks8N0Oy2LOJz7SIMUwWWWx7Mr5Z08hKkfpkKQbOtOGqzkFpckDJHjjZ8qfigN2W86A=="
|
||||
},
|
||||
"function-bind": {
|
||||
"version": "1.1.1",
|
||||
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
"express-handlebars": "^3.0.0",
|
||||
"fluent": "^0.8.1",
|
||||
"fluent-langneg": "^0.1.0",
|
||||
"full-icu": "^1.2.1",
|
||||
"git-rev-sync": "^1.12.0",
|
||||
"got": "^8.3.1",
|
||||
"hbs": "^4.0.1",
|
||||
|
@ -104,7 +105,7 @@
|
|||
"lint:audit": "npm audit",
|
||||
"pretest": "npm run lint",
|
||||
"get-hashsets": "node scripts/get-hashsets",
|
||||
"server": "nodemon server.js",
|
||||
"server": "NODE_ICU_DATA=./node_modules/full-icu nodemon server.js",
|
||||
"start": "run-p build:all watch:all server",
|
||||
"test:db:migrate": "NODE_ENV=tests knex migrate:latest --knexfile db/knexfile.js --env tests",
|
||||
"test:db:seed": "NODE_ENV=tests knex seed:run --knexfile db/knexfile.js --env tests",
|
||||
|
|
|
@ -29,7 +29,8 @@ test("localizedBreachDataClasses joins array by ',' and renders fluent translati
|
|||
|
||||
|
||||
test("localeString adds commas to numbers", () => {
|
||||
const display = HBSHelpers.localeString(1000000);
|
||||
const supportedLocales = ["en"];
|
||||
const display = HBSHelpers.localeString(supportedLocales, 1000000);
|
||||
expect(display).toEqual("1,000,000");
|
||||
});
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<td valign="top" style="vertical-align: top; padding-top: 0px; padding-right: 20px; padding-bottom: 10px;">
|
||||
<p class="body-copy" style="padding: 0px; margin: 0px; color: #333333; margin: 0px; font-weight: 500; font-size: 16px;">{{ breachAlert.Title }}</p>
|
||||
<p class="body-copy" style="padding: 2px 0px 2px 0px; margin: 0px; color: #333333; font-weight: 400; font-size: 14px;">{{fluentFormat supportedLocales "breach-date"}}:<span class="body-copy" style="font-weight:300; padding-left: 6px; color: #333333">{{prettyDate supportedLocales breachAlert.BreachDate }}</span></p>
|
||||
<p class="body-copy" style="padding: 2px 0px 2px 0px; margin: 0px; color: #333333; font-weight: 400; font-size: 14px;">{{fluentFormat supportedLocales "compromised-accounts"}}:<span class="body-copy" style="font-weight:300; padding-left: 6px; color: #333333">{{localeString breachAlert.PwnCount }}</span></p>
|
||||
<p class="body-copy" style="padding: 2px 0px 2px 0px; margin: 0px; color: #333333; font-weight: 400; font-size: 14px;">{{fluentFormat supportedLocales "compromised-accounts"}}:<span class="body-copy" style="font-weight:300; padding-left: 6px; color: #333333">{{localeString supportedLocales breachAlert.PwnCount }}</span></p>
|
||||
{{#if breachAlert.DataClasses }}
|
||||
<p class="body-copy" style="padding: 2px 0px 2px 0px; margin: 0px; color: #333333; font-weight: 400; font-size: 14px;">{{fluentFormat supportedLocales "compromised-data"}}:<span class="body-copy" style="font-weight:300; padding-left: 6px; color: #333333">{{localizedBreachDataClasses supportedLocales breachAlert.DataClasses }}</span></p>
|
||||
{{/if}}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<td valign="top" style="vertical-align: top; padding-top: 7px; padding-right: 20px; padding-bottom: 10px;">
|
||||
<p class="body-copy" style="padding: 0px; margin: 0px; color: #333333; margin: 0px; font-weight: 500; font-size: 16px;">{{ this.Title }}</p>
|
||||
<p class="body-copy" style="padding: 2px 0px 2px 0px; margin: 0px; color: #333333; font-weight: 400; font-size: 14px;">{{fluentFormat supportedLocales "breach-date"}}:<span class="body-copy" style="font-weight:300; padding-left: 6px; color: #333333">{{prettyDate supportedLocales this.BreachDate }}</span></p>
|
||||
<p class="body-copy" style="padding: 2px 0px 2px 0px; margin: 0px; color: #333333; font-weight: 400; font-size: 14px;">{{fluentFormat supportedLocales "compromised-accounts"}}:<span class="body-copy" style="font-weight:300; padding-left: 6px; color: #333333">{{localeString this.PwnCount }}</span></p>
|
||||
<p class="body-copy" style="padding: 2px 0px 2px 0px; margin: 0px; color: #333333; font-weight: 400; font-size: 14px;">{{fluentFormat supportedLocales "compromised-accounts"}}:<span class="body-copy" style="font-weight:300; padding-left: 6px; color: #333333">{{localeString supportedLocales this.PwnCount }}</span></p>
|
||||
{{#if this.DataClasses }}
|
||||
<p class="body-copy" style="padding: 2px 0px 2px 0px; margin: 0px; color: #333333; font-weight: 400; font-size: 14px;">{{fluentFormat supportedLocales "compromised-data"}}:<span class="body-copy" style="font-weight:300; padding-left: 6px; color: #333333">{{localizedBreachDataClasses supportedLocales this.DataClasses }}</span></p>
|
||||
{{/if}}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<div class="breach-info-wrap">
|
||||
<h4 class="medium">{{ Title }}</h4>
|
||||
<span class="breach-info"><span class="medium">{{fluentFormat req.supportedLocales "breach-date"}}:</span>{{prettyDate req.supportedLocales BreachDate }}</span>
|
||||
<span class="breach-info"><span class="medium">{{fluentFormat req.supportedLocales "compromised-accounts"}}:</span>{{localeString PwnCount }}</span>
|
||||
<span class="breach-info"><span class="medium">{{fluentFormat req.supportedLocales "compromised-accounts"}}:</span>{{localeString req.supportedLocales PwnCount }}</span>
|
||||
{{#if DataClasses }}
|
||||
<span class="breach-info"><span class="medium">{{fluentFormat req.supportedLocales "compromised-data"}}:</span>{{localizedBreachDataClasses req.supportedLocales DataClasses }}</span>
|
||||
{{/if}}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<div class="breach-info-wrap">
|
||||
<span class="breach-headline medium">{{ featuredBreach.Title }}</span>
|
||||
<span class="breach-info breach-date"><span class="medium">{{fluentFormat req.supportedLocales "breach-date"}}</span>{{prettyDate req.supportedLocales featuredBreach.BreachDate }}</span>
|
||||
<span class="breach-info"><span class="medium">{{fluentFormat req.supportedLocales "compromised-accounts"}}</span>{{localeString featuredBreach.PwnCount }}</span>
|
||||
<span class="breach-info"><span class="medium">{{fluentFormat req.supportedLocales "compromised-accounts"}}</span>{{localeString req.supportedLocales featuredBreach.PwnCount }}</span>
|
||||
{{#if featuredBreach.DataClasses }}
|
||||
<span class="breach-info"><span class="medium">{{fluentFormat req.supportedLocales "compromised-data"}}</span>{{localizedBreachDataClasses req.supportedLocales featuredBreach.DataClasses }}</span>
|
||||
{{/if}}
|
||||
|
|
Загрузка…
Ссылка в новой задаче