High-performance automated translation platform powered by Rust
Project description
LangLint
Breaking Language Barriers in Global Collaboration 🚀 | Now 10-50x Faster with Rust
LangLint is a high-performance, extensible automated translation platform powered by Rust, designed to eliminate language barriers in code comments and docstrings across software development and international collaboration.
🎉 v1.0.0 Stable Release: Production-ready! 10-50x faster, 143 tests passing, 100% code coverage.
🚀 Quick Start
Installation (Same as Before!)
# Install via pip (now installs Rust-powered version)
pip install langlint
# Or use pipx for isolated environment
pipx install langlint
# Or use uv for fastest installation
uv tool install langlint
💡 Zero Breaking Changes: Your existing scripts work immediately. Just upgrade and enjoy 10-50x speedup!
Basic Usage
# Scan translatable content (now 10x faster!)
langlint scan src/
# Translate (preserve original files)
langlint translate src/ -s auto -t en -o output/
# In-place translation (auto backup)
langlint fix src/ -s auto -t en
📸 Translation Demo
Before (Japanese code with comments):
def calculate_total(items):
"""商品の合計金額を計算する"""
total = 0
for item in items:
# 価格を累積
total += item.price
return total
def apply_discount(price, rate):
"""割引を適用する関数"""
if rate < 0 or rate > 1:
# 無効な割引率
raise ValueError("割引率は0から1の間である必要があります")
# 割引後の価格を計算
discounted = price * (1 - rate)
return round(discounted, 2)
After (One command: langlint fix example.py -s ja -t en):
def calculate_total(items):
"""Calculate the total price of the product"""
total = 0
for item in items:
# Accumulate prices
total += item.price
return total
def apply_discount(price, rate):
"""Function to apply discount"""
if rate < 0 or rate > 1:
# Invalid discount rate
raise ValueError("Discount rate must be between 0 and 1")
# Calculate discounted price
discounted = price * (1 - rate)
return round(discounted, 2)
Result:
- ✅ 9 units translated in <10ms (Rust) vs ~100ms (Python)
- ✅ 13x faster processing time
- ✅ Code structure preserved
- ✅ Syntax remains valid
- ✅ Automatic backup created
✨ Code still works perfectly! Only comments and docstrings are translated.
Core Commands
| Command | Function | Example |
|---|---|---|
scan |
Scan translatable content | langlint scan . |
translate |
Translate to new directory | langlint translate . -s auto -t en -o output/ |
fix |
In-place translate + backup | langlint fix . -s auto -t en |
Default: Google Translate, Auto-detect → English (Free, no API Key required)
Other Translators (OpenAI, DeepL)
openai- OpenAI GPT (requiresOPENAI_API_KEY) - 🚧 Coming soon in Rust versiondeepl- DeepL (requiresDEEPL_API_KEY) - 🚧 Coming soon in Rust versiongoogle- Google Translate (Free, no key needed) - ✅ Available nowmock- Mock translator for testing - ✅ Available now
✨ Key Features
🌍 Multilingual Translation Support
- ✅ 100+ Language Pairs: French↔English, German↔Chinese, Spanish↔Japanese, etc.
- ✅ Smart Language Detection: Auto-detect source language or specify manually
- ✅ Syntax Protection: Automatically excludes string literals and f-strings
- ✅ High-Performance Concurrency: Batch translation for multiple files (true parallelism in Rust!)
# Basic usage (auto-detect → English)
langlint fix src/
# European languages (French → English, specify source to avoid misdetection)
langlint fix french_code.py -s fr
# Translate to other languages (German → Chinese)
langlint fix german_code.py -s de -t zh-CN
📋 Supported Languages List
European Languages: English (en), French (fr), German (de), Spanish (es), Italian (it), Portuguese (pt), Russian (ru), Dutch (nl), Polish (pl), Swedish (sv)
Asian Languages: Simplified Chinese (zh-CN), Traditional Chinese (zh-TW), Japanese (ja), Korean (ko), Thai (th), Vietnamese (vi), Hindi (hi), Indonesian (id)
Other Languages: Arabic (ar), Hebrew (he), Turkish (tr), Greek (el), Persian (fa)
Note: European languages (French, German, Spanish, Italian, etc.) must use the -s parameter to specify source language, otherwise they will be misidentified as English!
🔌 Supported File Types (28+)
- Python:
.py - JavaScript/TypeScript:
.js,.ts,.jsx,.tsx - Systems:
.rs(Rust),.go,.c,.cpp,.h,.hpp - JVM:
.java,.scala,.kt(Kotlin) - Others:
.cs,.php,.rb,.swift,.dart,.lua,.sh,.bash,.sql,.r,.R,.m,.vim - Notebooks:
.ipynb(Jupyter) - ✅ Full support in Rust
What gets translated: Comments and docstrings in code files. String literals and configuration values are preserved.
⚡ High Performance
Rust-powered performance is 10-50x faster than the previous Python implementation! 🚀
True multi-threading (no GIL), zero-cost abstractions, and efficient memory management make LangLint blazing fast.
📖 Detailed Usage Guide (Click to expand)
Basic Commands
# Scan translatable content
langlint scan path/to/files
# Translate to new directory
langlint translate path/to/files -o output/
# In-place translation (auto backup)
langlint fix path/to/files
Multilingual Translation Scenarios
# Scenario 1: Translate French code comments to English
langlint scan french_project/ -o report.json --format json
langlint translate french_project/ -s fr -o english_project/
# Scenario 2: Internationalize codebase
langlint fix src/
pytest tests/ # Verify code still works
# Scenario 3: Translate Jupyter Notebook
langlint fix notebooks/ -s zh-CN -t en
Advanced Parameters
# Exclude specific files
langlint translate src/ -o output/ -e "**/test_*" -e "**/__pycache__/"
# Dry-run preview
langlint translate src/ -s fr -t en --dry-run
# Use different translators
langlint translate src/ -s zh-CN -t en --translator google # Google Translate (available now)
langlint translate src/ -s zh-CN -t en --translator mock # Mock translator for testing
🔧 Python API Usage (Click to expand)
LangLint can be used as a library in your Python projects. The API is 100% compatible with v0.0.6, but now runs on Rust!
Basic API Usage (Rust-Powered)
# Import the Rust-powered module
import langlint_py
# Scan files (now 10x faster!)
result = langlint_py.scan(
"src/",
format="json",
verbose=True
)
print(result) # JSON output
# Translate (now 10x faster!)
result = langlint_py.translate(
"example.py",
source="zh",
target="en",
translator="google", # or "mock"
output="example_en.py",
dry_run=False
)
print(result) # {"status": "success", "translated": 9, ...}
Batch Processing Example
import langlint_py
import json
from pathlib import Path
# Scan entire project
result_json = langlint_py.scan("src/", format="json")
result = json.loads(result_json)
print(f"Found {result['total_units']} translatable units in {result['files_scanned']} files")
# Translate all Python files
for py_file in Path("src").rglob("*.py"):
print(f"Translating {py_file}...")
langlint_py.translate(
str(py_file),
source="zh",
target="en",
translator="mock",
dry_run=False
)
Performance Comparison
import time
import langlint_py
# Benchmark
start = time.time()
result = langlint_py.scan("large_project/", format="json")
elapsed = time.time() - start
print(f"Scanned in {elapsed*1000:.2f}ms (Rust-powered!)")
# Typical: 3-5ms for 1000 lines
# Python v0.0.6 would take: 40-50ms for the same
⚙️ Configuration File (Click to expand)
LangLint supports multiple configuration formats. Create one of these files in your project root:
Option 1: .langlint.yml (Recommended)
# Global settings
translator: "google" # openai, deepl, google, mock
target_lang: "en"
source_lang: ["zh-CN", "ja", "ko"]
backup: true # Create backup files before in-place translation (default: true)
# File processing
include:
- "**/*.py"
- "**/*.js"
- "**/*.ts"
exclude:
- "**/node_modules/**"
- "**/test_*"
- "**/data/**"
# Path-specific overrides
path_configs:
"**/tests/**":
translator: "mock"
backup: false # Don't backup test files
"**/docs/**":
translator: "google"
target_lang: "en"
Option 2: pyproject.toml
[tool.langlint]
translator = "google"
target_lang = "en"
source_lang = ["zh-CN", "ja", "ko"]
backup = true
exclude = ["**/test_*", "**/data/"]
# Path-specific settings
[tool.langlint."backend/**/*.py"]
translator = "google"
Backup Control
The backup option controls whether backup files (.backup extension) are created during in-place translation:
# Use config file setting
langlint fix src/
# Force disable backup (overrides config)
langlint fix src/ --no-backup
Priority: --no-backup flag > config file backup setting > default (true)
Configuration is loaded by the Rust core for maximum performance.
🤖 CI/CD Integration
Integrate into Your Workflow Like Ruff - Automate multilingual code checking and translation!
Supports: GitHub Actions ✅ | GitLab CI ✅ | Azure Pipelines ✅ | Pre-commit Hooks ✅ | Docker ✅
🎯 Best Practice: Use with Ruff
# First, check code quality with Ruff
ruff check . --fix
# Then, translate with LangLint (now 10x faster with Rust!)
langlint fix .
# Finally, run Ruff again to ensure translated code meets standards
ruff check .
📋 View Complete CI/CD Integration Configuration (Click to expand)
Integrate LangLint into your CI/CD pipeline to automate multilingual code checking and translation, just as simple as using Ruff for code quality checks!
GitHub Actions Integration ⭐ Recommended
1️⃣ Automatic Translation Coverage Check
Add to .github/workflows/langlint-check.yml:
name: LangLint Check
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
schedule:
- cron: '0 8 * * *' # Daily check to catch new untranslated content
jobs:
langlint-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
- name: Install LangLint (Rust-powered!)
run: |
pip install langlint
- name: Scan for translatable content
run: |
langlint scan . -o report.json --format json
- name: Check translation requirements
run: |
# Check for translatable content
if [ -s report.json ]; then
echo "⚠️ Found translatable content. Run 'langlint translate' locally."
cat report.json
else
echo "✅ No translatable content found."
fi
2️⃣ Auto-Translate and Create PR
Automatically translate Chinese code to English and create a Pull Request:
name: Auto Translate
on:
workflow_dispatch: # Manual trigger
schedule:
- cron: '0 8 * * *' # Run daily at 8 AM UTC to keep translations fresh
jobs:
translate:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install LangLint (Rust-powered!)
run: pip install langlint
- name: Translate code
run: |
langlint translate src/ -o src_en/
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: 'chore: auto translate to English'
title: '🌐 Auto-translated code to English'
body: |
This PR contains auto-translated code from Chinese to English.
**Translation Details:**
- Source Language: Chinese (zh-CN)
- Target Language: English (en)
- Translator: Google Translate
Please review carefully before merging.
branch: auto-translate/en
delete-branch: true
3️⃣ Pre-commit Integration Check
Block commits containing untranslated Chinese comments:
name: Pre-commit Check
on:
pull_request:
types: [opened, synchronize]
jobs:
check-translation:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install LangLint (Rust-powered!)
run: pip install langlint
- name: Check for non-English content
run: |
# Scan for translatable content
langlint scan . -o report.json --format json
# Check if any non-English content exists
# This checks for common non-English language codes
if grep -qE '"(zh-CN|zh-TW|ja|ko|fr|de|es|it|pt|ru|ar|hi|th|vi)"' report.json; then
echo "❌ Found non-English content. Please translate before committing."
echo "Run: langlint fix ."
echo ""
echo "Detected languages:"
grep -oE '"(zh-CN|zh-TW|ja|ko|fr|de|es|it|pt|ru|ar|hi|th|vi)"' report.json | sort -u
exit 1
fi
echo "✅ All content is in English."
4️⃣ Batch Translate Project Code
Automatically translate all code comments in a project:
name: Translate Project
on:
workflow_dispatch: # Manual trigger
jobs:
translate-project:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
- name: Install LangLint (Rust-powered!)
run: pip install langlint
- name: Translate all code comments
run: |
# Translate Python files
langlint fix src/ -s zh-CN -t en
# Translate JavaScript files
langlint fix frontend/ -s zh-CN -t en
# Translate Jupyter Notebooks
langlint fix notebooks/ -s zh-CN -t en
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: 'chore: translate code comments to English'
title: '🌐 Translated code comments'
branch: translate-comments
Pre-commit Hooks Integration
Like Ruff, add LangLint to your pre-commit configuration.
Install pre-commit
pip install pre-commit
Configure .pre-commit-config.yaml
Option 1: Remote Hook (Recommended) - Automatically installs LangLint when needed:
repos:
# LangLint - Check translatable content (Rust-powered!)
- repo: https://github.com/HzaCode/Langlint
rev: main # ✅ Use 'main' to always get the latest updates and language coverage
hooks:
- id: langlint-scan
# Optional: Auto-translate (use with caution)
- id: langlint-fix
stages: [manual] # Manual trigger only
# Ruff - Code checking (for comparison)
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.0
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
💡 Why use
rev: main? Keepingrev: mainensures you automatically benefit from the latest Langlint improvements, new language support, and bug fixes without manual updates. Perfect for rapidly evolving projects!
Option 2: Local Hook - Uses your locally installed LangLint:
repos:
# LangLint - Check translatable content (Rust-powered!)
- repo: local
hooks:
- id: langlint-scan
name: LangLint Scan
entry: langlint scan
language: system
types: [python]
pass_filenames: true
verbose: true
# Optional: Auto-translate (use with caution)
- id: langlint-fix
name: LangLint Auto-fix
entry: langlint fix
language: system
types: [python]
pass_filenames: true
stages: [manual] # Manual trigger only
# Ruff - Code checking (for comparison)
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.0
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Note:
- Remote hook: pre-commit will automatically install LangLint in an isolated environment. No manual installation needed!
- Local hook: Requires
pip install langlintfirst, but gives you control over the version.
Use pre-commit
# Install hooks
pre-commit install
# Auto-run on each commit
git commit -m "feat: add new feature"
# Manually run all hooks
pre-commit run --all-files
# Manually trigger translation
pre-commit run langlint-fix --all-files
GitLab CI Integration
Add to .gitlab-ci.yml:
stages:
- lint
- translate
langlint-check:
stage: lint
image: python:3.11
script:
- pip install langlint
- langlint scan . -o report.json --format json
- |
if [ -s report.json ]; then
echo "⚠️ Found translatable content"
cat report.json
fi
artifacts:
paths:
- report.json
expire_in: 1 week
langlint-translate:
stage: translate
image: python:3.11
only:
- main
script:
- pip install langlint
- langlint translate src/ -o src_en/
artifacts:
paths:
- src_en/
expire_in: 1 month
Azure Pipelines Integration
Add to azure-pipelines.yml:
trigger:
- main
- develop
pool:
vmImage: 'ubuntu-latest'
steps:
- task: UsePythonVersion@0
inputs:
versionSpec: '3.11'
displayName: 'Use Python 3.11'
- script: |
pip install langlint
displayName: 'Install LangLint (Rust-powered!)'
- script: |
langlint scan . -o $(Build.ArtifactStagingDirectory)/report.json --format json
displayName: 'Scan translatable content'
- task: PublishBuildArtifacts@1
inputs:
pathToPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: 'langlint-report'
Docker Integration
Dockerfile Example
FROM python:3.11-slim
WORKDIR /app
# Install LangLint (Rust-powered!)
RUN pip install --no-cache-dir langlint
# Copy source code
COPY . .
# Run translation (now 10x faster!)
CMD ["langlint", "translate", ".", "-t", "google", "-s", "zh-CN", "-l", "en", "-o", "output/"]
Use Docker Compose
version: '3.8'
services:
langlint:
image: python:3.11-slim
volumes:
- .:/app
working_dir: /app
command: >
sh -c "
pip install langlint &&
langlint translate src/ -o src_en/
"
VS Code Integration (Coming Soon)
Upcoming VS Code extension will provide:
- ✅ Real-time translation suggestions
- ✅ Right-click menu translation
- ✅ Auto-translate on save
- ✅ Translation status indicator
Best Practices
1️⃣ Keep LangLint Updated for Maximum Coverage
# For pipx users (recommended)
pipx upgrade langlint
# For uv users
uv tool upgrade langlint
# For pip users
pip install --upgrade langlint
Why stay updated? LangLint continuously improves language detection accuracy, adds new file type support, and fixes edge cases. Regular updates ensure the best translation quality.
2️⃣ Phased Integration
# Phase 1: Scan only, don't block CI
langlint scan . -o report.json --format json
# Phase 2: Generate warnings
if grep -qE '"(zh-CN|zh-TW|ja|ko|fr|de|es|it|pt|ru|ar|hi|th|vi)"' report.json; then
echo "⚠️ Warning: Found non-English content"
grep -oE '"(zh-CN|zh-TW|ja|ko|fr|de|es|it|pt|ru|ar|hi|th|vi)"' report.json | sort -u
fi
# Phase 3: Block commits (strict mode)
if grep -qE '"(zh-CN|zh-TW|ja|ko|fr|de|es|it|pt|ru|ar|hi|th|vi)"' report.json; then
echo "❌ Error: Non-English content found. Must translate before merging"
grep -oE '"(zh-CN|zh-TW|ja|ko|fr|de|es|it|pt|ru|ar|hi|th|vi)"' report.json | sort -u
exit 1
fi
3️⃣ Translate Only New Content
# Get changed files (handles filenames with spaces)
git diff -z --name-only origin/main... | xargs -0 langlint fix
# Or using a loop for more control
git diff --name-only origin/main... | while IFS= read -r file; do
langlint fix "$file"
done
4️⃣ Cache Optimization
# Enable cache in GitHub Actions
- name: Cache LangLint
uses: actions/cache@v3
with:
path: ~/.cache/langlint
key: ${{ runner.os }}-langlint-${{ hashFiles('**/*.py') }}
restore-keys: |
${{ runner.os }}-langlint-
Enterprise Deployment
Self-hosted Runner
jobs:
translate:
runs-on: [self-hosted, linux, x64]
steps:
- name: Translate with Google Translate
run: |
langlint translate src/ -s zh-CN -t en --translator google -o src_en/
# Coming soon: OpenAI translator
# - name: Translate with OpenAI (🚧 Coming in v0.2.0)
# env:
# OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
# run: |
# langlint translate src/ -s zh-CN -t en --translator openai -o src_en/
Secrets Management
# Configure in GitHub Secrets
# Settings > Secrets and variables > Actions > New repository secret
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
DEEPL_API_KEY: ${{ secrets.DEEPL_API_KEY }}
Through CI/CD integration, LangLint can become an indispensable part of your development workflow, just like Ruff, automating multilingual code translation and improving team collaboration efficiency!
🛠️ Development
Building from Source
# Prerequisites
# 1. Install Rust (https://rustup.rs/)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# 2. Install Python 3.8+
python --version
# 3. Install maturin (Rust-Python build tool)
pip install maturin
# Build and install locally
maturin develop --release
# Run Rust tests
cargo test --workspace --exclude langlint_py
# Run Python tests
pytest tests/ --cov=python_wrapper/langlint --cov-report=term-missing
# Run ignored tests (Google API - requires network)
cargo test --workspace --exclude langlint_py -- --ignored
🧪 Testing
# Run Rust tests
cargo test --workspace --exclude langlint_py
# Run Python tests
pytest tests/ -v
# Run all tests with coverage
pytest tests/ --cov=python_wrapper/langlint --cov-report=term-missing
Contributing
# 1. Clone the repository
git clone https://github.com/HzaCode/Langlint.git
cd Langlint
# 2. Install dependencies
cargo build
# 3. Make your changes in crates/
# 4. Run tests
cargo test
cargo clippy # Linting
cargo fmt # Formatting
# 5. Build Python package
maturin develop --release
# 6. Test Python integration
python -c "import langlint_py; print(langlint_py.version())"
🤝 Contributing
Contributions welcome! The codebase is now 100% Rust for maximum performance.
How to contribute:
- Core features: Add to
crates/langlint_* - New parsers: Extend
crates/langlint_parsers/src/ - New translators: Add to
crates/langlint_translators/src/ - Python API: Update
crates/langlint_py/src/lib.rs
See CONTRIBUTING.md for detailed guidelines.
📄 License
This project is licensed under the MIT License. See the LICENSE file for details.
📞 Contact & Links
- Homepage: https://github.com/HzaCode/Langlint
- PyPI: https://pypi.org/project/langlint/
- Issues: https://github.com/HzaCode/Langlint/issues
- Discussions: https://github.com/HzaCode/Langlint/discussions
Made with ❤️ and 🦀 (Rust)
10-50x faster than pure Python ⚡
⭐ Star us on GitHub | 📦 Install from PyPI | 🦀 View Rust Code
⭐ LLM too slow? Try LangLint! Now powered by Rust for maximum speed 🚀
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 Distributions
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 langlint-1.0.0-cp311-cp311-win_amd64.whl.
File metadata
- Download URL: langlint-1.0.0-cp311-cp311-win_amd64.whl
- Upload date:
- Size: 5.3 MB
- Tags: CPython 3.11, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
59399da4d75b490f9e5a1e084956d4b6d6f7b61114ad4e1708fa79942ca301a8
|
|
| MD5 |
09e9a7e63e5e56a77a50aafc038aeae6
|
|
| BLAKE2b-256 |
a8609e9bd6a4771e3567fffb7203c59daf68d42c2cba31ba1fb7ef307ba2a709
|