Build: Update i18n generation to combine JS + PHP translations (https://github.com/woocommerce/woocommerce-admin/pull/481)

* Generate the PHP translations file from the POT file after building the project

* Remove unused tasks

* Update i18n task to generate JS pot file, then convert that to PHP, then run grunt php pot generation

* Update docs

* Pipe babel file output to null, not entire output of command

Helps with debugging the babel command itself
This commit is contained in:
Kelly Dwan 2018-09-26 10:23:55 -04:00 committed by GitHub
parent 3e3dbad408
commit 5dc1addbf8
5 changed files with 55 additions and 27 deletions

View File

@ -5,21 +5,6 @@ module.exports = function( grunt ) {
// Project configuration
grunt.initConfig( {
pkg: grunt.file.readJSON( 'package.json' ),
addtextdomain: {
options: {
textdomain: 'wc-admin',
},
update_all_domains: {
options: {
updateDomains: true
},
src: [ '*.php', '**/*.php', '!\.git/**/*', '!bin/**/*', '!node_modules/**/*', '!tests/**/*' ]
}
},
makepot: {
target: {
options: {
@ -38,8 +23,8 @@ module.exports = function( grunt ) {
},
} );
// Load NPM tasks to be used here.
grunt.loadNpmTasks( 'grunt-wp-i18n' );
grunt.registerTask( 'i18n', ['addtextdomain', 'makepot'] );
grunt.util.linefeed = '\n';

View File

@ -24,4 +24,4 @@ After cloning the repo, install dependencies with `npm install`. Now you can bui
There are also some helper scripts:
- `npm run lint` : Run eslint over the javascript files
- `npm run i18n` : Create a PHP file with the strings from the javascript files, [used to get around lack of JS support in WordPress.org](https://github.com/WordPress/packages/tree/master/packages/i18n#build).
- `npm run i18n` : A multi-step process, used to create a pot file from both the JS and PHP gettext calls. First it runs `i18n:js`, which creates a temporary `.pot` file from the JS files. Next it runs `i18n:php`, which converts that `.pot` file to a PHP file. Lastly, it runs `i18n:pot`, which creates the final `.pot` file from all the PHP files in the plugin (including the generated one with the JS strings).

View File

@ -4,6 +4,32 @@
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@babel/cli": {
"version": "7.1.0",
"resolved": "https://registry.npmjs.org/@babel/cli/-/cli-7.1.0.tgz",
"integrity": "sha512-+OdtGZcJNH92CnDqwaPxh7P7gddFyhoiHV3GBzgKpYbxIJlQ4WDEiC8m+AMcueYzlI+bXqrYlIU/Pp17NaC0hg==",
"dev": true,
"requires": {
"chokidar": "^2.0.3",
"commander": "^2.8.1",
"convert-source-map": "^1.1.0",
"fs-readdir-recursive": "^1.1.0",
"glob": "^7.0.0",
"lodash": "^4.17.10",
"mkdirp": "^0.5.1",
"output-file-sync": "^2.0.0",
"slash": "^2.0.0",
"source-map": "^0.5.0"
},
"dependencies": {
"slash": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/slash/-/slash-2.0.0.tgz",
"integrity": "sha512-ZYKh3Wh2z1PpEXWr0MpSBZ0V6mZHAQfYevttO11c51CaWjGTaadiKZ+wVt1PbMlDV5qhMFslpZCemhwOK7C89A==",
"dev": true
}
}
},
"@babel/code-frame": {
"version": "7.0.0-beta.54",
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.0.0-beta.54.tgz",
@ -4588,7 +4614,7 @@
},
"os-locale": {
"version": "1.4.0",
"resolved": "https://registry.npmjs.org/os-locale/-/os-locale-1.4.0.tgz",
"resolved": "http://registry.npmjs.org/os-locale/-/os-locale-1.4.0.tgz",
"integrity": "sha1-IPnxeuKe00XoveWDsT0gCYA8FNk=",
"dev": true,
"requires": {
@ -6032,6 +6058,12 @@
"jsonfile": "^2.1.0"
}
},
"fs-readdir-recursive": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/fs-readdir-recursive/-/fs-readdir-recursive-1.1.0.tgz",
"integrity": "sha512-GNanXlVr2pf02+sPN40XN8HG+ePaNcvM0q5mZBd668Obwb0yD5GiUbZOFgwn8kGMY6I3mdyDJzieUy3PTYyTRA==",
"dev": true
},
"fs-write-stream-atomic": {
"version": "1.0.10",
"resolved": "https://registry.npmjs.org/fs-write-stream-atomic/-/fs-write-stream-atomic-1.0.10.tgz",
@ -11023,7 +11055,7 @@
},
"chalk": {
"version": "1.1.3",
"resolved": "https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz",
"resolved": "http://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz",
"integrity": "sha1-qBFcVeSnAv5NFQq9OHKCKn4J/Jg=",
"dev": true,
"requires": {
@ -11079,7 +11111,7 @@
},
"minimist": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
"resolved": "http://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz",
"integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=",
"dev": true
},
@ -11627,6 +11659,17 @@
"os-tmpdir": "^1.0.0"
}
},
"output-file-sync": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/output-file-sync/-/output-file-sync-2.0.1.tgz",
"integrity": "sha512-mDho4qm7WgIXIGf4eYU1RHN2UU5tPfVYVSRwDJw0uTmj35DQUt/eNp19N7v6T3SrR0ESTEf2up2CGO73qI35zQ==",
"dev": true,
"requires": {
"graceful-fs": "^4.1.11",
"is-plain-obj": "^1.1.0",
"mkdirp": "^0.5.1"
}
},
"p-defer": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/p-defer/-/p-defer-1.0.0.tgz",

View File

@ -14,10 +14,14 @@
"install-if-no-packages": "node bin/install-if-no-packages.js",
"prebuild": "npm run -s install-if-deps-outdated",
"build": "cross-env NODE_ENV=production webpack",
"postbuild": "npm run -s i18n:php && npm run -s i18n:pot",
"prestart": "npm run -s install-if-deps-outdated",
"start": "webpack --watch",
"lint": "npm run -s install-if-deps-outdated && eslint client --ext=js,jsx",
"i18n": "pot-to-php ./languages/wc-admin.pot ./languages/wc-admin.php wc-admin && grunt i18n",
"i18n:js": "cross-env NODE_ENV=production babel client -o /dev/null",
"i18n:php": "pot-to-php ./languages/wc-admin.pot ./languages/wc-admin.php wc-admin",
"i18n:pot": "grunt makepot",
"i18n": "npm run -s i18n:js && npm run -s i18n:php && npm run -s i18n:pot",
"precommit": "npm run -s install-if-no-packages && node bin/pre-commit-hook.js",
"prepush": "npm run -s install-if-no-packages && node bin/pre-push-hook.js",
"pretest": "npm run -s install-if-no-packages",
@ -27,6 +31,7 @@
"docs": "node ./bin/generate-docs"
},
"devDependencies": {
"@babel/cli": "^7.1.0",
"@babel/core": "^7.1.0",
"@babel/plugin-transform-async-to-generator": "^7.1.0",
"@babel/runtime-corejs2": "^7.0.0",

View File

@ -1,9 +1,4 @@
/**
* /* eslint-disable
*
* @format
*/
/** @format */
const path = require( 'path' );
const ExtractTextPlugin = require( 'extract-text-webpack-plugin' );
const NODE_ENV = process.env.NODE_ENV || 'development';