multranslate
Advanced tools
Comparing version 0.4.4 to 0.5.0
@@ -7,3 +7,34 @@ #!/usr/bin/env node | ||
import Database from 'better-sqlite3' | ||
import path from 'path' | ||
import { fileURLToPath } from 'url' | ||
import { readFileSync } from 'fs' | ||
import { Command } from 'commander' | ||
const __filename = fileURLToPath(import.meta.url) | ||
const __dirname = path.dirname(__filename) | ||
const pkg = JSON.parse(readFileSync(path.join(__dirname, 'package.json'), 'utf-8')) | ||
const translators = ['all', 'Google', 'DeepL', 'Reverso', 'MyMemory'] | ||
let selectedTranslator = 'all' | ||
const program = new Command() | ||
program | ||
.description(pkg.description) | ||
.version(pkg.version) | ||
.option('-t, --translator <name>', `select translator: ${translators.join(', ')}`, 'all') | ||
.parse(process.argv) | ||
const inputTranslator = program.opts().translator.toLowerCase() | ||
const translatorsLowerCase = translators.map(t => t.toLowerCase()) | ||
if (!translatorsLowerCase.includes(inputTranslator)) { | ||
console.error(`Invalid parameter value. Choose one of: ${translators.join(', ')}`) | ||
process.exit(1) | ||
} | ||
selectedTranslator = translators[translatorsLowerCase.indexOf(inputTranslator)] | ||
var screen = blessed.screen({ | ||
@@ -222,2 +253,39 @@ autoPadding: true, | ||
if (selectedTranslator === "Google") { | ||
outputBox2.hidden = true | ||
outputBox3.hidden = true | ||
outputBox4.hidden = true | ||
outputBox1.width = '100%' | ||
outputBox1.height = '79%' | ||
outputBox1.top = '20%' | ||
outputBox1.left = '0%' | ||
} | ||
else if (selectedTranslator === "DeepL") { | ||
outputBox1.hidden = true | ||
outputBox3.hidden = true | ||
outputBox4.hidden = true | ||
outputBox2.width = '100%' | ||
outputBox2.height = '79%' | ||
outputBox2.top = '20%' | ||
outputBox2.left = '0%' | ||
} | ||
else if (selectedTranslator === "Reverso") { | ||
outputBox1.hidden = true | ||
outputBox2.hidden = true | ||
outputBox4.hidden = true | ||
outputBox3.width = '100%' | ||
outputBox3.height = '79%' | ||
outputBox3.top = '20%' | ||
outputBox3.left = '0%' | ||
} | ||
else if (selectedTranslator === "MyMemory") { | ||
outputBox1.hidden = true | ||
outputBox2.hidden = true | ||
outputBox3.hidden = true | ||
outputBox4.width = '100%' | ||
outputBox4.height = '79%' | ||
outputBox4.top = '20%' | ||
outputBox4.left = '0%' | ||
} | ||
// Добавление панелей на экран | ||
@@ -232,4 +300,2 @@ screen.append(inputBox) | ||
// screen.append(textInfo) | ||
// ------------------------------- Auto-detect Language --------------------------------- | ||
@@ -267,14 +333,8 @@ | ||
const dbPath = path.join(__dirname, 'translation-history.db') | ||
const clearHistory = 500 // Количество объектов истории для хранения в базе данных | ||
let maxID = 0 | ||
let curID = 0 | ||
const clearHistory = 500 // Количество объектов истории для хранения в базе данных | ||
import path from 'path' | ||
import { fileURLToPath } from 'url' | ||
const __filename = fileURLToPath(import.meta.url) | ||
const __dirname = path.dirname(__filename) | ||
function writeHistory(data) { | ||
const dbPath = path.join(__dirname, 'translation-history.db') | ||
const db = new Database(dbPath) | ||
@@ -294,3 +354,2 @@ db.exec(` | ||
function getAllId() { | ||
const dbPath = path.join(__dirname, 'translation-history.db') | ||
const db = new Database(dbPath) | ||
@@ -314,3 +373,2 @@ let result | ||
function readHistory(id) { | ||
const dbPath = path.join(__dirname, 'translation-history.db') | ||
const db = new Database(dbPath) | ||
@@ -331,3 +389,2 @@ const query = 'SELECT inputText,created_at FROM translationTable WHERE id = ?' | ||
function deleteHistory(id) { | ||
const dbPath = path.join(__dirname, 'translation-history.db') | ||
const db = new Database(dbPath) | ||
@@ -1021,17 +1078,51 @@ const query = 'DELETE FROM translationTable WHERE id = ?' | ||
// Запросы к API на перевод | ||
const [ | ||
translatedText1, | ||
translatedText2, | ||
translatedText3, | ||
translatedText4 | ||
] = await Promise.all([ | ||
translateGoogle(textToTranslate), | ||
translateDeepLX(textToTranslate), | ||
translateReversoFetch(textToTranslate), | ||
translateMyMemory(textToTranslate) | ||
]) | ||
outputBox1.setContent(translatedText1) | ||
outputBox2.setContent(translatedText2) | ||
outputBox3.setContent(translatedText3) | ||
outputBox4.setContent(translatedText4) | ||
if (selectedTranslator === "Google") { | ||
const [ | ||
translatedText, | ||
] = await Promise.all([ | ||
translateGoogle(textToTranslate) | ||
]) | ||
outputBox1.setContent(translatedText) | ||
} | ||
else if (selectedTranslator === "DeepL") { | ||
const [ | ||
translatedText, | ||
] = await Promise.all([ | ||
translateDeepLX(textToTranslate) | ||
]) | ||
outputBox2.setContent(translatedText) | ||
} | ||
else if (selectedTranslator === "Reverso") { | ||
const [ | ||
translatedText, | ||
] = await Promise.all([ | ||
translateReversoFetch(textToTranslate) | ||
]) | ||
outputBox3.setContent(translatedText) | ||
} | ||
else if (selectedTranslator === "MyMemory") { | ||
const [ | ||
translatedText, | ||
] = await Promise.all([ | ||
translateMyMemory(textToTranslate) | ||
]) | ||
outputBox4.setContent(translatedText) | ||
} | ||
else if (selectedTranslator === "all") { | ||
const [ | ||
translatedText1, | ||
translatedText2, | ||
translatedText3, | ||
translatedText4 | ||
] = await Promise.all([ | ||
translateGoogle(textToTranslate), | ||
translateDeepLX(textToTranslate), | ||
translateReversoFetch(textToTranslate), | ||
translateMyMemory(textToTranslate) | ||
]) | ||
outputBox1.setContent(translatedText1) | ||
outputBox2.setContent(translatedText2) | ||
outputBox3.setContent(translatedText3) | ||
outputBox4.setContent(translatedText4) | ||
} | ||
screen.render() | ||
@@ -1038,0 +1129,0 @@ inputBox.focus() |
{ | ||
"name": "multranslate", | ||
"version": "0.4.4", | ||
"version": "0.5.0", | ||
"description": "Cross-platform TUI for translating text in multiple translators simultaneously, with support for translation history and automatic language detection.", | ||
@@ -35,3 +35,4 @@ "keywords": [ | ||
"blessed": "^0.1.81", | ||
"clipboardy": "^4.0.0" | ||
"clipboardy": "^4.0.0", | ||
"commander": "^12.1.0" | ||
}, | ||
@@ -38,0 +39,0 @@ "bin": { |
@@ -15,3 +15,3 @@ <h1 align="center"> | ||
Терминальный пользовательский интерфейс (TUI) на базе библиотеки [Blessed](https://github.com/chjj/blessed) для одновременного перевода текста с использованием нескольких источников перевода. Все источники не требуют токена доступа или других настроек. Поддерживает **автоматическое определение исходного и целевого языка** на уровне кода между английским и русским (по умолчанию) и доступ к **истории переводов** через [SQLite](https://github.com/WiseLibs/better-sqlite3) (до 500 запросов, после чего применяется автоматическая чистка старых значений из истории). | ||
Терминальный пользовательский интерфейс (TUI) на базе библиотеки [Blessed](https://github.com/chjj/blessed) для одновременного перевода текста с использованием нескольких источников перевода. Все источники не требуют токена доступа или других настроек. Поддерживает **автоматическое определение исходного и целевого языка** на уровне кода между английским и русским (по умолчанию), а также доступ к **истории переводов** через [SQLite](https://github.com/WiseLibs/better-sqlite3) (до 500 запросов, после чего применяется автоматическая чистка старых значений из истории). | ||
@@ -25,3 +25,3 @@ ![interface](/image/interface.jpg) | ||
- [Reverso](https://www.reverso.net) - самый стабильный, бесплатный и без ограничений на количество символов (версия на сайте ограничена 2000 символам и 900 через приложение, через `API` возможно получить до 8000). Не содержит официальной документации, запрос был получен с официального сайта через *DevTools*. | ||
- [MyMemory](https://mymemory.translated.net/doc/spec.php) - бесплатный и открытый API (ограничение в 500 символов на запрос). Поддверживает до 3 вариантов ответа для коротких запросов. | ||
- [MyMemory](https://mymemory.translated.net/doc/spec.php) - бесплатный и открытый API (ограничение в 500 символов на запрос). Поддерживает до 3 вариантов ответа для коротких запросов. | ||
@@ -28,0 +28,0 @@ > ⚠ **Reverso** не поддерживает работу через **Axios** (ошибка: `Invalid header value char`), вместо этого используется **Fetch**. По этой причине не получается упаковать пакет с помощью `pkg` без ошибок при запуске. |
@@ -22,3 +22,4 @@ <h1 align="center"> | ||
- [Google](https://translate.google.com) - free and unlimited [API](https://github.com/vitalets/google-translate-api) using [serverless](https://github.com/olavoparno/translate-serverless-vercel) hosted on Vercel. Available for translation more than 5000 characters. | ||
- [DeepL](https://www.deepl.com) - free API via [DeepLX](https://github.com/OwO-Network/DeepLX) using [serverless](https://github.com/LegendLeo/deeplx-serverless) hosted on [Vercel](https://github.com/bropines/Deeplx-vercel). There are limitations on the number of frequent requests for translation, can have limitations when using a large number of - [Reverso](https://www.reverso.net) - the most stable, free and without any limitation on the number of characters (version on the site is limited to 2000 characters and 900 through the application, through the API can get up to 8000). Does not contain official documentation, request was received from official site via *DevTools*.characters (official limit of 5000 characters per request). | ||
- [DeepL](https://www.deepl.com) - free API via [DeepLX](https://github.com/OwO-Network/DeepLX) using [serverless](https://github.com/LegendLeo/deeplx-serverless) hosted on [Vercel](https://github.com/bropines/Deeplx-vercel). There are limitations on the number of frequent requests for translation, can have limitations when using a large number of | ||
- [Reverso](https://www.reverso.net) - the most stable, free and without any limitation on the number of characters (version on the site is limited to 2000 characters and 900 through the application, through the API can get up to 8000). Does not contain official documentation, request was received from official site via *DevTools*.characters (official limit of 5000 characters per request). | ||
- [MyMemory](https://mymemory.translated.net/doc/spec.php) - free and open API (limit of 500 characters per request). Supports up to 3 response options for short queries. | ||
@@ -25,0 +26,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1325869
9
1847
92
5
1
+ Addedcommander@^12.1.0
+ Addedcommander@12.1.0(transitive)