Last active
August 29, 2015 14:04
-
-
Save neonics/68e3ce4d44abd01c2715 to your computer and use it in GitHub Desktop.
Wordpress i18n Grunt: create .pot, update .po, generate .mo
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) { | |
require('load-grunt-tasks')(grunt); | |
grunt.initConfig({ | |
pkg: grunt.file.readJSON('package.json'), | |
wpi18nkeywords: [ | |
'__:1', | |
'_e:1', | |
'_x:1,2c', | |
'esc_html__:1', | |
'esc_html_e:1', | |
'esc_html_x:1,2c', | |
'esc_attr__:1', | |
'esc_attr_e:1', | |
'esc_attr_x:1,2c', | |
'_ex:1,2c', | |
'_n:1,2', | |
'_nx:1,2,4c', | |
'_n_noop:1,2', | |
'_nx_noop:1,2,3c' | |
], | |
pot: { | |
options:{ | |
text_domain: 'my-plugin', | |
dest: 'i18n/', | |
keywords: '<%= wpi18nkeywords %>' | |
}, | |
files:{ | |
src: [ 'plugin.php', 'inc/**/*.php' ], | |
expand: true, | |
} | |
}, | |
updatepo:{ | |
files:{ | |
src:['i18n/*.po'], | |
pot:'<%= pot.options.dest + pot.options.text_domain + ".pot" %>' | |
} | |
} | |
po2mo: { | |
files: { | |
src: 'i18n/*.po', | |
expand: true, | |
}, | |
}, | |
); | |
grunt.registerMultiTask('updatepo', "Update .po files with .pot", function() | |
{ | |
this.requiresConfig('pot'); | |
var data = this.data; | |
this.files[0].src.forEach( function(val,idx,array) { | |
// generate new target in the 'exec' config, and wrap the cmd with a logger: | |
grunt.config( 'exec.update_po_' + idx + '.cmd', function() { | |
var cmd ="msgmerge -U " + val + " " + data.pot; | |
console.log("exec:", cmd ); | |
return cmd; | |
} ); | |
grunt.task.run( ['exec:update_po_'+idx] ); | |
} ); | |
}); | |
grunt.registerTask( 'default', ['pot', 'updatepo', '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
{ | |
... | |
"devDependencies": { | |
"grunt": "~0.4.4", | |
"load-grunt-tasks": "~0.4.0", | |
"grunt-checktextdomain": "^0.1.1", | |
"grunt-pot": "^0.1.2", | |
"grunt-exec": "~0.4.5" | |
"grunt-po2mo": "^0.1.0", | |
}, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment