Added full interpolation support to the i18n

ref #5
This commit is contained in:
Nicolai Ort 2021-02-06 21:15:48 +01:00
parent 784d7c656f
commit f755f4f9fb
4 changed files with 14 additions and 8 deletions

View File

@ -13,6 +13,7 @@ import { Runner } from './models/Runner';
export class PdfCreator { export class PdfCreator {
private templateDir = path.join(__dirname, '/templates'); private templateDir = path.join(__dirname, '/templates');
private browser; private browser;
private static interpolations = { eventname: "Lauf für Kaya! 2021", sponsoring_receipt_minimum_amount: '10', currency_symbol: "€" }
/** /**
* Main constructor. * Main constructor.
@ -30,7 +31,7 @@ export class PdfCreator {
}); });
Handlebars.registerHelper('__', Handlebars.registerHelper('__',
function (str) { function (str) {
return i18next.t(str).toString(); return i18next.t(str, PdfCreator.interpolations).toString();
} }
); );
puppeteer.launch({ headless: true }).then(browser => { 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_source = fs.readFileSync(`${this.templateDir}/sponsoring_contract.html`, 'utf8');
const template = Handlebars.compile(template_source); const template = Handlebars.compile(template_source);
const result = template({ runners }) const result = template({ runners })
console.log(template)
return await this.renderPdf(result, { format: "A5", landscape: true }); return await this.renderPdf(result, { format: "A5", landscape: true });
} }

View File

@ -14,5 +14,7 @@
"date": "Datum", "date": "Datum",
"signature": "Unterschrift", "signature": "Unterschrift",
"location": "Ort", "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."
} }

View File

@ -12,5 +12,8 @@
"city": "City", "city": "City",
"location": "Location", "location": "Location",
"date": "date", "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."
} }

View File

@ -43,7 +43,7 @@
</p> </p>
</div> </div>
</div> </div>
<p>{{__ "sponsoring_subtitle"}}</p> <p> {{__ "sponsoring_subtitle"}} </p>
<div class="detail"> <div class="detail">
<div class="columns" style="padding-top: 0;"> <div class="columns" style="padding-top: 0;">
<div class="column is-8"> <div class="column is-8">
@ -70,7 +70,7 @@
</div> </div>
</div> </div>
</div> </div>
<p>mit einem Betrag von _____€ pro gelaufenem Kilometer zu unterstützen.</p> <p>{{__ "sponsoring_amount_per_distance"}}</p>
<div class="detail"> <div class="detail">
<div class="columns"> <div class="columns">
<div class="column is-6"> <div class="column is-6">
@ -84,8 +84,7 @@
</div> </div>
</div> </div>
<p style="font-size: medium;">{{__ "address"}} ({{__ "sponsor"}})</p> <p style="font-size: medium;">{{__ "address"}} ({{__ "sponsor"}})</p>
<p style="font-size: x-small;">(Muss ausgefüllt werden, wenn Sie eine Spendenquittung benötigen - <p style="font-size: x-small;">({{__ "sponsoring_address_condition"}})</p>
Spendenquittungen können erst ab einem Gesamtbetrag von 10€ ausgestellt werden)</p>
<div class="detail"> <div class="detail">
<div class="columns"> <div class="columns">
<div class="column is-8"> <div class="column is-8">