Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1171: Ensure translatable strings in blocks can actually be translated #1173

Merged
merged 5 commits into from May 29, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 24 additions & 8 deletions Gruntfile.js
Expand Up @@ -42,7 +42,16 @@ module.exports = function( grunt ) {
verify_matching_versions: {
command: 'php bin/verify-version-consistency.php'
},
create_release_zip: {
webpack_production: {
command: 'cross-env BABEL_ENV=production webpack'
},
pot_to_php: {
command: 'npm run pot-to-php'
},
makepot: {
command: 'wp i18n make-pot .'
},
create_build_zip: {
command: 'if [ ! -e build ]; then echo "Run grunt build first."; exit 1; fi; if [ -e amp.zip ]; then rm amp.zip; fi; cd build; zip -r ../amp.zip .; cd ..; echo; echo "ZIP of build: $(pwd)/amp.zip"'
}
},
Expand Down Expand Up @@ -82,6 +91,8 @@ module.exports = function( grunt ) {
spawnQueue = [];
stdout = [];

grunt.task.run( 'shell:webpack_production' );

spawnQueue.push(
{
cmd: 'git',
Expand All @@ -100,12 +111,14 @@ module.exports = function( grunt ) {
versionAppend = commitHash + '-' + new Date().toISOString().replace( /\.\d+/, '' ).replace( /-|:/g, '' );

paths = lsOutput.trim().split( /\n/ ).filter( function( file ) {
return ! /^(blocks|\.|bin|([^/]+)+\.(md|json|xml)|Gruntfile\.js|tests|wp-assets|dev-lib|readme\.md|composer\..*)/.test( file );
return ! /^(blocks|\.|bin|([^/]+)+\.(md|json|xml)|Gruntfile\.js|tests|wp-assets|dev-lib|readme\.md|composer\..*|languages\/README.*)/.test( file );
} );
paths.push( 'vendor/autoload.php' );
paths.push( 'assets/js/*-compiled.js' );
paths.push( 'vendor/composer/**' );
paths.push( 'vendor/sabberworm/php-css-parser/lib/**' );
paths.push( 'languages/amp-translations.php' );
paths.push( 'languages/amp.pot' );

grunt.task.run( 'clean' );
grunt.config.set( 'copy', {
Expand Down Expand Up @@ -137,8 +150,6 @@ module.exports = function( grunt ) {
grunt.task.run( 'readme' );
grunt.task.run( 'copy' );

grunt.task.run( 'shell:create_release_zip' );

done();
}

Expand All @@ -163,16 +174,21 @@ module.exports = function( grunt ) {
doNext();
} );

grunt.registerTask( 'create-release-zip', [
'build',
'shell:create_release_zip'
grunt.registerTask( 'create-build-zip', [
'shell:create_build_zip'
] );

grunt.registerTask( 'build-release', [
'shell:makepot',
'shell:pot_to_php',
'build'
] );

grunt.registerTask( 'deploy', [
'build',
'jshint',
'shell:phpunit',
'shell:verify_matching_versions',
'build-release',
'wp_deploy'
] );
};
2 changes: 1 addition & 1 deletion bin/deploy-travis-pantheon.sh
Expand Up @@ -85,7 +85,7 @@ if [ ! -e node_modules/.bin ]; then
npm install
fi
PATH="node_modules/.bin/:$PATH"
grunt build
npm run build
rsync -avz --delete ./build/ "$repo_dir/wp-content/plugins/amp/"
git --no-pager log -1 --format="Build AMP plugin at %h: %s" > /tmp/commit-message.txt

Expand Down
12 changes: 10 additions & 2 deletions contributing.md
Expand Up @@ -31,7 +31,15 @@ npm install # (if you haven't done so yet)
npm run build
```

This will create an `amp.zip` in the plugin directory which you can install. The contents of this ZIP are also located in the `build` directory which you can `rsync` somewhere as well.
This will create an `amp.zip` in the plugin directory which you can install. The contents of this ZIP are also located in the `build` directory which you can `rsync` somewhere as well.

TO create a build of the plugin as it will be deployed to WordPress.org, run:

```bash
npm run build-release
```

Note that this will currently take much longer than a regular build because it generates the files required for translation. You also must have WP-CLI installed with the `i18n` package.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding the performance: a quick guess is that the command currently scans every folder looking for PHP files to parse—including node_modules. We might wanna exclude this directory (and others) by default. See https://github.com/wp-cli/i18n-command/blob/90f3f8e80a8e7db71e3b1e2d2b26140d5dd9e9fe/src/WordPressCodeExtractor.php#L115-L135 and wp-cli/i18n-command#27.

If you try running wp i18n make-pot without a node_modules folder being there, it should definitely be very fast. If not, it's something else.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@swissspidy I tried moving vendor and node_modules out of the directory without much improvement. But when I moved .git out of the directory, then it became much faster. It seems that it's scanning all the files inside the .git directory as well. So yeah, excluding those directories seems like the solution!


## Updating Allowed Tags And Attributes

Expand Down Expand Up @@ -98,7 +106,7 @@ When you push a commit to your PR, Travis CI will run the PHPUnit tests and snif

Contributors who want to make a new release, follow these steps:

1. Do `npm run build` and install the `amp.zip` onto a normal WordPress install running a stable release build; do smoke test to ensure it works.
1. Do `npm run build-release` and install the `amp.zip` onto a normal WordPress install running a stable release build; do smoke test to ensure it works.
2. Bump plugin versions in `package.json` (×1), `package-lock.json` (×1, just do `npm install` first), `composer.json` (×1), and in `amp.php` (×2: the metadata block in the header and also the `AMP__VERSION` constant).
3. Add changelog entry to readme.
4. Draft blog post about the new release.
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -33,8 +33,8 @@
"main": "blocks/index.js",
"scripts": {
"pot-to-php": "pot-to-php languages/amp-js.pot languages/amp-translations.php amp",
"makepot": "wp i18n make-pot .",
"build": "cross-env BABEL_ENV=production webpack; grunt build; npm run pot-to-php; npm run makepot",
"build": "grunt build; grunt create-build-zip",
"build-release": "grunt build-release; grunt create-build-zip",
"deploy": "grunt deploy",
"dev": "cross-env BABEL_ENV=default webpack --watch"
}
Expand Down