lipilekhika 1.0.8

A transliteration library for Indian Brahmic scripts
Documentation
# Lipi Lekhika โ€” Rust

> A high-performance transliteration library for Indian Brahmic scripts

[![crates.io](https://img.shields.io/crates/v/lipilekhika.svg)](https://crates.io/crates/lipilekhika)
[![crates.io](https://img.shields.io/crates/d/lipilekhika.svg)](https://crates.io/crates/lipilekhika)
[![Tests](https://github.com/shubhattin/lipilekhika/actions/workflows/rust_ci.yml/badge.svg)](https://github.com/shubhattin/lipilekhika/actions/workflows/rust_ci.yml)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)

๐ŸŒ **[Website](https://lipilekhika.in)** โ€ข ๐Ÿ“– **[Documentation](https://lipilekhika.in/getting-started/rust)** โ€ข ๐Ÿฆ€ **[Crates.io](https://crates.io/crates/lipilekhika)** โ€ข ๐Ÿ“ **[Changelog](./CHANGELOG.md)**

---

## โœจ Features

- ๐Ÿ”„ **Bidirectional Transliteration** โ€” Convert between 15+ Indian Brahmic scripts
- โšก **High Performance** โ€” Zero-overhead abstractions and optimized algorithms
- ๐Ÿ›ก๏ธ **Type Safe** โ€” Leverages Rust's type system for safety and correctness
- ๐ŸŽฏ **Customizable Options** โ€” Fine-tune transliteration and typing behaviour
- โŒจ๏ธ **Typing Mode** โ€” Stateful context for real-time character-by-character input
- ๐Ÿ“ฆ **Embedded Script Data** โ€” All script data bundled at compile time

## ๐Ÿ“ฅ Installation

```bash
cargo add lipilekhika
```

## ๐Ÿš€ Quick Start

### Basic Transliteration

```rust
use lipilekhika::transliterate;

fn main() {
    let result = transliterate(
        "namaskAraH",
        "Normal",
        "Devanagari",
        None
    ).unwrap();
    
    println!("{}", result); // เคจเคฎเคธเฅเค•เคพเคฐเคƒ
}
```

### With Custom Options

```rust
use lipilekhika::transliterate;
use std::collections::HashMap;

fn main() {
    let mut options = HashMap::new();
    options.insert(
        "brahmic_to_brahmic:replace_pancham_varga_varna_with_anusvAra".to_string(),
        true
    );
    
    let result = transliterate(
        "เฐ—เฐ‚เฐ—เฐพ",
        "Telugu",
        "Gujarati",
        Some(&options)
    ).unwrap();
    
    println!("{}", result); // เช—เช‚เช—เชพ (instead of เช—เช™เซเช—เชพ)
}
```

## ๐Ÿ“š API

### Core Functions

#### `transliterate`

```rust
pub fn transliterate(
    text: &str,
    from: &str,
    to: &str,
    trans_options: Option<&HashMap<String, bool>>,
) -> Result<String, String>
```

Transliterates text from one script to another.

**Parameters:**
- `text` โ€” Text to transliterate
- `from` โ€” Source script/language name (e.g., "Normal", "Devanagari", "Telugu")
- `to` โ€” Target script/language name
- `trans_options` โ€” Optional custom transliteration options

**Returns:** `Result<String, String>` โ€” Transliterated text or error message

#### `get_all_option`

```rust
pub fn get_all_option(
    from_script_name: &str,
    to_script_name: &str,
) -> Result<Vec<String>, String>
```

Gets all available custom options for a script pair.

**Parameters:**
- `from_script_name` โ€” Source script/language name
- `to_script_name` โ€” Target script/language name

**Returns:** `Result<Vec<String>, String>` โ€” List of option keys or error message

#### `get_script_typing_data_map`

```rust
pub fn get_script_typing_data_map(
    script: &str,
) -> Result<ScriptTypingDataMap, String>
```

Gets typing data mappings for a script (for building custom input methods).

**Parameters:**
- `script` โ€” Script/language name

**Returns:** `Result<ScriptTypingDataMap, String>` โ€” Typing data or error message

### Typing Module

For character-by-character real-time input:

```rust
use lipilekhika::typing::{TypingContext, TypingContextOptions};

fn main() {
    let mut ctx = TypingContext::new("Devanagari", None).unwrap();
    
    // Process character-by-character input
    let diff = ctx.take_key_input("n").unwrap();
    println!("Delete: {}, Add: '{}'", diff.to_delete_chars_count, diff.diff_add_text);
    
    let diff = ctx.take_key_input("a").unwrap();
    println!("Delete: {}, Add: '{}'", diff.to_delete_chars_count, diff.diff_add_text);
    
    // Clear context when needed
    ctx.clear_context();
}
```

#### Types

- **`TypingContext`** โ€” Stateful context for typing mode
  - `new(typing_lang: &str, options: Option<TypingContextOptions>)` โ€” Create new context
  - `take_key_input(&mut self, key: &str)` โ€” Process single character input
  - `clear_context(&mut self)` โ€” Clear internal state

- **`TypingContextOptions`** โ€” Configuration for typing behavior
  - `auto_context_clear_time_ms: u64` โ€” Auto-clear timeout (default: 4500ms)
  - `use_native_numerals: bool` โ€” Use script-native numerals (default: true)
  - `include_inherent_vowel: bool` โ€” Include inherent vowel/schwa (default: false)

- **`TypingDiff`** โ€” Result of processing a key input
  - `to_delete_chars_count: usize` โ€” Characters to delete from current state
  - `diff_add_text: String` โ€” Text to insert

- **`ScriptTypingDataMap`** โ€” Typing data for a script (from `get_script_typing_data_map`)
  - `common_krama_map: Vec<TypingDataMapItem>` โ€” Common character mappings
  - `script_specific_krama_map: Vec<TypingDataMapItem>` โ€” Script-specific mappings

- **`ListType`** โ€” Character type enum: `Anya`, `Vyanjana`, `Matra`, `Svara`

- **`TypingDataMapItem`** โ€” Type alias for `(String, ListType, Vec<String>)`

## ๐ŸŽฏ Supported Scripts

Devanagari, Bengali, Tamil, Telugu, Kannada, Malayalam, Gujarati, Odia, Gurmukhi, Sinhala, Tamil-Extended, Myanmar, Tibetan, Limbu, and more.

๐Ÿ“– Full list: [lipilekhika.in/reference/supported_scripts](https://lipilekhika.in/reference/supported_scripts)

## ๐Ÿ”ง Custom Options

See the full list of custom transliteration options:

๐Ÿ“– [lipilekhika.in/reference/custom_trans_options](https://lipilekhika.in/reference/custom_trans_options)

## ๐Ÿ“– Resources

- **[Website]https://lipilekhika.in** โ€” Documentation and guides
- **[Supported Scripts]https://lipilekhika.in/reference/supported_scripts** โ€” Full list of scripts
- **[Custom Options]https://lipilekhika.in/reference/custom_trans_options** โ€” Transliteration options reference
- **[GitHub Repository]https://github.com/shubhattin/lipilekhika** โ€” Source code and issues

## ๐Ÿ“ License

MIT License โ€” See [LICENSE](./LICENCE) for details