Skip to content

shivapoudel/grunt-potomo

Repository files navigation

grunt-potomo Build Status npm version

Grunt plug-in to compile .po files into binary .mo files with msgfmt.

Requirements

Getting Started

If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:

npm install grunt-potomo --save-dev

Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:

grunt.loadNpmTasks( 'grunt-potomo' );

The "potomo" task

Run this task with the grunt potomo command.

Task targets, files and options may be specified according to the grunt Configuring tasks guide.

Options

options.poDel

Type: Boolean
Default: false

Whether the PO file(s) used from source should be deleted or remove after the creation of MO file(s).

Example config

grunt.initConfig({
  potomo: {                            // Task
    dist: {                            // Target
      options: {                       // Target options
        poDel: true
      },
      files: {                         // Dictionary of files
        'en_GB.mo': 'en_GB.po',        // 'destination': 'source'
        'ne_NP.mo': 'ne_NP.po'
      }
    },
    dev: {                             // Another target
      options: {                       // Target options
        poDel: false
      },
      files: {
        'dest/languages': [ 'en_GB.po', 'ne_NP.po' ]
      }
    }
  }
});

grunt.loadNpmTasks( 'grunt-potomo' );

grunt.registerTask( 'default', ['potomo' ]);

Example usage

Compile

grunt.initConfig({
  potomo: {
    dist: {
      files: {
        'ne_NP.mo': 'ne_NP.po'
      }
    }
  }
});

Compile with options

grunt.initConfig({
  potomo: {
    dist: {
      options: {
        poDel: true
      }
      files: {
        'ne_NP.mo': 'ne_NP.po'
      }
    }
  }
});

Compile multiple files

You can specify multiple destination: source items in files.

grunt.initConfig({
  potomo: {
    dist: {
      files: {
        'en_GB.mo': 'en_GB.po',
        'ne_NP.mo': 'ne_NP.po'
      }
    }
  }
});

Compile files in a directory

Instead of naming all files you want to compile, you can use the expand property allowing you to specify a directory. More information available in the grunt docs - Building the files object dynamically.

grunt.initConfig({
  dirs: {
    lang: 'language',
  },
  potomo: {
    dist: {
      options: {
        poDel: false
      },
      files: [{
        expand: true,
        cwd: '<%= dirs.lang %>/po',
        src: ['*.po'],
        dest: '<%= dirs.lang %>/mo',
        ext: '.mo',
        nonull: true
      }]
    }
  }
});

License

Copyright (c) 2016 Shiva Poudel
Licensed under the MIT license:
http://shivapoudel.mit-license.org/

About

Grunt plug-in to compile .po files into binary .mo files with msgfmt.

Resources

License

Stars

Watchers

Forks

Packages

No packages published