-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
29 lines (24 loc) · 938 Bytes
/
index.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
#!/usr/bin/env node
const translateJson = require("./translate-json");
if (require.main === module) {
const args = process.argv.slice(2);
if (args.length < 2) {
console.error("❌ Usage: translate-json <inputLang> <targetLangs> [apiKey]");
process.exit(1);
}
const [inputLang, targetLangs, cliApiKey] = args;
const apiKey = cliApiKey || process.env.GOOGLE_TRANSLATE_API_KEY;
if (!apiKey) {
console.error("❌ Error: GOOGLE_TRANSLATE_API_KEY is not provided. Set it as an environment variable or pass it as the last argument.");
process.exit(1);
}
translateJson(inputLang, targetLangs, apiKey, true).catch((error) => {
if (error.code === "ENOENT") {
console.error(`❌ File not found: ${error.path}. Please ensure the file exists and try again.`);
} else {
console.error(`❌ An error occurred: ${error.message}`);
}
process.exit(1);
});
}
module.exports = translateJson;