-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathbuild.translation.specific.mjs
More file actions
185 lines (161 loc) Β· 4.76 KB
/
build.translation.specific.mjs
File metadata and controls
185 lines (161 loc) Β· 4.76 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
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#!/usr/bin/env node
import chalk from 'chalk';
import { spawn } from 'child_process';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// ANSI color codes for console output
const colors = {
red: '\x1b[31m',
green: '\x1b[32m',
yellow: '\x1b[33m',
blue: '\x1b[34m',
magenta: '\x1b[35m',
cyan: '\x1b[36m',
reset: '\x1b[0m',
bold: '\x1b[1m',
};
function log(message, color = 'reset') {
console.log(`${colors[color]}${message}${colors.reset}`);
}
// Supported languages from the automation script
const SUPPORTED_LANGUAGES = {
ar: 'Arabic',
de: 'German',
es: 'Spanish',
fr: 'French',
hi: 'Hindi',
id: 'Indonesian',
ja: 'Japanese',
ko: 'Korean',
pt: 'Portuguese',
ru: 'Russian',
tr: 'Turkish',
vi: 'Vietnamese',
'zh-CN': 'Chinese (Simplified)',
};
function showHelp() {
log('π Push Chain Translation - Specific Language Tool', 'cyan');
log('', 'reset');
log('Usage:', 'bold');
log(' yarn translations:generate:specific <language-code>', 'cyan');
log(' node build.translation.specific.mjs <language-code>', 'cyan');
log('', 'reset');
log('Supported Languages:', 'bold');
Object.entries(SUPPORTED_LANGUAGES).forEach(([code, name]) => {
log(` ${code.padEnd(6)} - ${name}`, 'green');
});
log('', 'reset');
log('Examples:', 'bold');
log(
' yarn translations:generate:specific es # Translate to Spanish only',
'cyan'
);
log(
' yarn translations:generate:specific hi # Translate to Hindi only',
'cyan'
);
log(
' yarn translations:generate:specific zh-CN # Translate to Chinese only',
'cyan'
);
log('', 'reset');
log('π‘ Tips:', 'bold');
log(' β’ This will only translate the specified language', 'yellow');
log(
' β’ Use "yarn translations:generate" to translate all languages',
'yellow'
);
log(
' β’ Use "yarn translations:nuke" to clean up before translating',
'yellow'
);
}
function runAutomationScript(targetLanguage) {
return new Promise((resolve, reject) => {
log(`π Starting translation automation for ${SUPPORTED_LANGUAGES[targetLanguage]}...`, 'cyan');
const child = spawn('node', ['build.translation.automation.mjs', targetLanguage], {
cwd: __dirname,
stdio: 'inherit',
});
child.on('close', (code) => {
if (code === 0) {
log('β
Translation automation completed successfully', 'green');
resolve();
} else {
log(`β Translation automation failed with exit code ${code}`, 'red');
reject(new Error(`Process exited with code ${code}`));
}
});
child.on('error', (error) => {
log(`β Failed to start automation script: ${error.message}`, 'red');
reject(error);
});
});
}
async function main() {
const args = process.argv.slice(2);
// Show help if no arguments or help flag
if (args.length === 0 || args.includes('--help') || args.includes('-h')) {
showHelp();
return;
}
const targetLanguage = args[0];
// Validate language code
if (!SUPPORTED_LANGUAGES[targetLanguage]) {
log(`β Unsupported language code: ${targetLanguage}`, 'red');
log('', 'reset');
log('Supported languages:', 'bold');
Object.entries(SUPPORTED_LANGUAGES).forEach(([code, name]) => {
log(` ${code.padEnd(6)} - ${name}`, 'green');
});
process.exit(1);
}
log('π― Push Chain Translation - Specific Language Mode', 'cyan');
log('β'.repeat(60), 'gray');
log(
`Target Language: ${targetLanguage} (${SUPPORTED_LANGUAGES[targetLanguage]})`,
'bold'
);
log('', 'reset');
try {
// Run the automation script with specific language argument
await runAutomationScript(targetLanguage);
log('', 'reset');
log('π Specific language translation completed successfully!', 'green');
log(
` Translation for ${SUPPORTED_LANGUAGES[targetLanguage]} (${targetLanguage}) is ready.`,
'green'
);
log('', 'reset');
log('π‘ Next steps:', 'bold');
log(
' β’ Check the translated files in static/locales/' +
targetLanguage +
'/',
'cyan'
);
log(' β’ Run "yarn start" to test the translations locally', 'cyan');
log(
' β’ Use "yarn translations:generate" to translate all languages',
'cyan'
);
} catch (error) {
log(`β Translation process failed: ${error.message}`, 'red');
process.exit(1);
}
}
// Handle process termination
process.on('SIGINT', () => {
log('\nβ οΈ Process interrupted', 'yellow');
process.exit(0);
});
process.on('SIGTERM', () => {
log('\nβ οΈ Process terminated', 'yellow');
process.exit(0);
});
main().catch((error) => {
log(`β Unexpected error: ${error.message}`, 'red');
process.exit(1);
});