Skip to main content

A high-performance markdown translator that supports multiple languages and preserves markdown formatting.

Project description

ZMP Markdown Translator

Platform Badge Component Badge CI Badge License Badge PyPI - Version PyPI - Implementation PyPI - Python Version PyPI - Wheel

A high-performance markdown translator that supports multiple languages and preserves markdown formatting. Uses OpenAI's GPT models for translation.

Features

  • Translates entire directories of markdown files
  • Preserves markdown formatting and structure
  • Supports multiple target languages simultaneously
  • Handles large files through automatic chunking
  • Maintains Docusaurus-compatible directory structures
  • Shows real-time progress with colorized output
  • Enforces consistent translation rules for technical documentation

Translation Rules

The translator follows strict rules to ensure consistent and accurate translations:

Preserved in English

  • All section headers (including those with HTML tags)
  • All HTML-wrapped headers and subheadings
  • Product names (e.g., Cloud Z CP)
  • Platform names (e.g., Kubernetes)
  • Service names (e.g., Container Management Service)
  • Tool names (e.g., Chrome, Gitea)
  • Version numbers and technical specifications
  • Table headers in markdown tables
  • Section IDs in curly braces

Translated to Target Language

  • All paragraphs and content text
  • Descriptions and explanations
  • UI messages and instructions
  • List items and bullet points
  • Table content (except headers)
  • Sentences containing product names (while keeping the names in English)

Consistency Requirements

  • No mixed language content within sentences
  • Complete translation of all paragraphs
  • Preservation of markdown structure and formatting
  • Exact maintenance of whitespace and line numbers

Installation

# Using Poetry (recommended)
poetry install

# Or using pip
pip install .

Usage

Basic Command Structure

poetry run zmp-translate \
  --source-dir SOURCE_PATH \
  --target-dir TARGET_DIR \
  --languages LANG_CODES

The SOURCE_PATH can be either:

  • A path to a single markdown file (.md or .mdx)
  • A directory containing markdown files

Example Usage

# Translate a directory of markdown files
poetry run zmp-translate \
  --source-dir "./repo/docs/ZCP" \
  --target-dir "./repo/i18n" \
  --languages "ko,ja,zh"

# Translate a single markdown file
poetry run zmp-translate \
  --source-dir "./repo/docs/ZCP/introduction.md" \
  --target-dir "./repo/i18n" \
  --languages "ko,ja,zh"

Using short options:

# Directory translation
poetry run zmp-translate \
  --s "./repo/docs/ZCP" \
  --t "./repo/i18n" \
  --l "ko,ja,zh"

# Single file translation
poetry run zmp-translate \
  --s "./repo/docs/ZCP/introduction.md" \
  --t "./repo/i18n" \
  --l "ko"

Command Line Options

  • -s, --source-dir: Path to markdown file or directory containing markdown files (required)
  • -t, --target-dir: Target directory for translations (default: "i18n")
  • -l, --languages: Comma-separated list of target language codes (required)
  • -m, --model: OpenAI model to use (overrides .env setting)
  • -c, --chunk-size: Maximum chunk size for translation (overrides .env setting)
  • -n, --concurrent: Maximum concurrent requests (overrides .env setting)

Supported Language Codes

The following language codes are supported:

Code Language
ko Korean
fr French
ja Japanese
es Spanish
de German
zh Chinese
ru Russian
it Italian
pt Portuguese
ar Arabic

Environment Configuration

Create a .env file in your project root:

# OpenAI Configuration
OPENAI_API_KEY=your-api-key-here
OPENAI_MODEL=your-model-here

# Performance Settings
MAX_CHUNK_SIZE=4000
MAX_CONCURRENT_REQUESTS=5

Directory Structure

The translator maintains a Docusaurus-compatible directory structure based on the source directory name:

  • For *_zcp sources:
    [target_dir]/[lang]/docusaurus-plugin-content-docs-zcp/current/
    
  • For *_apim sources:
    [target_dir]/[lang]/docusaurus-plugin-content-docs-apim/current/
    
  • For *_amdp sources:
    [target_dir]/[lang]/docusaurus-plugin-content-docs-amdp/current/
    
  • For other sources:
    [target_dir]/[lang]/docusaurus-plugin-content-docs/current/
    

Development

# Install dependencies
poetry install

# Run tests
poetry run test

License

This project is distributed under the MIT License. See the LICENSE file for more information.

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

zmp_md_translator-0.1.7.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

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

zmp_md_translator-0.1.7-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

Details for the file zmp_md_translator-0.1.7.tar.gz.

File metadata

  • Download URL: zmp_md_translator-0.1.7.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.11.10 Darwin/24.3.0

File hashes

Hashes for zmp_md_translator-0.1.7.tar.gz
Algorithm Hash digest
SHA256 c475738ed5fe11af4a2b09f1d6b4bd1fbf1e6c0c14c013b048fde02e2844277c
MD5 125c85e0890d2ec5b3aac3b956b9db7b
BLAKE2b-256 4427e5cb8b7b83daba723cea5885996184194b4480217deca0a8521a7b64faa0

See more details on using hashes here.

File details

Details for the file zmp_md_translator-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: zmp_md_translator-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 14.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.11.10 Darwin/24.3.0

File hashes

Hashes for zmp_md_translator-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 c8595e4fb758daeef601e95d570b798b2efcecde0cc7c9c1a1077c9012c61e80
MD5 c814d600e3f218fbe72e221cabfcd9e1
BLAKE2b-256 cf98f98afaedb4ead0b2ab0baa60b877e6864d5531524b4296ebcbc9c81f773c

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