singlish-sinhala
v0.3.1
Published
High-performance Singlish → Sinhala transliteration engine compiled to WebAssembly. Full Sinhala script coverage, suggestion candidates, 100% client-side — no server, no tracking.
Maintainers
Readme
singlish-sinhala
High-performance Singlish → Sinhala transliteration engine compiled to WebAssembly.
- 🚀 Runs 100% client-side — near-native speed, zero network calls, no server, no tracking
- 🎯 ~100-word curated dictionary with exact spellings (
ayubowan→ආයුබෝවන්) - 💡 Suggestion candidates for ambiguous words (
t/d/n,th,sh…) - 🔁 Reverse transliteration: Sinhala → Singlish
- 🧩 IME-ready syllable chunks for per-chunk backspace handling
- 🦀 Built with Rust + wasm-bindgen; ships with TypeScript declarations
Install
npm install singlish-sinhalaQuick start — Browser (bundler / Vite / webpack)
import init, { transliterate } from 'singlish-sinhala';
await init(); // loads and instantiates the .wasm
transliterate('kohomada oya?'); // "කොහොමද ඔය?"Quick start — CDN (no build step)
<script type="module">
import init, { transliterate } from 'https://esm.sh/singlish-sinhala';
await init();
document.querySelector('#out').textContent = transliterate('ayubowan');
</script>Quick start — Node.js (18+)
import init, { transliterate } from 'singlish-sinhala';
import { readFile } from 'node:fs/promises';
const wasm = await readFile(
new URL('./node_modules/singlish-sinhala/singlish_core_bg.wasm', import.meta.url)
);
await init(wasm); // pass the .wasm bytes directlyAPI
| Function | Description | Example |
| --- | --- | --- |
| transliterate(text) | Full-string Singlish → Sinhala; preserves spaces & punctuation | "kohomada oya?" → "කොහොමද ඔය?" |
| transliterate_word(word) | Single word, dictionary-aware | "ayubowan" → "ආයුබෝවන්" |
| candidates(word) | Up to 5 suggestions for ambiguous words (primary first) | "kotha" → ["කොත","කොථ","කොට"] |
| reverse_transliterate(text) | Sinhala → Singlish (best-effort, follows forward convention) | "සිංහල" → "singhala" |
| split_chunks(word) | Sinhala syllable chunks; combining marks attach to their base (IME backspace) | "kohomada" → ["කො","හො","ම","ද"] |
| is_sinhala_text(text) | true when ≥50% of non-space chars are Sinhala | "කොහොමද" → true |
| sinhala_char_count(text) | Count of Sinhala-range characters | "කොහොමද hello" → 6 |
| transliterate_batch(words) | Bulk word conversion in one call | ["kohomada","bath"] → ["කොහොමද","බත්"] |
| version() | Engine version string | "0.3.0" |
Typing conventions
- Vowels — signs attach to the preceding consonant:
ka→ක,kaa→කා,kae→කැ,ke→කෙ,koo→කෝStandalone:a→අ,aa→ආ,ae→ඇ,i→ඉ,u→උ,e→එ,o→ඔ - Consonant digraphs —
ch→ච,kh→ඛ,gh→ඝ,th→ත,dh→ධ,sh→ශ,bh→භ,ph→ඵ,gn/ny→ඤ - Nasals —
ng→ං(sing→සිං),nk→ංක(lanka→ලංක) - Gemination —
kka→ක්ක,amma→අම්මා - Final consonant — gets virama:
k→ක් - Case-insensitive —
Sriandsribehave identically
Dictionary
Common words resolve to their exact Sinhala spellings instead of phonetic guesses:
ayubowan→ආයුබෝවන්, sri lanka→ශ්රී ලංකා, colombo→කොළඹ, kandy→මහනුවර,
amma→අම්මා, machang→මචං, thambili→තැඹිලි, singhala→සිංහල …
Demo
A full demo page (live typing, suggestions, direction toggle, copy) ships with the source repo. To run it:
cd singlish-core
wasm-pack build --target web
cd ..
python3 -m http.server 8000 # then open http://localhost:8000License
MIT
