-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
translation-update.js
54 lines (49 loc) · 1.41 KB
/
translation-update.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
const cp = require('child_process');
console.log('Extracting all localization calls...');
performNlsExtract();
if (hasNlsFileChanged()) {
const token = getDeepLToken();
if (token) {
console.log('Performing DeepL translation...');
performDeepLTranslation(token);
console.log('Translation finished successfully!');
} else {
console.log('No DeepL API token found in env');
process.exit(1);
}
} else {
console.log('No localization changes found.');
}
function performNlsExtract() {
cp.spawnSync('npm', [
'run',
'theia', 'nls-extract',
'-o', './packages/core/i18n/nls.json',
'-e', 'vscode',
'-f', './packages/**/browser/**/*.{ts,tsx}'
], {
shell: true,
stdio: 'inherit'
});
}
function hasNlsFileChanged() {
const childProcess = cp.spawnSync('git', ['diff', '--exit-code', './packages/core/i18n/nls.json']);
return childProcess.status === 1;
}
function getDeepLToken() {
return process.env['DEEPL_API_TOKEN'];
}
function performDeepLTranslation(token) {
const childProcess = cp.spawnSync('yarn', [
'theia', 'nls-localize',
'-f', './packages/core/i18n/nls.json',
'--free-api', '-k', token
], {
shell: true,
stdio: 'inherit'
});
if (childProcess.status !== 0) {
console.error('DeepL translation failed');
process.exit(1);
}
}