Skip to main content

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 .

如果想尽量自动把 mdtomd 放进当前机器的可执行路径:

./scripts/install_cli.sh

Windows:

powershell -ExecutionPolicy Bypass -File .\scripts\install_cli.ps1

配置

直接改 config.yaml 即可。

常见方式:

  1. providers.<provider> 里写 model/base_url/api_key/max_tokens
  2. llm.provider 里选默认 provider
  3. translator.chunk_size 留空时,会默认跟当前模型的 max_tokens 一致
  4. 临时覆盖时再用命令行参数或环境变量

如果不想把 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

给插件或脚本用结构化输出:

mdtomd estimate -i examples/doc1.md --json
mdtomd translate -i examples/doc1.md --json

查看 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

VS Code 插件

插件目录在 vscode-extension/

当前插件已支持:

  • 文件树右键翻译 Markdown 文件
  • 文件树右键翻译文件夹
  • 首次安装后自动检测 CLI,缺失时会从 PyPI 自动安装 mdtomd
  • 先调用 estimate --json 弹确认框
  • config.yaml 已配模型里选择
  • 直接在 VS Code 设置面板里按“通用 + 厂商分组”填写模型参数,不需要手改 settings.json
  • 支持 DeepSeek、MiniMax、OpenAI、OpenAI Codex、OpenRouter、Anthropic、Gemini、Z.ai、Kimi、Alibaba、OpenAI Compatible
  • 状态栏显示完成结果

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

mdtomd-0.1.1.tar.gz (34.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mdtomd-0.1.1-py3-none-any.whl (36.3 kB view details)

Uploaded Python 3

File details

Details for the file mdtomd-0.1.1.tar.gz.

File metadata

  • Download URL: mdtomd-0.1.1.tar.gz
  • Upload date:
  • Size: 34.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for mdtomd-0.1.1.tar.gz
Algorithm Hash digest
SHA256 026ff9e1f58e313bb577eccd283c7223a173db7111d09ccce9ffac9ff2827aa2
MD5 7d7a8600b09fc57c5d9924d530478f08
BLAKE2b-256 1d314c0f73d68561a6a0ee3c00a07659c41bff1a8496c6673b526db363c7bca2

See more details on using hashes here.

File details

Details for the file mdtomd-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: mdtomd-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 36.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for mdtomd-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7f7b72266687a7fb2b406157ad98dad91b09cb46d231d3d649e68ced710bf69f
MD5 deab26e017008708c106e33ef034a65e
BLAKE2b-256 3de8f16ce737f1f7cfefbc929a478b23daf6b9dde2d6bfb06ead57f8f84a0592

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page