forked from Freemius/wordpress-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
executable file
·167 lines (147 loc) · 5.68 KB
/
gulpfile.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
var gulp = require('gulp');
var path = require('path');
var filesystem = require('fs');
var wpPot = require('gulp-wp-pot');
var gettext = require('gulp-gettext');
var sort = require('gulp-sort');
var pofill = require('gulp-pofill');
var rename = require('gulp-rename');
var clean = require('gulp-clean');
var languagesFolder = './languages/';
var options = require('./transifex-config.json');
function getFolders(dir) {
return filesystem.readdirSync(dir)
.filter(function (file) {
return filesystem.statSync(path.join(dir, file)).isDirectory();
});
}
var transifex = require('gulp-transifex').createClient(options);
// Create POT out of i18n.php.
gulp.task('prepare-source', function () {
gulp.src('**/*.php')
.pipe(sort())
.pipe(wpPot({
destFile : 'freemius.pot',
package : 'freemius',
bugReport : 'https://github.com/Freemius/wordpress-sdk/issues',
lastTranslator : 'Vova Feldman <vova@freemius.com>',
team : 'Freemius Team <admin@freemius.com>',
/*gettextMethods: {
instances: ['this', '_fs'],
methods: [
'get_text_inline'
]
},*/
gettextFunctions: [
{name: 'get_text_inline'},
{name: 'fs_text_inline'},
{name: 'fs_echo_inline'},
{name: 'fs_esc_js_inline'},
{name: 'fs_esc_attr_inline'},
{name: 'fs_esc_attr_echo_inline'},
{name: 'fs_esc_html_inline'},
{name: 'fs_esc_html_echo_inline'},
{name: 'get_text_x_inline', context: 2},
{name: 'fs_text_x_inline', context: 2},
{name: 'fs_echo_x_inline', context: 2},
{name: 'fs_esc_attr_x_inline', context: 2},
{name: 'fs_esc_js_x_inline', context: 2},
{name: 'fs_esc_js_echo_x_inline', context: 2},
{name: 'fs_esc_html_x_inline', context: 2},
{name: 'fs_esc_html_echo_x_inline', context: 2}
/*,
{name: '_fs_text'},
{name: '_fs_x', context: 2},
{name: '_fs_echo'},
{name: '_fs_esc_attr'},
{name: '_fs_esc_attr_echo'},
{name: '_fs_esc_html'},
{name: '_fs_esc_html_echo'},
{name: '_fs_ex', context: 2},
{name: '_fs_esc_attr_x', context: 2},
{name: '_fs_esc_html_x', context: 2},
{name: '_fs_n', plural: 2},
{name: '_fs_n_noop', plural: 2},
{name: '_fs_nx', plural: 2, context: 4},
{name: '_fs_nx_noop', plural: 2, context: 3}*/
]
}))
.pipe(gulp.dest(languagesFolder + 'freemius.pot'));
// Create English PO out of the POT.
return gulp.src(languagesFolder + 'freemius.pot')
.pipe(pofill({
items: function (item) {
// If msgstr is empty, use identity translation
if (!item.msgstr.length) {
item.msgstr = [''];
}
if (!item.msgstr[0]) {
item.msgstr[0] = item.msgid;
}
return item;
}
}))
.pipe(rename('freemius-en.po'))
.pipe(gulp.dest(languagesFolder));
});
// Push updated po resource to transifex.
gulp.task('update-transifex', ['prepare-source'], function () {
return gulp.src(languagesFolder + 'freemius-en.po')
.pipe(transifex.pushResource());
});
// Download latest *.po translations.
gulp.task('download-translations', ['update-transifex'], function () {
return gulp.src(languagesFolder + 'freemius-en.po')
.pipe(transifex.pullResource());
});
// Move translations to languages root.
gulp.task('prepare-translations', ['download-translations'], function () {
var folders = getFolders(languagesFolder);
return folders.map(function (folder) {
return gulp.src(path.join(languagesFolder, folder, 'freemius-en.po'))
.pipe(rename('freemius-' + folder + '.po'))
.pipe(gulp.dest(languagesFolder));
});
});
// Feel up empty translations with English.
gulp.task('translations-feelup', ['prepare-translations'], function () {
return gulp.src(languagesFolder + '*.po')
.pipe(pofill({
items: function (item) {
// If msgstr is empty, use identity translation
if (0 == item.msgstr.length) {
item.msgstr = [''];
}
if (0 == item.msgstr[0].length) {
// item.msgid[0] = item.msgid;
item.msgstr[0] = item.msgid;
}
return item;
}
}))
.pipe(gulp.dest(languagesFolder));
});
// Cleanup temporary translation folders.
gulp.task('cleanup', ['prepare-translations'], function () {
var folders = getFolders(languagesFolder);
return folders.map(function (folder) {
return gulp.src(path.join(languagesFolder, folder), {read: false})
.pipe(clean());
});
});
// Compile *.po to *.mo binaries for usage.
gulp.task('compile-translations', ['translations-feelup'], function () {
// Compile POs to MOs.
return gulp.src(languagesFolder + '*.po')
.pipe(gettext())
.pipe(gulp.dest(languagesFolder))
});
gulp.task('default', [], function () {
gulp.run('prepare-source');
gulp.run('update-transifex');
gulp.run('download-translations');
gulp.run('prepare-translations');
gulp.run('translations-feelup');
gulp.run('cleanup');
gulp.run('compile-translations');
});