bilingual
针对 markdown 文件的命令行翻译 —— 使用翻译云服务(百度、腾讯、小牛)。
该工具的目的:翻译 md 文件。和网页翻译一样,md 文件也包含很多样式(tag)。
此外:
- 我整理了一份 API 选择方案;
- 拆分出两个辅助库:它们有最少依赖,尽可能地降低与命令行功能的耦合,增加通用性。
- translation-api-cn:定义翻译的网络(请求和接收)接口结构体。
- bilingual:根据字节/字符上限抽取 (extract) md 文本。
不足:
- 非异步 I/O:由于 API 调用的 QPS 限制,异步请求暂时不是考虑的重点。
- 含有 HTML 样式的地方,其翻译内容不会是你想要的结果。见 #10。
- 未支持更多翻译 API 服务:性价比是我考虑翻译 API 的主要原因,见 #2。
安装
-
下载 已编译的版本;
-
或者 cargo 安装:
CARGO_PROFILE_RELEASE_LTO=yes CARGO_PROFILE_RELEASE_OPT_LEVEL=3 cargo install bilingual --features bin
-
或者源码编译最新版本:
git clone https://github.com/zjp-CN/bilingual.git cd bilingual cargo build --release --features bin
使用
bilingual.toml
样例:
[]
= "xxxxxxxxxxxxxxxxx"
= "xxxxxxxxxxxxxxxxxxxx"
# limit = { bytes = 6000 }
[]
= "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
= "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# limit = { chars = 2000 }
[]
= "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
# limit = { chars = 5000 }
命令行帮助:
Usage: bilingual [<multiquery...>] -a <api> [-i <id>] [-k <key>] [-f <from>] [-t <to>] [-q <singlequery>] [-m <input-files...>] [-d <input-dirs...>] [-M <output-files...>] [-D <output-dirs...>] [-r] [--forbid-dir-creation] [--toml <toml>]
【bilingual】 作者:苦瓜小仔
针对 markdown 文件的命令行翻译。使用 `bilingual --help` 查看此帮助说明。
例子:
* *****注意:本程序使用翻译云服务,因此需要自行申请翻译 API。命令行提供的 id 和 key 会覆盖掉配置文件的信息。
Options:
-D, --output-dirs 输出目录。默认在输入的目录旁,但是翻译后的目录会增加 `--to` 标识。可多次指定。
-r, --replace-files
--forbid-dir-creation
--toml 配置文件 bilingual.toml 的路径。默认为 `./bilingual.toml` 或者
--help display usage information
实际使用例子:
-
bilingual -a tencent "# 标题" "正文:模拟 markdown 文件的内容。" -f zh -t en
(等价于使用\
转义的例子)结果:正文:模拟 markdown 文件的内容。 Body: simulates the contents of the markdown file.
-
8_6_io_eventqueue-zh.md:源文件来自于此处
-
markdown-it 的 各种 API 翻译后的版本:源文件来自于此处
日志控制见:#29