Markdown/MDX translation CLI
Project description
mdtomd
一个给自己用的 Markdown/MDX 翻译工具。
默认会读取当前目录的 config.yaml,支持:
- 单文件翻译
- 目录批量翻译
.md/.markdown/.mdx- 翻译前 token 估算
- 翻译后显示输入 / 输出 token
安装
发布版安装:
python3 -m pip install mdtomd
本地开发安装:
python3 -m pip install -e .
配置
直接改 config.yaml 即可。
常见方式:
- 在
providers.<provider>里写model/base_url/api_key/max_tokens - 在
llm.provider里选默认 provider translator.chunk_size留空时,会默认跟当前模型的max_tokens一致- 临时覆盖时再用命令行参数或环境变量
如果不想把 key 写进配置,可以用环境变量,例如:
export DEEPSEEK_API_KEY="your-key"
用法
快捷命令,先 estimate 再 translate:
mdtomd examples/doc1.md
mdtomd examples
单文件翻译:
mdtomd translate -i examples/doc1.md
目录翻译:
mdtomd translate -i examples
目录输入会自动递归处理,并默认把结果写回原目录,生成 *_zh.md / *_zh.mdx。
如果想输出到别的目录:
mdtomd translate -i examples --output-dir out
先看 token:
mdtomd estimate -i examples/doc1.md
mdtomd estimate -i examples
查看 provider 和模型:
mdtomd providers
mdtomd models
输出说明
单文件翻译完成后会额外打印:
原文 tokens请求输入 tokens回复输出 tokens
其中:
请求输入 tokens是按当前 prompt 和分块策略统计的输入 token回复输出 tokens是模型接口实际返回的 completion token
测试
python3 -m unittest discover -s tests -v
CLI 发布
构建并检查产物:
./scripts/build_cli.sh
上传到 PyPI:
export TWINE_PASSWORD="pypi-***"
./scripts/publish_cli.sh
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mdtomd-0.1.0.tar.gz.
File metadata
- Download URL: mdtomd-0.1.0.tar.gz
- Upload date:
- Size: 33.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9b33aa047063af90026aa929cf87fe01462706c42876725eec4d07bb199538c3
|
|
| MD5 |
2fffa8c02a82ee45dcf55a499e240f64
|
|
| BLAKE2b-256 |
ceca3d6334cbcef0a6b9c15c6132979799423cd1f2b005d0c2d2ab8ea47f2d5b
|
File details
Details for the file mdtomd-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mdtomd-0.1.0-py3-none-any.whl
- Upload date:
- Size: 35.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0c15efb0d16eeaac3e87dafd62d3aaf8c0baeae028755a60888375014fcf7b7b
|
|
| MD5 |
77b17b9c61d8bf2a89aae699f2ad1fa7
|
|
| BLAKE2b-256 |
ce71daa66cda925e251f6ddcccd642387387b3253ef4ff90e69e3fddea4b7ce5
|