Files
doc-translator/src/app/index.js
T
anker-na-20 b6dd80e749 First commit
This is base for automatization translating
2026-05-21 10:45:27 +03:00

51 lines
1.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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);
});