Skip to content

Commit 87a75a0

Browse files
committed
Getting close
1 parent 65b65fb commit 87a75a0

16 files changed

+358
-204
lines changed

.gitignore

100644100755
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
/node_modules
22
/build
3+
.DS_Store
4+
.idea
5+

.tx/config

100644100755
File mode changed.

Gruntfile.js

100644100755
Lines changed: 7 additions & 171 deletions
Original file line numberDiff line numberDiff line change
@@ -1,173 +1,9 @@
1-
module.exports = function(grunt) {
2-
3-
// Load multiple grunt tasks using globbing patterns
4-
require('load-grunt-tasks')(grunt);
5-
6-
// Project configuration.
7-
grunt.initConfig({
8-
pkg: grunt.file.readJSON('package.json'),
9-
10-
makepot: {
11-
target: {
12-
options: {
13-
domainPath: '/languages', // Where to save the POT file.
14-
exclude: ['build/.*'],
15-
mainFile: 'foo.php', // Main project file.
16-
potFilename: 'foo.pot', // Name of the POT file.
17-
potHeaders: {
18-
poedit: true, // Includes common Poedit headers.
19-
'x-poedit-keywordslist': true // Include a list of all possible gettext functions.
20-
},
21-
type: 'wp-plugin', // Type of project (wp-plugin or wp-theme).
22-
updateTimestamp: true, // Whether the POT-Creation-Date should be updated without other changes.
23-
updatePoFiles: true, // Whether to update PO files in the same directory as the POT file.
24-
processPot: function(pot, options) {
25-
pot.headers['report-msgid-bugs-to'] = 'http://wp-translations.org/';
26-
pot.headers['last-translator'] = 'WP-Translations <[email protected]>';
27-
pot.headers['language-team'] = 'WP-Translations (http://wp-translations.org/)';
28-
pot.headers['language'] = 'en_US';
29-
var translation, // Exclude meta data from pot.
30-
excluded_meta = [
31-
'Plugin Name of the plugin/theme',
32-
'Plugin URI of the plugin/theme',
33-
'Author of the plugin/theme',
34-
'Author URI of the plugin/theme'
35-
];
36-
for (translation in pot.translations['']) {
37-
if ('undefined' !== typeof pot.translations[''][translation].comments.extracted) {
38-
if (excluded_meta.indexOf(pot.translations[''][translation].comments.extracted) >= 0) {
39-
console.log('Excluded meta: ' + pot.translations[''][translation].comments.extracted);
40-
delete pot.translations[''][translation];
41-
}
42-
}
43-
}
44-
return pot;
45-
}
46-
}
47-
}
48-
},
49-
50-
checktextdomain: {
51-
options:{
52-
text_domain: 'foo', //Name of Your textdomain
53-
create_report_file: true,
54-
keywords: [
55-
'__:1,2d',
56-
'_e:1,2d',
57-
'_x:1,2c,3d',
58-
'esc_html__:1,2d',
59-
'esc_html_e:1,2d',
60-
'esc_html_x:1,2c,3d',
61-
'esc_attr__:1,2d',
62-
'esc_attr_e:1,2d',
63-
'esc_attr_x:1,2c,3d',
64-
'_ex:1,2c,3d',
65-
'_n:1,2,4d',
66-
'_nx:1,2,4c,5d',
67-
'_n_noop:1,2,3d',
68-
'_nx_noop:1,2,3c,4d',
69-
' __ngettext:1,2,3d',
70-
'__ngettext_noop:1,2,3d',
71-
'_c:1,2d',
72-
'_nc:1,2,4c,5d'
73-
]
74-
},
75-
files: {
76-
src: [
77-
'**/*.php', // Include all files
78-
'!node_modules/**', // Exclude node_modules/
79-
'!build/.*'// Exclude build/
80-
],
81-
expand: true
82-
}
83-
},
84-
85-
exec: {
86-
npmUpdate: {
87-
command: 'npm update'
88-
},
89-
txpull: { // Pull Transifex translation - grunt exec:txpull
90-
cmd: 'tx pull -a -f --minimum-perc=100' // Change the percentage with --minimum-perc=yourvalue
91-
},
92-
txpush_s: { // Push pot to Transifex - grunt exec:txpush_s
93-
cmd: 'tx push -s'
94-
}
95-
},
96-
97-
dirs: {
98-
lang: 'languages' // It should be languages or lang
99-
},
100-
101-
potomo: {
102-
dist: {
103-
options: {
104-
poDel: false // Set to true if you want to erase the .po
105-
},
106-
files: [{
107-
expand: true,
108-
cwd: '<%= dirs.lang %>',
109-
src: ['*.po'],
110-
dest: '<%= dirs.lang %>',
111-
ext: '.mo',
112-
nonull: true
113-
}]
114-
}
115-
},
116-
117-
// Clean up build directory
118-
clean: {
119-
main: ['build/<%= pkg.name %>']
120-
},
121-
122-
// Copy the theme into the build directory
123-
copy: {
124-
main: {
125-
src: [
126-
'**',
127-
'!node_modules/**',
128-
'!build/**',
129-
'!.git/**',
130-
'!Gruntfile.js',
131-
'!package.json',
132-
'!.gitignore',
133-
'!.gitmodules',
134-
'!.tx/**',
135-
'!**/Gruntfile.js',
136-
'!**/package.json',
137-
'!**/README.md',
138-
'!**/*~'
139-
],
140-
dest: 'build/<%= pkg.name %>/'
141-
}
142-
},
143-
144-
// Compress build directory into <name>.zip and <name>-<version>.zip
145-
compress: {
146-
main: {
147-
options: {
148-
mode: 'zip',
149-
archive: './build/<%= pkg.name %>.zip'
150-
},
151-
expand: true,
152-
cwd: 'build/<%= pkg.name %>/',
153-
src: ['**/*'],
154-
dest: '<%= pkg.name %>/'
155-
}
1+
/* global require, process */
2+
module.exports = function( grunt ) {
3+
// Load Grunt plugin configurations
4+
require('load-grunt-config')(grunt, {
5+
data: {
6+
pkg: grunt.file.readJSON('package.json')
1567
}
1578
});
158-
159-
// Default task. - grunt makepot
160-
grunt.registerTask('default', 'makepot');
161-
162-
// Checktextdomain and makepot task(s)
163-
grunt.registerTask('go-pot', ['checktextdomain', 'makepot', 'potomo']);
164-
165-
// Makepot and push it on Transifex task(s).
166-
grunt.registerTask('tx-push', ['makepot', 'exec:txpush_s']);
167-
168-
// Pull from Transifex and create .mo task(s).
169-
grunt.registerTask('tx-pull', ['exec:txpull', 'potomo']);
170-
171-
// Build task(s).
172-
grunt.registerTask('build', ['clean', 'copy', 'compress']);
173-
};
9+
};

README.md

100644100755
Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,22 @@ A set of grunt tasks to integrate i18n tools and Transifex to your WordPress plu
1111

1212
* Extras: Builds a zip folder of all your files - ready to use
1313

14+
* Bonus: A set of others grunt.js ready to use
15+
1416
## Requirements
1517

1618
* Node.js - [Install Node.js](https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager)
1719
* Grunt-cli and Grunt (`npm install grunt-cli -g`)
1820
* Transifex Client - [Install tx client](http://docs.transifex.com/developer/client/setup)
1921
* Gettext - [Install Gettext](https://www.gnu.org/software/gettext/) or `brew install gettext` -> [Homebrew formula for OS X](http://brewformulas.org/Gettext)
20-
* [PHP CLI](http://www.php.net/manual/en/features.commandline.introduction.php) in your system path.
2122

2223
## Getting started
2324

2425
If you haven't used [Grunt](http://gruntjs.com/) before, check out Chris Coyier's post on [getting started with Grunt](http://24ways.org/2013/grunt-is-not-weird-and-hard/).
2526

26-
And for more WP-Grunt tools check out Devin Price's post [Using Grunt with WordPress Themes](http://wptheming.com/2014/05/grunt-wordpress-themes/).
27+
And for more WP-Grunt optimization [Supercharging your Gruntfile](http://www.html5rocks.com/en/tutorials/tooling/supercharging-your-gruntfile/).
28+
29+
All Grunt configuration are separated into different files already setup for you and almost all Grunt config setups are done in the package.json file
2730

2831
Clone this repo, cd to the directory, run `npm install` to install the necessary packages.
2932

@@ -57,42 +60,34 @@ More info about [setting up your Transifex client](http://docs.transifex.com/dev
5760

5861
In .tx->config replace the project_slug and the pot_slug by your own Transifex project data.
5962

60-
### Creates pot
63+
### packages.json
6164

62-
In your Gruntfile.js, replace in the section named `makepot` the data below:
65+
All variables are setup in this file. Change all settings to reflect your own project infos. Nothing complicated
6366

64-
```js
65-
makepot: {
66-
target: {
67-
options: {
68-
mainFile: 'foo.php', // Main project file.
69-
potFilename: 'foo.pot', // Name of the POT file.
70-
type: 'wp-plugin', // Type of project (wp-plugin or wp-theme).
71-
updateTimestamp: true, // Whether the POT-Creation-Date should be updated without other changes.
72-
updatePoFiles: false // Whether to update PO files in the same directory as the POT file.
73-
}
74-
}
75-
}
76-
```
67+
#### pot
7768

78-
### Checktexdomain
79-
80-
In your Gruntfile.js, replace in the section named `checktextdomain` the text_domain option:
69+
In your package.json, replace in the section named `pot` the data below:
8170

8271
```js
83-
checktextdomain: {
84-
options:{
85-
text_domain: 'foo', //Name of Your textdomain
72+
"pot": {
73+
"type": "wp-plugin",
74+
"textdomain": "foo",
75+
"src": "foo.php",
76+
"header": {
77+
"bugs": "http://wp-translations.org/",
78+
"team": "WP-Translations <[email protected]>",
79+
"last_translator": "WP-Translations <[email protected]>"
80+
}
81+
},
8682
```
87-
8883
### Creates pot and pushes it to Transifex
8984

90-
In your Gruntfile.js, replace in the section named `exec` the -- minimum percentage value if needed:
85+
In your grunt > exec.js, replace in the section named `exec` the -- minimum percentage value if needed:
9186

9287
```js
9388
exec: {
9489
txpull: { // Pull Transifex translation - grunt exec:txpull
95-
cmd: 'tx pull -a --minimum-perc=100' // Change the percentage with --minimum-perc=yourvalue
90+
cmd: 'tx pull -a -f --minimum-perc=100' // Change the percentage with --minimum-perc=yourvalue
9691
}
9792
}
9893
```
@@ -107,7 +102,7 @@ That's it you're ready to `Grunt it` now with those commands!
107102

108103
### Check textdomain and makepot
109104

110-
`grunt go-pot`
105+
`grunt build:i18n`
111106

112107
### Creates pot and pushes it to Transifex
113108

@@ -123,7 +118,7 @@ That's it you're ready to `Grunt it` now with those commands!
123118

124119
### Thanks to:
125120

126-
[grunt-wp-i18n](https://github.com/cedaro/grunt-wp-i18n) by Brady Vercher to generate the .pot files.
121+
[grunt-wp-i18n](https://github.com/cedaro/grunt-wp-i18n) by Bradley Vercher to generate the .pot files.
127122

128123
[grunt-potomo](https://github.com/axisthemes/grunt-potomo) by AxisThemes to generate automatically the .mo files.
129124

example.inc.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
$test = __( 'Here I am' );

example.php

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?php
2+
3+
/**
4+
* The plugin bootstrap file
5+
*
6+
* This file is read by WordPress to generate the plugin information in the plugin
7+
* admin area. This file also includes all of the dependencies used by the plugin,
8+
* registers the activation and deactivation functions, and defines a function
9+
* that starts the plugin.
10+
*
11+
* @link https://passifookeca.com
12+
* @since 1.0.0
13+
* @package Foo
14+
*
15+
* @wordpress-plugin
16+
* Plugin Name: Foo Plugin
17+
* Plugin URI: http://foo.plugin
18+
* Description: This is a short description of what the plugin does. It's displayed in the WordPress admin area.
19+
* Version: 1.0.0
20+
* Author: Mister Foo
21+
* Author URI: https://passifookeca.com
22+
* License: GPL-2.0+
23+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
24+
* Text Domain: foo
25+
* Domain Path: /languages
26+
*/
27+
28+
__('I alert checktextdomain task');
29+
30+
31+
32+
// If this file is called directly, abort.
33+
if ( ! defined( 'WPINC' ) ) {
34+
die;
35+
}
36+
37+
/**
38+
* The code that runs during plugin activation.
39+
* This action is documented in includes/class-foo-activator.php
40+
*/
41+
function activate_plugin_name() {
42+
require_once plugin_dir_path( __FILE__ ) . 'includes/class-foo-activator.php';
43+
Foo_Activator::activate();
44+
}
45+
46+
/**
47+
* The code that runs during plugin deactivation.
48+
* This action is documented in includes/class-foo-deactivator.php
49+
*/
50+
function deactivate_plugin_name() {
51+
require_once plugin_dir_path( __FILE__ ) . 'includes/class-foo-deactivator.php';
52+
Foo_Deactivator::deactivate();
53+
}
54+
55+
register_activation_hook( __FILE__, 'activate_plugin_name' );
56+
register_deactivation_hook( __FILE__, 'deactivate_plugin_name' );
57+
58+
/**
59+
* The core plugin class that is used to define internationalization,
60+
* admin-specific hooks, and public-facing site hooks.
61+
*/
62+
require plugin_dir_path( __FILE__ ) . 'includes/class-foo.php';
63+
64+
/**
65+
* Begins execution of the plugin.
66+
*
67+
* Since everything within the plugin is registered via hooks,
68+
* then kicking off the plugin from this point in the file does
69+
* not affect the page life cycle.
70+
*
71+
* @since 1.0.0
72+
*/
73+
function run_plugin_name() {
74+
75+
$plugin = new Foo();
76+
$plugin->run();
77+
78+
}
79+
run_plugin_name();

grunt/aliases.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Grunt aliases
2+
---
3+
# Checktextdomain and makepot task(s)
4+
'build:i18n':
5+
- 'checktextdomain'
6+
- 'makepot'
7+
- 'newer:potomo'
8+
# Makepot and push it to Transifex task(s).
9+
tx-push:
10+
- 'makepot'
11+
- 'exec:txpush_s'
12+
# Pull from Transifex and create .mo task(s).
13+
tx-pull:
14+
- 'exec:txpull'
15+
- 'newer:potomo'
16+
# Build everything
17+
build:
18+
- 'clean'
19+
- 'copy'
20+
- 'compress'
21+
# Default task
22+
default:
23+
- 'makepot'

0 commit comments

Comments
 (0)