-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtranslate.cjs
More file actions
50 lines (41 loc) · 1.63 KB
/
Copy pathtranslate.cjs
File metadata and controls
50 lines (41 loc) · 1.63 KB
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
const { execSync } = require('child_process');
const fs = require('fs');
const path = require('path');
/**
* Sequential Translation Script
* Usage: node translate.cjs [lang1,lang2,...]
* If no languages provided, it uses the default Discord set.
*/
const defaultLanguages = [
'es', 'fr', 'pl', 'nl', 'da', 'sv', 'no', 'fi', 'cs',
'hu', 'ro', 'bg', 'hr', 'lt', 'el', 'uk', 'hi', 'th', 'zh', 'vi'
];
const args = process.argv.slice(2);
const languages = args.length > 0 ? args[0].split(',') : defaultLanguages;
const localesDir = path.join(process.cwd(), 'src', 'locales');
const sourceFile = path.join(localesDir, 'tr.json');
if (!fs.existsSync(sourceFile)) {
console.error(`Source file not found: ${sourceFile}`);
process.exit(1);
}
for (const lang of languages) {
try {
console.log(`\n--- Translating to [${lang}] ---`);
execSync(`qlit i18n src/locales/tr.json --to ${lang}`, { stdio: 'inherit' });
const generatedFile = path.join(localesDir, `tr.${lang}.json`);
const targetFile = path.join(localesDir, `${lang}.json`);
if (fs.existsSync(generatedFile)) {
// Move and overwrite the existing locale file
if (fs.existsSync(targetFile)) {
fs.unlinkSync(targetFile);
}
fs.renameSync(generatedFile, targetFile);
console.log(`Successfully saved: ${lang}.json`);
} else {
console.warn(`Warning: qlit finished but ${generatedFile} was not found.`);
}
} catch (error) {
console.error(`Failed to translate to ${lang}:`, error.message);
}
}
console.log('\nAll tasks completed.');