-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgulpfile.js
96 lines (80 loc) · 2.72 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
const gulp = require('gulp');
const fs = require('fs');
const path = require('path');
const mkdirp = require('mkdirp-sync');
const axios = require('axios');
const dotenv = require('dotenv');
const config = dotenv.config();
const PotExtractor = require('./pot-extractor');
const locoReadKey = config.parsed.LOCO_READ_KEY || 'dhQPr2oER4qtN9vkYuGePC17HZage_ci';
const locoWriteKey = config.parsed.LOCO_WRITE_KEY;
const locales = require('./config/locales.json');
gulp.task('pot', PotExtractor.extract);
gulp.task('locales:import', () => {
mkdirp(path.resolve('./resources/locales'));
const writeLocaleFile = (locale, translates) => {
fs.writeFileSync(path.resolve(`./src/locales/${locale}.json`), JSON.stringify(translates));
};
const extractLocale = (locale) => {
const successLoad = function (response) {
writeLocaleFile(locale, response.data);
};
const errorLoad = (error) => {
console.log(`Locale ${locale} error!`);
writeLocaleFile(locale, {});
};
axios
.get(`https://localise.biz/api/export/locale/${locale}.json`, {
params: {
index: 'text',
format: 'i18next3',
status: 'translated',
key: locoReadKey,
},
})
.then(successLoad)
.catch(errorLoad);
};
const codes = Object.keys(locales);
codes.forEach(extractLocale);
});
gulp.task('locales:export', () => {
if (!locoWriteKey) {
console.log('You have to set Locolise KEY for https://localise.biz/');
return;
}
const tagNew = 'To Translate';
const tagAbsent = 'Deprecated';
const requestBody = fs.readFileSync('build/messages.pot');
const requestParams = {
headers: {
Authorization: `Loco ${locoWriteKey}`,
'Content-Type': 'text/plain',
},
params: {
'tag-new': tagNew,
'tag-updated': tagNew,
'tag-absent': tagAbsent,
'untag-updated': tagAbsent,
'untag-absent': tagNew,
},
};
axios
.post('https://localise.biz/api/import/pot?async=1', requestBody, requestParams)
.then((resp) => {
console.log('Upload done: ', resp.status);
})
.catch((err) => {
console.log(err);
});
});
function copyTask(opts) {
const {source, destination, destinations = [destination], pattern = '**/*'} = opts;
return () => {
let stream = gulp.src(source + pattern, {base: source});
destinations.forEach((destination) => {
stream = stream.pipe(gulp.dest(destination));
});
return stream;
};
}