gulp-pug-i18n

Gulp plugin for Pug with i18n support

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
gulp-pug-i18n
1.0.25 years ago8 years agoMinified + gzip package size for gulp-pug-i18n in KB

Readme

gulp-pug-i18n
i18n library for Pug (previously Jade). This plugin extends gulp-pug with i18n functionality.

How to use?

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

gulp.task('default', function () {
  /*  input:
      - input/index.pug
      - input/about.pug
  */

  gulp.src('input/*.pug')
    .pipe(pug({
      i18n: {
        locales: 'locale/*' // locales: en.yml, de.json,
        filename: '{{basename}}.{{lang}}.html'
      },
      pretty: true // Pug option
    }))
    .pipe(gulp.dest('output/'));

  /*  output:
      - output/index.en.html
      - output/index.de.html
      - output/about.en.html
      - output/about.de.html
  */
});

Configuration

Module function takes an object for configuration.

(optional) data object

Pass additional data (including functions) to Pug.
Example: A Markdown function to use in template: { md: require('marked') }

i18n object

(required) locales

Path to search for i18n files. Supports glob patterns.
Example: src/locale/*.{yml,json}

(optional) namespace

Default value: $i18n
Set to null to use root scope.

(optional) default

Specify a default locale. Plugin will remove single curly braces if it matches the current locale to the default locale that is set. For more information check Advanced Usage below.

(optional) filename

How to name rendered Pug (Jade) files. Supports directories.
Available variables:
  • Filename related: basename, origname, origext
  • Locale related: lang, script, region, sort

Note: Add _lower to variable for lowercase, _upper for uppercase.
Default value: {{basename}}.{{lang}}.html
Advanced usage
Using single curly braces outside a double braces will make that variable only show if it's not empty.
For example if we use {{basename}}{.{{lang}}}{-{{region}}}.html, lang or region will be printed only if they are not empty.
  1. en_USindex.en-US.html
  2. enindex.en.html
  3. de_DEindex.de-DE.html
  4. _DEindex-DE.html (we are using this only to show this example, don't use like this)

Another example: {{basename}}{-{{lang}}}{-{{region}}}.html, default locale is en
  1. enindex.html
  2. trindex-tr.html