BhaSha Class
For advanced use cases or non-React applications, you can use the `BhaSha` class directly. This gives you complete control over the transliteration engine.
Basic Usage
Instantiate the class and use its methods to perform transliteration.
import { BhaSha } from '@bhashaime/core';
const bhasha = new BhaSha();
// Set the language
bhasha.setLanguage('hindi');
// Transliterate a full sentence
const hindiText = bhasha.transliterateText('namaste, aap kaise hai?');
console.log(hindiText); // नमस्ते, आप कैसे है?
// Get a list of supported languages
const supportedLangs = bhasha.getSupportedLanguages();
console.log(supportedLangs); // ['english', 'gujarati', 'hindi']
Advanced Usage
For more granular control, you can process input character by character. This is useful for building custom interactive input experiences.
import { BhaSha } from '@bhashaime/core';
const bhasha = new BhaSha();
bhasha.setLanguage('gujarati');
let fullOutput = '';
const englishInput = 'kem chho';
for (const char of englishInput) {
const result = bhasha.processInput(char);
if (result.valid) {
fullOutput = result.output; // processInput returns the full transliterated string so far
}
}
console.log(fullOutput); // કેમ છ્છો
API Reference
setLanguage(lang: SupportedLanguage): void
Sets the active language for transliteration.
transliterateText(text: string): string
Transliterates a complete string of text.
processInput(char: string): { valid: boolean; output: string }
Processes a single character and returns the updated output.
getSupportedLanguages(): SupportedLanguage[]
Returns an array of all supported language codes.