Skip to main content

A pure-Python Hinglish ↔ Hindi (Devanagari) transliterator

Project description

hinlangpy

Hinglish ↔ Hindi Transliterator for Python

Convert between Roman Hindi (Hinglish) and Devanagari script effortlessly.

pip install hinlangpy

Python License


✨ Features

  • 🔤 Roman → Devanagari"Namaste Dosto""नमस्ते दोस्तो"
  • 🔡 Devanagari → Roman"नमस्ते दोस्तो""namaste dosto"
  • 📖 500+ word dictionary for accurate common word translation
  • Character-level transliteration for unknown/new words
  • 🔁 Round-trip accurate — convert back and forth reliably
  • 🧩 Auto-detection — automatically detects input script
  • 📦 Zero dependencies — pure Python, no external packages
  • 🐍 Python 3.7+ compatible
  • 💻 CLI tool included — use directly from terminal

📦 Installation

pip install hinlangpy

Or install from source:

git clone https://github.com/ranjanlive/hinlang.git
cd hinlang
pip install -e .

🚀 Quick Start

Basic Usage

import hinlang

# Roman to Devanagari
hindi = hinlang.to_hindi("Namaste Dosto")
print(hindi)  # नमस्ते दोस्तो

# Devanagari to Roman
roman = hinlang.to_roman("नमस्ते दोस्तो")
print(roman)  # namaste dosto

# Auto-detect and convert
result = hinlang.convert("Kya haal hai")
print(result)  # क्या हाल है

result = hinlang.convert("क्या हाल है")
print(result)  # kya haal hai

Using Classes Directly

from hinlang import RomanToHindi, HindiToRoman

# Roman → Hindi
r2h = RomanToHindi()
print(r2h.transliterate("Mera naam Ranjan hai"))
# मेरा नाम रंजन है

# Hindi → Roman
h2r = HindiToRoman()
print(h2r.transliterate("मेरा नाम रंजन है"))
# mera naam ranjan hai

Batch Translation

import hinlang

sentences = [
    "Aap kaise ho",
    "Main theek hoon",
    "Bahut accha kaam kiya",
    "Shukriya dost",
]

# Convert all at once
results = hinlang.to_hindi_batch(sentences)
for original, converted in zip(sentences, results):
    print(f"{original}{converted}")

Output:

Aap kaise ho  →  आप कैसे हो
Main theek hoon  →  मैं ठीक हूँ
Bahut accha kaam kiya  →  बहुत अच्छा काम किया
Shukriya dost  →  शुक्रिया दोस्त

Script Detection

import hinlang

print(hinlang.detect_script("Hello Dosto"))     # "roman"
print(hinlang.detect_script("नमस्ते दोस्तो"))     # "devanagari"
print(hinlang.detect_script("Hello दोस्तो"))     # "mixed"

Custom Dictionary

from hinlang import RomanToHindi

converter = RomanToHindi()

# Add your own word mappings
converter.add_word("bruh", "ब्रह")
converter.add_word("vibe", "वाइब")
converter.add_words({
    "cringe": "क्रिंज",
    "lowkey": "लोकी",
    "sigma":  "सिग्मा",
})

print(converter.transliterate("Bruh kya vibe hai"))
# ब्रह क्या वाइब है

💻 CLI Usage

# Roman to Hindi
hinlangpy "Namaste Dosto"
# Output: नमस्ते दोस्तो

# Hindi to Roman
hinlangpy "नमस्ते दोस्तो"
# Output: namaste dosto

# Specify direction explicitly
hinlangpy --to-hindi "Kya haal hai"
hinlangpy --to-roman "क्या हाल है"

# Interactive mode
hinlangpy --interactive

# Translate a file
hinlangpy --file input.txt --output output.txt

# Pipe support
echo "Namaste Dosto" | hinlangpy

📚 API Reference

Module-Level Functions

Function Description
hinlang.to_hindi(text) Convert Roman text to Devanagari
hinlang.to_roman(text) Convert Devanagari text to Roman
hinlang.convert(text) Auto-detect script and convert to the other
hinlang.to_hindi_batch(list) Convert a list of Roman strings to Hindi
hinlang.to_roman_batch(list) Convert a list of Hindi strings to Roman
hinlang.detect_script(text) Detect script: "roman", "devanagari", or "mixed"

Note: Install with pip install hinlangpy, import as import hinlang.

Classes

RomanToHindi

from hinlang import RomanToHindi

converter = RomanToHindi()
result = converter.transliterate("Namaste Dosto")

# Custom words
converter.add_word("key", "value")
converter.add_words({"key1": "val1", "key2": "val2"})

HindiToRoman

from hinlang import HindiToRoman

converter = HindiToRoman()
result = converter.transliterate("नमस्ते दोस्तो")

# Custom words
converter.add_word("key", "value")
converter.add_words({"key1": "val1", "key2": "val2"})

🗺️ Transliteration Guide

Roman Devanagari Example
a amarअमर
aa aapआप
i isइस
ee eelईल
u uparउपर
oo oonchaऊंचा
e ekएक
ai aisaऐसा
o om
au aurऔर
k kalकल
kh khatखत
g gharघर
gh gheeघी
ch chaiचाय
chh chhotaछोटा
j jabजब
jh jhoothझूठ
t tabतब
th theekठीक
d dinदिन
dh dhanधन
n naamनाम
p paaniपानी
ph phirफिर
b basबस
bh bhaiभाई
m maaमाँ
y yahanयहाँ
r raatरात
l logलोग
v/w wohवो
sh shaamशाम
s sabसब
h haiहै
z ज़ zindagiज़िंदगी

🧪 Testing

# Run all tests
python -m pytest tests/

# Run with verbose
python -m pytest tests/ -v

# Quick test (package is 'hinlangpy' on PyPI, import as 'hinlang')
python -c "import hinlang; print(hinlang.to_hindi('Namaste Dosto'))"

📁 Project Structure

hinlang/
├── hinlang/
│   ├── __init__.py          # Public API & convenience functions
│   ├── roman_to_hindi.py    # Roman → Devanagari engine
│   ├── hindi_to_roman.py    # Devanagari → Roman engine
│   ├── detector.py          # Script detection utility
│   ├── dictionary.py        # Word dictionaries (500+ words)
│   └── cli.py               # Command-line interface
├── tests/
│   ├── __init__.py
│   ├── test_roman_to_hindi.py
│   ├── test_hindi_to_roman.py
│   ├── test_roundtrip.py
│   └── test_detector.py
├── examples/
│   ├── basic_usage.py
│   ├── batch_convert.py
│   └── custom_dictionary.py
├── docs/
│   └── TRANSLITERATION_GUIDE.md
├── setup.py
├── setup.cfg
├── pyproject.toml
├── MANIFEST.in
├── LICENSE
├── README.md
└── .gitignore

🤝 Contributing

Contributions are welcome! Here's how:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Add your changes and tests
  4. Commit: git commit -m 'Add amazing feature'
  5. Push: git push origin feature/amazing-feature
  6. Open a Pull Request

Adding New Words

The easiest way to contribute is by adding words to the dictionary:

# In hinlang/dictionary.py, add to ROMAN_TO_HINDI dict:
'yourword': 'देवनागरी',

📄 License

MIT License — see LICENSE for details.


🙏 Credits

  • Built with ❤️ for the Hindi-speaking developer community
  • Inspired by the need for a simple, offline, dependency-free Hindi transliterator

Made with ❤️ in India 🇮🇳

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

hinlangpy-1.0.0.tar.gz (22.5 kB view details)

Uploaded Source

Built Distribution

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

hinlangpy-1.0.0-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

File details

Details for the file hinlangpy-1.0.0.tar.gz.

File metadata

  • Download URL: hinlangpy-1.0.0.tar.gz
  • Upload date:
  • Size: 22.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for hinlangpy-1.0.0.tar.gz
Algorithm Hash digest
SHA256 29784c437f80e31876f3fbdb7b59b55f73914e40c7b8b4b4548813092b60dbda
MD5 c60efe25c3ae56af66903114486d9ca9
BLAKE2b-256 fd0cd3832d3a26216c6176f79abbe8b8dac032314103c8ae140c99078700384c

See more details on using hashes here.

Provenance

The following attestation bundles were made for hinlangpy-1.0.0.tar.gz:

Publisher: publish.yml on ranjanlive/hinlang

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hinlangpy-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: hinlangpy-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 19.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for hinlangpy-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f79b27cb0878e697655a68e7ae577a38d9dc1b4b50336b83804a04c632583b0a
MD5 2e4a421dbb76d500e037b2a3f24bc853
BLAKE2b-256 aad882241613b6dc8352c0e730e4a6aafe7ee54e2fe5bc28fa35f339060e27e2

See more details on using hashes here.

Provenance

The following attestation bundles were made for hinlangpy-1.0.0-py3-none-any.whl:

Publisher: publish.yml on ranjanlive/hinlang

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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