Minimal CLI to translate Markdown/text to a target locale via an OpenAI-compatible Chat Completions endpoint.
Project description
md2lang-oai
Minimal CLI that translates Markdown/text into a target locale using an OpenAI-compatible Chat Completions HTTP endpoint.
Install / run (uv)
Run without installing:
uv run md2lang-oai --help
Usage
Translate from stdin to stdout:
echo "Hello" | uv run md2lang-oai --to es-ES
Translate a file:
uv run md2lang-oai --to es-ES --input README.md
Write to a file:
uv run md2lang-oai --to es-ES --input input.md --output output.md
Pipe-friendly (stdin):
cat input.md | uv run md2lang-oai --to es-ES > output.md
Configuration
- API key is read from
OPENAI_API_KEYby default. - Choose a different env var name with
--api-key-env. - Override the endpoint with
--base-url(must be OpenAI-compatible). - Choose a model with
--model. - Adjust timeout with
--timeout(default: 300s for slow/local models). - Control chunking with
--max-tokens(default: 3000 tokens per chunk).
Example:
export OPENAI_API_KEY="..."
uv run md2lang-oai --to es-ES --model gpt-4o-mini --base-url https://api.openai.com/v1 < input.md
Large files and context limits
If your input exceeds the model's context window, the CLI automatically splits it into chunks by paragraph boundaries. Each chunk is translated separately and reassembled. Adjust --max-tokens to fit your model's limit (e.g., 3000 for small models, 8000+ for larger ones).
Example for a local Ollama model with a 4K context:
export OPENAI_API_KEY=test
uv run md2lang-oai --to es-ES --model openchat:7b --base-url http://localhost:11434/v1 --max-tokens 2000 --timeout 600 --input large-file.md --output large-file-es.md
Markdown handling
The tool preserves Markdown structure as much as possible:
- Does not translate inside fenced code blocks (
...). - Does not translate inline code spans (
like this). - Keeps link/image syntax intact; URLs are never translated.
Development
Run tests:
uv run pytest
Project details
Release history Release notifications | RSS feed
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 md2lang_oai-1.0.0.tar.gz.
File metadata
- Download URL: md2lang_oai-1.0.0.tar.gz
- Upload date:
- Size: 19.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d087547b42e8039ec6b385b01b48cfd3905e3f3b10c88da2d54b1a373c6f6a4a
|
|
| MD5 |
bc9f95a1378dc6764b0e81c558c23590
|
|
| BLAKE2b-256 |
b63bb237294d0906b4fdf1394e424f08575b81eaff8c02d1de477461d463ed77
|
Provenance
The following attestation bundles were made for md2lang_oai-1.0.0.tar.gz:
Publisher:
publish-to-pypi.yml on carloscasalar/md2lang-oai
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
md2lang_oai-1.0.0.tar.gz -
Subject digest:
d087547b42e8039ec6b385b01b48cfd3905e3f3b10c88da2d54b1a373c6f6a4a - Sigstore transparency entry: 779115747
- Sigstore integration time:
-
Permalink:
carloscasalar/md2lang-oai@54c78405be0f93b03b12cea948ddc0607e67415e -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/carloscasalar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@54c78405be0f93b03b12cea948ddc0607e67415e -
Trigger Event:
push
-
Statement type:
File details
Details for the file md2lang_oai-1.0.0-py3-none-any.whl.
File metadata
- Download URL: md2lang_oai-1.0.0-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7e915057c7d71f7233352fedb7d91426076468e84a76acf61ded2966d8ab9f99
|
|
| MD5 |
1396710d233026caaa2aecd9aebd8d43
|
|
| BLAKE2b-256 |
3158af1481c2475d8ff095393e7ee3671bb32ee539d8e83b1ff380c62434467b
|
Provenance
The following attestation bundles were made for md2lang_oai-1.0.0-py3-none-any.whl:
Publisher:
publish-to-pypi.yml on carloscasalar/md2lang-oai
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
md2lang_oai-1.0.0-py3-none-any.whl -
Subject digest:
7e915057c7d71f7233352fedb7d91426076468e84a76acf61ded2966d8ab9f99 - Sigstore transparency entry: 779115748
- Sigstore integration time:
-
Permalink:
carloscasalar/md2lang-oai@54c78405be0f93b03b12cea948ddc0607e67415e -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/carloscasalar
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-pypi.yml@54c78405be0f93b03b12cea948ddc0607e67415e -
Trigger Event:
push
-
Statement type: