How to use the setExtension function from swig

Find comprehensive JavaScript swig.setExtension code examples handpicked from public code repositorys.

57
58
59
60
61
62
63
64
65
  } else {
    return translations && tag && language && translations[tag] && translations[tag][language] ? translations[tag][language] : defaultTranslation;
  }
}

swig.setExtension('i18n', function(ctx, tag, default_translation) {
  var language = ctx.i18n ? ctx.i18n.language : 'unknown';
  return translate(tag, language, default_translation);
});
fork icon4
star icon4
watch icon0

3550
3551
3552
3553
3554
3555
3556
3557
3558
3559

/**
 * Add extensions for custom tags. This allows any custom tag to access a globally available methods via a special globally available object, <var>_ext</var>, in templates.
 *
 * @example
 * swig.setExtension('trans', function (v) { return translate(v); });
 * function compileTrans(compiler, args, content, parent, options) {
 *   return '_output += _ext.trans(' + args[0] + ');'
 * };
 * swig.setTag('trans', parseTrans, compileTrans, true);
fork icon0
star icon1
watch icon0

37
38
39
40
41
42
43
44
45
46
var parseToken = function (token) {
  var match = token.match;
  this.out.push(match);
};

swig.setExtension('currency', function(ctx, value) {
  var cldr = buildCldr(ctx);

  var currency;
  if (ctx && ctx.i18n && ctx.i18n.currency_code){
fork icon0
star icon0
watch icon0

+ 2 other calls in file