Skip to main content

Python package for Indian language translation using AI4Bharat's IndicTrans2 API

Project description

anuvaad-rev

A Python package for Indian language translation using AI4Bharat's IndicTrans2 API service. This package provides an easy-to-use interface for translating text between English and various Indian languages, with automatic language detection.

Acknowledgment

This package uses the IndicTrans2 translation service provided by AI4Bharat. All translation capabilities are powered by AI4Bharat's API. Visit AI4Bharat's website for more information about their services.

Features

  • Support for 23 Indian languages
  • Automatic language detection
  • Language information utilities
  • User agent rotation to avoid rate limits
  • Automatic session refresh
  • Retry mechanism for failed requests
  • Error handling and input validation
  • Easy to integrate into existing projects

Installation

pip install anuvaad-rev

Quick Start

from anuvaad_rev import IndicTranslator

# Create translator instance
translator = IndicTranslator()

# Auto-detect language and translate
text = "नमस्ते, कैसे हैं आप?"
translation = translator.translate(text, target_lang="en")
print(translation)  # Output: Hello, how are you?

# Get language information
languages = translator.get_supported_languages()
print(languages)

Language Detection and Information

# Detect language
text = "வணக்கம், எப்படி இருக்கிறீர்கள்?"
detected = translator.detect_language(text)
print(detected)  # Output: ta

# Get language name
lang_name = translator.get_language_name("ta")
print(lang_name)  # Output: Tamil

# Get confidence scores
confidence = translator.detect_language_confidence(text)
for lang, score in confidence:
    print(f"{lang}: {score:.2%}")

# Get language code from name
code = translator.get_language_code("Hindi")
print(code)  # Output: hi

# List all supported languages
codes = translator.get_supported_language_codes()
names = translator.get_supported_language_names()

Advanced Translation

# Create translator with custom settings
translator = IndicTranslator(
    max_retries=3,              # Number of retries for failed requests
    session_refresh_interval=3600  # Refresh session every hour
)

# Batch translation with auto-detection
texts = [
    "Hello world!",
    "नमस्ते दुनिया!",
    "வணக்கம் உலகம்!"
]

for text in texts:
    # Source language will be auto-detected
    translation = translator.translate(text, target_lang="hi")
    print(f"Original: {text}")
    print(f"Hindi: {translation}\n")

Supported Languages

Language Code Language Code
Assamese as Malayalam ml
Bengali bn Manipuri mni
Bodo brx Marathi mr
Dogri doi Nepali ne
English en Odia or
Gujarati gu Punjabi pa
Hindi hi Sanskrit sa
Kannada kn Santali sat
Kashmiri ks Sindhi sd
Konkani kok Tamil ta
Maithili mai Telugu te
Urdu ur

API Reference

IndicTranslator

class IndicTranslator:
    def translate(self, text, target_lang, source_lang=None):
        """
        Translate text with optional auto-detection
        
        Args:
            text: Text to translate
            target_lang: Target language code
            source_lang: Source language code (if None, will be auto-detected)
            
        Returns:
            Translated text if successful, None otherwise
        """
    
    def detect_language(self, text):
        """
        Detect the language of input text
        
        Returns:
            Detected language code
        """
    
    def detect_language_confidence(self, text):
        """
        Detect language with confidence scores
        
        Returns:
            List of (language_code, confidence_score) tuples
        """
    
    def get_language_name(self, lang_code):
        """Get language name from code"""
    
    def get_language_code(self, language_name):
        """Get language code from name"""
    
    def get_supported_languages(self):
        """Get dictionary of supported languages"""
    
    def get_supported_language_codes(self):
        """Get list of supported language codes"""
    
    def get_supported_language_names(self):
        """Get list of supported language names"""

Examples

The package includes several example scripts demonstrating various features:

  • Basic translation usage
  • Batch translation with rate limit handling
  • Language detection and information features

License

This package is licensed under the MIT License - see the LICENSE file for details.

Disclaimer

This is an unofficial package that uses AI4Bharat's IndicTrans2 API service. Users must ensure their usage complies with AI4Bharat's terms of service and guidelines. This package is not affiliated with or endorsed by AI4Bharat.

Credits

Translation service provided by AI4Bharat.

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

anuvaad_rev-0.1.2.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

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

anuvaad_rev-0.1.2-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file anuvaad_rev-0.1.2.tar.gz.

File metadata

  • Download URL: anuvaad_rev-0.1.2.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.4

File hashes

Hashes for anuvaad_rev-0.1.2.tar.gz
Algorithm Hash digest
SHA256 385c7ea4133d3bf14c2374a33c3f4b9f6ea8747228462fa5e7e2eea0932b888d
MD5 225d0cdcd4a8c9045eafe25661a0d4c9
BLAKE2b-256 190e57657c913c92a4874f081d8dfbcda43cb1efa9cfa449e587eb018d709e6b

See more details on using hashes here.

File details

Details for the file anuvaad_rev-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: anuvaad_rev-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.4

File hashes

Hashes for anuvaad_rev-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 419e8f845d193fc513c4878191c815b359801ab3e9251bd6b4ecb48774d6297f
MD5 16f90435e84219eee8a1077687df472a
BLAKE2b-256 04c677d2da6f19f9095bae8b7467ecbf394b23ba9c50f6d8bbf7232b3f28caa7

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