Last active
November 4, 2015 09:27
-
-
Save lonchbox/705858892b3b5bc4d208 to your computer and use it in GitHub Desktop.
Example to use grunt-wp-i18n makepot, update .po from .pot and grunt-po2mo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function(grunt) { | |
grunt.initConfig({ | |
pkg: grunt.file.readJSON('package.json'), | |
// LESS Compilation | |
less: { | |
development: { | |
options: { | |
paths: ["src/css"] | |
}, | |
files: { | |
'src/css/style.css': 'src/less/style.less', | |
} | |
}, | |
}, | |
// CSS minification | |
cssmin: { | |
combine: { | |
options: { | |
// Remove comments | |
keepSpecialComments: 0 | |
}, | |
files: { | |
'assets/css/app.css': ['src/css/*.css'] | |
} | |
} | |
}, | |
// CSS autoprefixer | |
autoprefixer: { | |
single_file: { | |
options: { | |
// Target-specific options go here. | |
}, | |
src: 'assets/css/app.css', | |
dest: 'assets/css/app.css' | |
}, | |
}, | |
// JS concatenation | |
concat: { | |
dist: { | |
src: ['src/js/*.js'], | |
dest: 'assets/js/app.js', | |
}, | |
}, | |
// JS minification | |
uglify: { | |
dist: { | |
files: { | |
'assets/js/app.min.js': ['assets/js/app.js'] | |
} | |
} | |
}, | |
// Watch css files | |
watch: { | |
less: { | |
files: 'src/less/*.less', | |
tasks: ['less'], | |
}, | |
css: { | |
files: ['src/css/*.css'], | |
tasks: ['cssmin', 'autoprefixer'], | |
}, | |
js: { | |
files: 'src/js/*.js', | |
tasks: ['concat', 'uglify'], | |
}, | |
}, | |
// Generate POT file | |
makepot: { | |
target: { | |
options: { | |
mainFile: 'style.css', | |
domainPath: '/languages', // Where to save the POT file. | |
type: 'wp-theme', // Type of project (wp-plugin or wp-theme). | |
potFilename: 'my-theme-name-v-1.pot', | |
updateTimestamp: true, // Whether the POT-Creation-Date should be updated without other changes. | |
potHeaders: { // Headers to add to the generated POT file. | |
poedit: true, // Includes common Poedit headers. | |
'last-translator': 'Name Last <name@mail.com>', | |
'language-team': 'Name Last <name@mail.com>', | |
'plural-forms': 'nplurals=2; plural=(n != 1);', | |
'language': 'en', | |
'x-poedit-country': 'Spain', | |
'x-poedit-language': 'Spanish', | |
'x-poedit-sourcecharset': 'UTF-8', | |
'x-poedit-basepath': '../', | |
'x-poedit-searchpath-0': '.', | |
'x-poedit-bookmarks': '', | |
'x-textdomain-support': 'yes', | |
'x-poedit-keywordslist': true // Include a list of all possible gettext functions. | |
}, | |
updatePoFiles: true, //To use this option is need to have gettext installed. | |
//For OSX install http://brew.sh | |
//Open Terminal and paste: `brew install gettext` | |
//And link it: `brew link gettext --force` | |
//The reason you need to link gettext is because OSX already ships with | |
//gettext and brew is conservative about it. | |
} | |
} | |
}, | |
// Generate .mo from .po | |
po2mo: { | |
files: { | |
src: 'languages/es_ES.po', | |
dest: 'languages/es_ES.mo', | |
}, | |
files: { | |
src: 'languages/ca.po', | |
dest: 'languages/ca.mo', | |
}, | |
files: { | |
src: 'languages/de_DE.po', | |
dest: 'languages/de_DE.mo', | |
}, | |
}, | |
}); | |
// Load Grunt plugins | |
require('load-grunt-tasks')(grunt); | |
// Set up Grunt tasks | |
grunt.registerTask('css', ['less', 'cssmin', 'autoprefixer']); | |
grunt.registerTask('js', ['concat', 'uglify']); | |
grunt.registerTask('translate', ['makepot', 'po2mo']); | |
grunt.registerTask('default', ['css', 'js', 'makepot']); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment