forked from woocommerce/woocommerce-language-packs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gruntfile.js
113 lines (101 loc) · 3.28 KB
/
Gruntfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/* jshint node:true */
module.exports = function( grunt ){
'use strict';
grunt.initConfig({
wget: {
resources: {
files: {
'resources/woocommerce.pot': 'https://raw.githubusercontent.com/woothemes/woocommerce/master/i18n/languages/woocommerce.pot',
'resources/woocommerce-admin.pot': 'https://raw.githubusercontent.com/woothemes/woocommerce/master/i18n/languages/woocommerce-admin.pot'
}
}
},
shell: {
options: {
stdout: true,
stderr: true
},
txpush: {
command: 'tx push -s' // push the resources
},
txpull: {
command: 'tx pull -a -f' // pull the .po files
}
},
potomo: {
options: {
poDel: false
},
dist: {
files: [{
expand: true,
cwd: 'languages/',
src: [
'*.po',
'!*-zh_CN.GB2312.po',
'!*-zh_TW.Big5.po'
],
dest: 'languages/',
ext: '.mo',
nonull: true
}]
},
special: {
files: {
'languages/woocommerce-zh_CN.GB2312.mo': 'languages/woocommerce-zh_CN.GB2312.po',
'languages/woocommerce-admin-zh_CN.GB2312.mo': 'languages/woocommerce-admin-zh_CN.GB2312.po',
'languages/woocommerce-zh_TW.Big5.mo': 'languages/woocommerce-zh_TW.Big5.po',
'languages/woocommerce-admin-zh_TW.Big5.mo': 'languages/woocommerce-admin-zh_TW.Big5.po'
}
}
}
});
// Load NPM tasks to be used here
grunt.loadNpmTasks( 'grunt-shell' );
grunt.loadNpmTasks( 'grunt-wget' );
grunt.loadNpmTasks( 'grunt-potomo' );
// Register tasks
grunt.registerTask( 'default', function () {
grunt.log.writeln( "\n ################################################# " );
grunt.log.writeln( " ###### WooCommerce Language Pack Generator ###### " );
grunt.log.writeln( " ################################################# \n" );
grunt.log.writeln( " # Commands: \n" );
grunt.log.writeln( " grunt compile = Gets the Transifex translations, compiles the .mo files and generates zip files " );
grunt.log.writeln( " grunt resources = Gets the WooCommerce core .pot files and pushes on Transifex " );
});
grunt.registerTask( 'resources', [
'wget:resources',
'shell:txpush'
]);
grunt.registerTask( 'update_translations', [
'shell:txpull',
'potomo'
]);
grunt.registerTask( 'compress', function () {
var fs = require( 'fs' ),
files = fs.readdirSync( 'languages/' ),
done = this.async();
files.forEach( function ( file ) {
var lang = file.replace( /(^woocommerce-admin-)(.+)(.po)/, '$2' );
if ( lang !== file ) {
var dest = 'packages/' + lang + '.zip';
var zip = new require('node-zip')();
zip.file( 'woocommerce-' + lang + '.po', fs.readFileSync( 'languages/woocommerce-' + lang + '.po' ) );
zip.file( 'woocommerce-' + lang + '.mo', fs.readFileSync( 'languages/woocommerce-' + lang + '.mo' ) );
zip.file( 'woocommerce-admin-' + lang + '.po', fs.readFileSync( 'languages/woocommerce-admin-' + lang + '.po' ) );
zip.file( 'woocommerce-admin-' + lang + '.mo', fs.readFileSync( 'languages/woocommerce-admin-' + lang + '.mo' ) );
var data = zip.generate({
base64: false,
compression: 'DEFLATE'
});
fs.writeFileSync( dest, data, 'binary' );
grunt.log.writeln( ' -> ' + lang + ': ' + dest + ' file created successfully' );
}
});
done();
});
grunt.registerTask( 'compile', [
'update_translations',
'compress'
]);
};