@dreamproduction/gettext-twig-parser

0.1.5 • Public • Published

npm (scoped) npm

gettext-twig-parser

A module that parses i18n twig strings and creates a PHP file with all the calls readable by a pot file generator.

Getting Started

First add it as a dependency to your package.json:

NPM
npm install @dreamproduction/gettext-twig-parser --save-dev
Yarn
yarn add @dreamproduction/gettext-twig-parser

Once the plugin has been installed, it may be used in a JavaScript file using:

require('@dreamproduction/gettext-twig-parser');

How to Use

Overview

In a JavaScript file, require the module and assign it to a variable:

const gettextTwigParser = require('@dreamproduction/gettext-twig-parser');

Then run it while specifying some options:

gettextTwigParser.parse({
    options: {
        textdomain: 'sample',
        add_textdomain: true,
        output_dir: 'src/tmp/',
        output_filename: 'gettext-twig-parser.php'
    },
    files: [ '**/*.twig' ]
});

Options

options.textdomain

Type: String|null Default value: null

A string value that matches your text domain.

options.add_textdomain

Type: Bool Default value: true

A boolean value that specifies if the text domain should be appended to the output file.

options.output_dir

Type: String Default value: ''

A string value that specifies the output directory in which the PHP file will be created.

options.output_filename

Type: String Default value: ''

A string value that specifies the output filename which will contain the PHP code.

Supported Translation Functions

  • __()
  • _x()
  • _n()
  • _nx()
  • _n_noop()
  • _nx_noop()

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Lint and test your code.

Package Sidebar

Install

npm i @dreamproduction/gettext-twig-parser

Weekly Downloads

4

Version

0.1.5

License

MIT

Last publish

Collaborators

  • florin.sarba
  • mircea.tihu