translater

基于多翻译引擎的整句翻译命令行程序,仅支持 中英英中 整句互译,会根据要翻译的语言自动判断。

当前代码包含以下翻译引擎:

以上状态来自实际的 headless Firefox 测试,但网页结构和反自动化策略会随时变化,因此不保证引擎始终可用。首次安装或发现引擎失效时,请运行 translater --init 检测引擎;检测结果会保存在 XDG 数据目录中,默认选择引擎时会排除检测失败的引擎。之后也可以随时重新检测。

本工具适合中英文整句互译,如需翻译单词详细释义,请使用其他工具。

默认会随机选择一个支持的引擎来翻译,这可以避免过于频繁的使用某一翻译引擎而导致 IP 被封。

搭配 goldendict 作为词典之一,一起食用效果更佳!

goldendict

 ╰─ $ bin/translater  'hello world!'
Using Ali
---------- Ali, spent 7.15 seconds use Firefox ----------
你好世界!

 ╰─ $ bin/translater  '那些杀不死你的,终将使你变得更强大'
Using Bing
---------- Bing, spent 6.07 seconds use Firefox ----------
What doesn't kill you will make you stronger

某一翻译引擎运行一次之后,如果再次选择该引擎,因为使用了浏览器 cache, 速度将得到极大提升!

在我本地测试,平均出翻译结果时间在两秒左右。

 ╰─ $ bin/translater -e ali  "Those who can't kill you will eventually make you stronger."
Using Ali
---------- Ali, spent 1.91 seconds use Firefox cache ----------
那些不能杀死你的人最终会让你更强大
 
 ╰─ $ bin/translater -e bing '你好,世界!'
Using Bing
---------- Bing, spent 2.90 seconds use Firefox cache ----------
Hello, world!

translater --help 获取有关参数的更多帮助。

Arch Linux 安装

可以通过 Arch Linux 的 AUR 仓库安装 translater-git自建源

yay -Syu translater

Dependencies

火狐(Firefox)浏览器及 geckodriver (selenium driver for Firefox).

以 Arch Linux 为例:

$: pacman -S firefox geckodriver

或安装 Firefox 之后,自己下载 geckodriver,并拷贝至 /usr/local/bin

Sqlite3

translater 使用 Sqlite3 保存缓存的 session,来加速翻译流程。

translster 同时还维护一个最快引擎的数据库,会自动记录每次不同引擎翻译的耗时, 可以使用 --profile 初始化数据库以及分析那个翻译引擎速度快一些。,见:--auto 以及 --profile 选项。

Installation

release 页面 下载(单文件)最新版, 扔到 $PATH 的文件夹里,目前支持 Linux 和 OSX.

或者从源码编译安装:

$: make release
$: sudo make install

已知限制

  1. 翻译依赖第三方网页 DOM,不是官方 API;站点改版后可能需要更新 selector。

Contributing

  1. Fork it (https://github.com/zw963/translater/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors