b6dd80e749
This is base for automatization translating
51 lines
1.5 KiB
JavaScript
51 lines
1.5 KiB
JavaScript
import fs from "fs";
|
||
import path from "path";
|
||
|
||
/**
|
||
* Простейшая заготовка:
|
||
* - читает все .txt файлы из папки input
|
||
* - копирует их в папку output (пока без реального перевода)
|
||
*/
|
||
|
||
const inputDir = path.join(process.cwd(), "input");
|
||
const outputDir = path.join(process.cwd(), "output");
|
||
|
||
function ensureDirExists(dirPath) {
|
||
if (!fs.existsSync(dirPath)) {
|
||
fs.mkdirSync(dirPath, { recursive: true });
|
||
}
|
||
}
|
||
|
||
async function main() {
|
||
ensureDirExists(inputDir);
|
||
ensureDirExists(outputDir);
|
||
|
||
const files = fs
|
||
.readdirSync(inputDir)
|
||
.filter((name) => name.toLowerCase().endsWith(".txt"));
|
||
|
||
if (files.length === 0) {
|
||
console.log("В папке 'input' нет .txt файлов. Положи туда китайский текст и запусти снова.");
|
||
return;
|
||
}
|
||
|
||
for (const file of files) {
|
||
const sourcePath = path.join(inputDir, file);
|
||
const targetPath = path.join(outputDir, file);
|
||
|
||
const content = fs.readFileSync(sourcePath, "utf8");
|
||
|
||
// TODO: здесь позже будет вызов API перевода (OpenAI/DeepL/Яндекс и т.п.)
|
||
const translated = `ПОКА ЗАГЛУШКА\n\n${content}`;
|
||
|
||
fs.writeFileSync(targetPath, translated, "utf8");
|
||
console.log(`Обработан файл: ${file}`);
|
||
}
|
||
|
||
console.log("Готово.");
|
||
}
|
||
|
||
main().catch((err) => {
|
||
console.error("Ошибка в скрипте:", err);
|
||
process.exit(1);
|
||
}); |