gulp-fill-pot-po
TypeScript icon, indicating that this package has built-in type declarations

3.0.3 • Public • Published

gulp-fill-pot-po

GitHub release (latest SemVer) NPM version

Build Status Coverall Coverage Status Dependencies Status Downloads

Gulp wrapper for fill-pot-po. Generates pre-filled PO files from POT file, using source PO files.

Based on the POT filename or set options, it looks for source PO files. For each PO file, it will create a new one, based on the contents of the POT file. The source PO file is used to fill in the matching translated strings.

For more information, details and all options, see documentation of fill-pot-po.

This package now supports both ESM and CommonJS 🎉

Install

npm install --save-dev gulp-fill-pot-po

Example usage

Basic (ESM)

import gulp from 'gulp';
const { src, dest } = gulp;
import fillPotPo from 'gulp-fill-pot-po';

const defaultTask = () => {
  return src('src/languages/*.pot')
    .pipe(fillPotPo())
    .pipe(dest('dist/languages/'));
};

export default defaultTask;

Basic (CommonJS)

const { src, dest } = require('gulp');
const fillPotPo = require('gulp-fill-pot-po');

const defaultTask = () => {
  return src('src/languages/*.pot')
    .pipe(fillPotPo())
    .pipe(dest('dist/languages/'));
};

exports.default = defaultTask;

Continue pipe with POT files

const { src, dest } = require('gulp');
const fillPotPo = require('gulp-fill-pot-po');

const defaultTask = () => {
  return (
    src('src/languages/*.pot')
      .pipe(
        fillPotPo({
          returnPOT: true,
          writeFiles: true,
          destDir: 'dist/languages/',
        })
      )
      // Continue processing POT files
      .pipe(/* ... */)
  );
};

exports.default = defaultTask;

Use with gulp-wp-pot

This example uses gulp-wp-pot to extract all translation strings from a WordPress project and generate a POT file.

The POT file is then used to create PO files with the translated strings pre-filled from detected source PO files.

For each detected PO source file, it will generate a matching new one, based on the POT file contents and filled using the source PO file.

const { src, dest } = require('gulp');
const wpPot = require('gulp-wp-pot');
const fillPotPo = require('gulp-fill-pot-po');

const defaultTask = () => {
  return (
    src('src/**/*.php')
      // Extract all translation strings from code base
      // and generate a POT file.
      .pipe(wpPot())

      // Save POT file to disk.
      .pipe(dest('dist/language/text-domain.pot'))

      // Look for matching (prior) PO translation files (e.g. text-domain-en_EN.po)
      // and use them to fill in translated strings in the new POT content.
      .pipe(
        fillPotPo({
          srcDir: 'src/language/',
        })
      )

      // Save the new pre-filled PO files to disk (one for each source PO file).
      .pipe(dest('dist/language/'))
  );
};

exports.default = defaultTask;

fillPotPo( options )

See all available options in the fill-pot-po readme.

All options are passed to fill-pot-po, but there are a few differences:

potSources

Will be set by gulp-fill-pot-po internally.

writeFiles

The default value for writeFiles is false, because the resulting buffers will probably be .pipe( dest() )'d which writes them to disk instead.

returnPOT

boolean

Whether the plugin should return the source POT file(s) (true) or the generated PO file(s) (false).

By default, it will return the generated PO files for further processing, like .pipe( dest('./') ).

In cases where you want to continue processing the source POT files, you can set this to true. Note, that in this case you need to set writeFiles to true or no PO files will be generated and the plugin throws an error.

Default: false

Related

  • fill-pot-po - NodeJS module that does all the work
  • gulp-wp-pot - Generate POT files for WordPress projects in gulp

Extra

License

MIT © Philip van Heemstra

Package Sidebar

Install

npm i gulp-fill-pot-po

Weekly Downloads

114

Version

3.0.3

License

MIT

Unpacked Size

14.7 kB

Total Files

7

Last publish

Collaborators

  • vheemstra