Added translations using i18next

ref #5
This commit is contained in:
2021-02-05 21:20:05 +01:00
parent 19697692bc
commit 75eb925267
3 changed files with 22 additions and 5 deletions

View File

@@ -1,8 +1,11 @@
import fs from "fs";
import Handlebars from 'handlebars';
import i18next from "i18next";
import Backend from 'i18next-fs-backend';
import path from 'path';
import puppeteer from "puppeteer";
import { Runner } from './models/Runner';
import Handlebars = require('handlebars');
/**
* This class is responsible for all things pdf creation.
* This uses the html templates from src/templates.
@@ -12,12 +15,25 @@ export class PdfCreator {
private browser;
constructor() {
i18next
.use(Backend)
.init({
fallbackLng: 'en',
lng: 'en',
backend: {
loadPath: path.join(__dirname, '/locales/{{lng}}.json')
}
});
Handlebars.registerHelper('__',
function (str) {
return i18next.t(str).toString();
}
);
puppeteer.launch({ headless: true }).then(browser => {
this.browser = browser;
});
}
//TODO: Accept the runner class
public async generateSponsoringContract(runner: Runner): Promise<any> {
const template_source = fs.readFileSync(`${this.templateDir}/sponsoring_contract.html`, 'utf8');
const template = Handlebars.compile(template_source);