Skip to content

Commit

Permalink
Document the translation function
Browse files Browse the repository at this point in the history
  • Loading branch information
fflorent committed Nov 26, 2024
1 parent 3c7b862 commit 9fcf510
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions app/server/lib/sendAppPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,22 @@ import * as fse from 'fs-extra';
import * as handlebars from 'handlebars';
import jsesc from 'jsesc';
import * as path from 'path';
import { difference, trimEnd } from 'lodash';
import difference from 'lodash/difference';

const { escapeExpression } = handlebars.Utils;

const translateEscaped = (req: express.Request, key: string, args?: any) => {
const res = req.t(`sendAppPage.${key}`, args)?.toString();
return res ? escapeExpression(res) : res;
};
/**
* Return the translation given the key, but also ensure that the return value is HTML-escaped
* in order to avoid possible script injection (that we don't need in any case).
*
* @param req
* @param key The key of the translation (which will be prefixed by `sendAppPage`)
* @param args The args to pass to the translation string (optional)
*/
function translateEscaped(req: express.Request, key: string, args?: any) {
const translation = req.t(`sendAppPage.${key}`, args)?.toString();
return translation ? escapeExpression(translation) : translation;
}

export interface ISendAppPageOptions {
path: string; // Ignored if .content is present (set to "" for clarity).
Expand Down

0 comments on commit 9fcf510

Please sign in to comment.