felixzapata / gulp-i18n-pug

Gulp plugin to compile Pug templates with internationalization support based on JS/JSON/YAML files
MIT License
28 stars 4 forks source link

No html files saved #3

Closed albpara closed 7 years ago

albpara commented 7 years ago

My gulp task is not generating any output files. This is my task code:

gulp.task('dev:compile:pug', function (done) {
  var options = {
    i18n: {
      dest: 'translations',
      locales: 'locales/*',
      namespace: '$t'
    },
    pretty: true
  }

  return gulp.src('app/**/*.pug')
    .pipe(pugI18n(options))
    .pipe(gulp.dest(options.i18n.dest));
});

The gulp task output seem to "reach" the pug files:

[11:12:04] Starting 'dev:compile:pug'...
[11:12:04] Loading locale de
[11:12:04] Reading translation data: locales/de.yml
[11:12:04] Loading locale en
[11:12:04] Reading translation data: locales/en.yml
[...]

But no output files are saved

felixzapata commented 7 years ago

hi @albpara, I will take a look as soon as possible.

felixzapata commented 7 years ago

hi @albpara, your example it works for me. Can you show me your translation and pug files?

albpara commented 7 years ago

Thaks for the reply Felix. This is my pug:

div #{$t.helloworld}!
p Using locale #{$localeName}

de.yml

helloworld: 'Hallo welt'

en.yml

helloworld: 'Hello world'
albpara commented 7 years ago

Just tested again, I noticed that the translations are created on the wrong place

My project path is /home/xxxxx/development/my-fe-project so gulpfile.js is on /home/xxxxx/development/my-fe-project/gulpfile.js

The translations are created under development folder no inside my-fe-project

The gulps task is defined as follows(sorry I changed it a little, only the paths):

gulp.task('dev:compile:pug:i18n', function (done) {
  var options = {
    i18n: {
      dest: './app-dev/translation',
      locales: './app/locales/*'
    },
    pretty: true
  }

  return gulp.src(paths.pugSrc)
    .pipe(pug(options))
    .pipe(gulp.dest(options.i18n.dest));
});

The locales path is interpreted correctly with ./ but not the dest path which is created one level "behind"

felixzapata commented 7 years ago

hi @albpara, I tested your example with the same routes and the dest folder was created under the directory of the gulp file.

albpara commented 7 years ago

Dunno what to test... I am not able to make it work, but if is working for you I suppose that is just a problem with my configuration, I will try to figure out what is wrong.

felixzapata commented 7 years ago

Ok, contact me again if it does not make it work

mytototo commented 7 years ago

Same issue here. The compiled files are two directories before the current path. If I'm in ./one/foo/bar/website with a dest to ./.tmp, the compiled files are written in ./one/.tmp.

I've tried some workarounds with path, __dirname process.cwd() but nothing works.

OS: macOS Node.js: v8.4.0 npm: v5.3.0

Related to #2

felixzapata commented 7 years ago

hi @mytototo , can you send your gulp task?

fschucht commented 7 years ago

Also having exactly the same issue as described above. It seems to have something to do with the base parameter in line 168. When I change the line from base: path.join(__dirname, locale), to base: options.i18n.dest, everything works as expected for me.

This is my task code:

const PATHS = {
  dist: 'dist',
  templates: 'src/templates/*.pug'
}

gulp.task('translate-templates', () => {
  const options = {
    i18n: {
      dest: PATHS.dist,
      locales: `${PATHS.dist}/translations/*.json`,
      localeExtension: false
    }
  }
  return gulp.src(PATHS.templates)
    .pipe(pugI18n(options))
    .pipe(gulp.dest(PATHS.dist))
})
felixzapata commented 7 years ago

hi @fschucht , your code it is works for me. In order to test it, I've created this folder structure based in your gulpfile.js (is it the same than yours?):

captura de pantalla 2017-09-13 a las 21 25 32

the gulpfile.js

var gulp = require('gulp');
var pugI18n = require('gulp-pug-i18n');

const PATHS = {
  dist: 'dist',
  templates: 'src/templates/*.pug'
}

gulp.task('translate-templates', () => {
  const options = {
    i18n: {
      dest: PATHS.dist,
      locales: `${PATHS.dist}/translations/*.json`,
      localeExtension: false
    }
  }
  return gulp.src(PATHS.templates)
    .pipe(pugI18n(options))
    .pipe(gulp.dest(PATHS.dist))
})

the pug file:

body
  div
    h1 #{$i18n.message}
    h2 #{$i18n.nested.msg}

the es_ES.json file

{
    "message": "Hola Mundo!",
    "nested": {
        "msg": "y hola a tí también"
    }
}

the en_US.json file

{
    "message": "Hello world!",
    "nested": {
        "msg": "and hello to you"
    }
}

The result:

captura de pantalla 2017-09-13 a las 21 29 49

captura de pantalla 2017-09-13 a las 21 36 03

The template.en.html file

<body><div><h1>Hello world!</h1><h2>and hello to you</h2></div></body>

The template.es.html file

<body><div><h1>Hola Mundo!</h1><h2>y hola a tí también</h2></div></body>
fschucht commented 7 years ago

Hey @felixzapata. Thanks for your help! I see the error. I used gulp-i18n-pug (as the name of the git would suggest) rather than gulp-pug-i18n which you are using. With the latter it works. Maybe it should be mentioned in the readme which version should be installed?

With gulp-pug-i18n however I have a new problem. The localeExtension option is getting ignored and files are always compiled with the locale as a extension. This is also the case in your test. I will create a new issue for this.

felixzapata commented 7 years ago

I will update the README. I had to change the repository name when I wanted publish the plugin because the name already did exist.

I will take a look to the other issue so I will close this one.

felixzapata commented 7 years ago

hi @fschucht I´m going to reopen the issue because I made a mistake about the name of the plugin. The name I used in my previous comment it is not the correct (it was not my plugin). There are two plugins almost with the same name, so I´m going to test again your folder structure.

Sorry for that.

felixzapata commented 7 years ago

Hi @fschucht , I've released the version 1.0.2 with the fix.

$ npm install gulp-i18n-pug --save-dev