forked from wechange-eg/cosinnus-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nunjucks.config.js
35 lines (32 loc) · 1.1 KB
/
nunjucks.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
module.exports = function(env){
function parse (parser, nodes, lexer) {
var tok = parser.nextToken();
key = parser.parseSignature(null, true);
parser.advanceAfterBlockEnd(tok.value);
return new nodes.CallExtension(this, 'run', key);
}
function Translation () {
this.tags = ['trans'];
this.parse = parse;
this.run = function (ctx, key) {
// cosinnus_current_language is defined in base.html
// COSINNUS_PO_TRANS is defined in webpack/shared.config.js
if (cosinnus_current_language in COSINNUS_PO_TRANS && key in COSINNUS_PO_TRANS[cosinnus_current_language]) {
var trans = COSINNUS_PO_TRANS[cosinnus_current_language][key];
if (trans && trans.length > 0) {
return trans;
}
}
return key;
};
}
function Ignore () {
this.tags = ['load'];
this.parse = parse;
this.run = function () {
return '';
};
}
env.addExtension('translation', new Translation());
env.addExtension('passThrough', new Ignore());
}