From f755f4f9fb1463af6bec3cf73b7fabf95ef3fb2e Mon Sep 17 00:00:00 2001 From: Nicolai Ort Date: Sat, 6 Feb 2021 21:15:48 +0100 Subject: [PATCH] Added full interpolation support to the i18n ref #5 --- src/PdfCreator.ts | 4 +++- src/locales/de.json | 4 +++- src/locales/en.json | 7 +++++-- src/templates/sponsoring_contract.html | 7 +++---- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/PdfCreator.ts b/src/PdfCreator.ts index aed8070..c527ab9 100644 --- a/src/PdfCreator.ts +++ b/src/PdfCreator.ts @@ -13,6 +13,7 @@ import { Runner } from './models/Runner'; export class PdfCreator { private templateDir = path.join(__dirname, '/templates'); private browser; + private static interpolations = { eventname: "Lauf für Kaya! 2021", sponsoring_receipt_minimum_amount: '10', currency_symbol: "€" } /** * Main constructor. @@ -30,7 +31,7 @@ export class PdfCreator { }); Handlebars.registerHelper('__', function (str) { - return i18next.t(str).toString(); + return i18next.t(str, PdfCreator.interpolations).toString(); } ); puppeteer.launch({ headless: true }).then(browser => { @@ -48,6 +49,7 @@ export class PdfCreator { const template_source = fs.readFileSync(`${this.templateDir}/sponsoring_contract.html`, 'utf8'); const template = Handlebars.compile(template_source); const result = template({ runners }) + console.log(template) return await this.renderPdf(result, { format: "A5", landscape: true }); } diff --git a/src/locales/de.json b/src/locales/de.json index 1bd446a..0157138 100644 --- a/src/locales/de.json +++ b/src/locales/de.json @@ -14,5 +14,7 @@ "date": "Datum", "signature": "Unterschrift", "location": "Ort", - "sponsoring_subtitle": "Ich Bin" + "sponsoring_subtitle": "Ich/Wir sind bereit anlässlich des {{eventname}}", + "sponsoring_address_condition": "Muss ausgefüllt werden, wenn Sie eine Spendenquittung benötigen - Spendenquittungen können erst ab einem Gesamtbetrag von {{sponsoring_receipt_minimum_amount}}{{currency_symbol}} ausgestellt werden", + "sponsoring_amount_per_distance": "mit einem Betrag von _____{{currency_symbol}} pro gelaufenem Kilometer zu unterstützen." } \ No newline at end of file diff --git a/src/locales/en.json b/src/locales/en.json index 0d50c5c..084afc8 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -12,5 +12,8 @@ "city": "City", "location": "Location", "date": "date", - "signature": "Signature" -} + "signature": "Signature", + "sponsoring_address_condition": "You have to provide an address if you want a donation receipt - Donation receipts can't be issued for total donation amounts under {{sponsoring_receipt_minimum_amount}}{{currency_symbol}}", + "sponsoring_subtitle": "On the ocation of the {{eventname}} I/We want to support", + "sponsoring_amount_per_distance": "with the amount of _____{{currency_symbol}} per kilometer run." +} \ No newline at end of file diff --git a/src/templates/sponsoring_contract.html b/src/templates/sponsoring_contract.html index 5f17d30..796f05c 100644 --- a/src/templates/sponsoring_contract.html +++ b/src/templates/sponsoring_contract.html @@ -43,7 +43,7 @@

-

{{__ "sponsoring_subtitle"}}

+

{{__ "sponsoring_subtitle"}}

@@ -70,7 +70,7 @@
-

mit einem Betrag von _____€ pro gelaufenem Kilometer zu unterstützen.

+

{{__ "sponsoring_amount_per_distance"}}

@@ -84,8 +84,7 @@

{{__ "address"}} ({{__ "sponsor"}})

-

(Muss ausgefüllt werden, wenn Sie eine Spendenquittung benötigen - - Spendenquittungen können erst ab einem Gesamtbetrag von 10€ ausgestellt werden)

+

({{__ "sponsoring_address_condition"}})