carlitoplatanito / gulp-nunjucks-render

[Gulp](https://github.com/wearefractal/gulp) plugin to render [Nunjucks](http://mozilla.github.io/nunjucks/) templates
149 stars 33 forks source link

Example using extensions e.g. https://www.npmjs.com/package/nunjucks-i18n #57

Closed dillonbailey closed 6 years ago

dillonbailey commented 7 years ago

When attempting to add this extension to the environment the block tag i18n resulted in this error:

[13:27:24] gulp-notify: [Error running Gulp] Template render error in plugin 'gulp-nunjucks'
(unknown path) [Line 11, Column 2]
  unknown block tag:
i18n
Kilbourne commented 7 years ago

This should work:

var gulp = require('gulp'),
    data = require('gulp-data'),
    template = require('gulp-nunjucks-render'),
    I18nExtension = require("nunjucks-i18n")(require('gulp-nunjucks-render').nunjucks);
var manageEnvironment = function(environment) {
   environment.addExtension('I18nExtension', new I18nExtension({
        env: environment,
        translations: {
            fr: {
                HELLOWORLD: "Bonjour"
            }
        }
    }));
};
gulp.task('template', function() {
        var context={
           __locale__ : "fr"
       };
        gulp.src(src)
            .pipe(data(context))
            .pipe(template({                
                manageEnv: manageEnvironment,                
            }))
            .pipe(dist);
});