As of writing this answer there is still no plugin that does this seemlessly. However you can acheive automation using a GRUNT task.
Using Grunt requires you have a nodejs development environment configured
Create a package.json in your project root similar to
{
"name": "yourProject",
"majorVersion": "0",
"minorVersion": "0",
"incrementalVersion": "1",
"qualifier": "-alpha",
"version": "0.0.1-alpha",
"description": "My great idea",
"main": "GruntFile.js",
"directories": {
"test": "test"
},
"repository": {
"type": "git",
"url": "https://yourgitrepo.com/name/project.git"
},
"dependencies": {},
"devDependencies": {
"grunt": "^1.5.3",
"grunt-cli": "^1.4.3",
"grunt-contrib-clean": "^2.0.1",
"grunt-contrib-copy": "^1.0.0",
"grunt-exec": "^3.0.0",
"grunt-pot": "^0.3.0",
"grunt-replace": "^2.0.2",
"load-grunt-tasks": "^5.1.0",
"npm-cli": "^0.1.0"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Your Name",
"license": "SEE LICENCE IN LICENCE.txt"
}
Once created navigate using a terminal and run
npm install
This creates a node environment.
Now create a GruntFile.js
See below for example.
module.exports = function(grunt) {
require('load-grunt-tasks')(grunt);
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
prvPkg: grunt.file.readJSON('private.json'),
clean: {
standard: ['myproject/target',
],
},
makepot: {
target: {
options: {
cwd: 'myproject/target/generated/myproject',
include: ['.*'],
domainPath: 'languages/', // Where to save the POT file.
mainFile: 'myproject.php', // Main project file.
potFilename: 'myproject.pot', // Name of the POT file.
type: 'wp-plugin',
potHeaders: {
'report-msgid-bugs-to': 'https://www.myproject.com.au',
'plural-forms': 'nplurals=2; plural=n != 1;',
'last-translator': 'Author Name <author@myproject.com.au>',
'language-team': 'My Team <author@myproject.com.au>',
poedit:true,
'x-poedit-keywordslist': true,
'x-textdomain-support': 'yes'
}
}
}
},
});
// Default task(s).
grunt.registerTask('createMachineLanguage', '', function () {
let exec = require('child_process').execSync;
let options = {
cwd: 'myproject/target/generated/myproject/languages/',
encoding: 'utf8'
}
let result = exec("msginit --no-translator --input=myproject.pot --locale=en --output=myproject_en_AU.po",options);
result += exec("msgfmt myproject_en_AU.po -o myproject_en_AU.mo",options);
result += exec("rm myproject_en_AU.po",options);
grunt.log.writeln(result);
});
grunt.registerTask('default',['clean:standard','makepot','createMachineLanguage'] );
}
The critical components are the
grunt-pot
grunt plugin. Your terminal environment must have the
GNU gettext intalled which provides the function
msginit
and
msgfmt
. The grunt process executes these tasks automatically.
Please note my environment was Ubuntu so you can see I use an
rm
to remove the po file once it is converted to an mo file.
So using the GruntTask plugin you can create your language files automatically. Executing them from GruntTask.
