-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtranslate.js
52 lines (43 loc) · 1.1 KB
/
translate.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
'use strict';
/**
* External dependencies
*/
import {
src,
dest,
} from 'gulp';
import sort from 'gulp-sort';
import wpPot from 'gulp-wp-pot';
/**
* Internal dependencies
*/
import {
paths,
isProd,
nameFieldDefaults,
} from './constants';
import { getMainConfig } from './utils';
/**
* Generates translation files.
*
* @param {function} done Function to call when async processes finish.
* @return {NodeJS.ReadWriteStream} NodeJS stream.
*/
const translate = ( done ) => {
const config = getMainConfig();
// Bail if translation is disabled in production.
if ( isProd && ! config?.export?.generatePotFile ) {
return done();
}
const translateOptions = {
domain: ( isProd ) ? config.core.slug : nameFieldDefaults.slug,
package: ( isProd ) ? config.core.name : nameFieldDefaults.name,
bugReport: ( isProd ) ? config.core.name : nameFieldDefaults.name,
lastTranslator: ( isProd ) ? config.core.author : nameFieldDefaults.author,
};
return src( paths.languages.src )
.pipe( sort() )
.pipe( wpPot( translateOptions ) )
.pipe( dest( paths.languages.dest ) );
};
export default translate;