Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return async (
tenant: Tenant,
templateName: string,
locale: LanguageCode,
fromAddress: string,
data: MailerData
): Promise => {
// Setup the localization bundles.
const bundle = i18n.getBundle(locale);
const loc = new DOMLocalization([], generateBundleIterator(bundle));
// Translate the HTML fragments.
let dom: JSDOM;
try {
// Parse the rendered template.
dom = new JSDOM(data.message.html, {});
} catch (err) {
logger.error({ err }, "could not parse the HTML for i18n");
throw err;
}
// Translate the bundle.
await loc.translateFragment(dom.window.document);
// Grab the rendered HTML from the dom, and juice them.