Usage Guide
Type Roman letters (English) to get Nepali Unicode text. The converter works in real-time as you type.
Examples:
- namaste → नमस्ते
- nepal → नेपाल
- mero naam ram ho → मेरो नाम राम हो
- kathmandu → काठमाडौं
- swatantrata → स्वतन्त्रता
- sa*bidhan → संबिधान
- pratishat/ko → प्रतिशतको
- bas\ → बस्
- yo {mobile} ho → यो mobile हो
Special Character Keys:
- * - अनुस्वर (sa*sar = संसार)
- ** - चन्द्रबिन्दु (ka**ch = काँच)
- \ - हलन्त (bas\ = बस्)
- / - अलग गर्ने (pratishat/ko = प्रतिशतको)
- {text} - अंग्रेजीमा राख्ने (yo {text} ho = यो text हो)
- rr - half र (ghar+yo = घर्यो)
- ^ or ~ - र in front of consonant (^ka = र्क)
- om - ॐ symbol
Case-Sensitive Characters:
- T, Th, D, Dh, N, Sh - ट, ठ, ड, ढ, ण, ष (uppercase)
- t, th, d, dh, n, sh - त, थ, द, ध, न, श (lowercase)
Special Conjuncts (Combined Consonants):
- ksh - क्ष (as in क्षमा)
- gya - ज्ञ (as in ज्ञान)
- tra - त्र (as in त्रिभुवन)
- swa - स्व (as in स्वतन्त्र)
- dwa - द्व (as in द्वार)
Tips for Accurate Conversion:
- Use slash (/) to separate characters if incorrectly combined (sa/mjh/naa = सम्झना)
- For ending a word with halant, use backslash (\) at the end (bus\ = बस्)
- Remember to use uppercase for cerebral sounds (Ta = ट) and lowercase for dental sounds (ta = त)
- To keep English text, enclose it in curly braces {like this}
// Fix "reph" form (र + ्) at the beginning of a conjunct
text = text.replace(/([क-ह])र्/g, 'र्$1');
// Handle anusvara (ं) positioning
text = text.replace(/([ािीुूृेैोौ])ं/g, '$1ँ');
// Handle chandrabindu (ँ) properly
text = text.replace(/([क-ह])ँ/g, '$1ँ');
// Fix common incorrect forms
text = text.replace(/क्स/g, 'क्ष');
text = text.replace(/त्र्/g, 'त्र');
text = text.replace(/ज्ञ्/g, 'ज्ञ');
// Fix half letters with a vowel sign
text = text.replace(/([क-ह])्([ािीुूृेैोौ])/g, '$1$2');
// Handle visarga (:) character
text = text.replace(/:([क-ह])/g, 'ः$1');
// Apply typical Nepali diacritic rules
text = text.replace(/([क-ह])([ि])/g, '$2$1'); // i-kar (ि) goes before consonant
text = text.replace(/([क-ह])([ीुूृेैोौ])/g, '$1$2'); // other vowel signs go after
// Handle "au" and "ai" diphthongs
text = text.replace(/([क-ह])ाै/g, '$1ौ');
text = text.replace(/([क-ह])ाे/g, '$1ो');
text = text.replace(/([क-ह])ाै/g, '$1ौ');
text = text.replace(/([क-ह])ाई/g, '$1ै');
// Fix common word endings
text = text.replace(/को/g, 'को');
text = text.replace(/मा/g, 'मा');
text = text.replace(/ले/g, 'ले');
text = text.replace(/बाट/g, 'बाट');
return text;
};
// Utility function to escape special characters in regex
const escapeRegex = (string) => {
return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
};
// Process replacement in proper order with longest matches first
const processReplacements = (text, dictionary) => {
// Sort keys by length (longest first) to avoid partial replacements
const sortedKeys = Object.keys(dictionary).sort((a, b) => b.length - a.length);
for (const key of sortedKeys) {
const escapedKey = escapeRegex(key);
const regex = new RegExp(escapedKey, 'g');
text = text.replace(regex, dictionary[key]);
}
return text;
};
// First check for common words (direct conversions)
let convertedText = processReplacements(plainText, commonWords);
// Then apply custom rules for consonant+vowel combinations
convertedText = processReplacements(convertedText, customRules);
// Then apply conjuncts
convertedText = processReplacements(convertedText, conjuncts);
// Then apply half letters
convertedText = processReplacements(convertedText, halfLetters);
// Then apply consonants
convertedText = processReplacements(convertedText, consonants);
// Then apply vowels
convertedText = processReplacements(convertedText, vowels);
// Then apply numbers
convertedText = processReplacements(convertedText, numbers);
// Finally apply special characters
convertedText = processReplacements(convertedText, special);
// Handle specific Nepali grammar rules
convertedText = refineGrammar(convertedText);
// Specific fixes for consonant-vowel combinations
convertedText = convertedText.replace(/([क-ह])्अ/g, '$1'); // Remove halant+अ combination
convertedText = convertedText.replace(/([क-ह])्आ/g, '$1ा'); // Fix halant+आ → vowel sign ा
convertedText = convertedText.replace(/([क-ह])्इ/g, '$1ि'); // Fix halant+इ → vowel sign ि
convertedText = convertedText.replace(/([क-ह])्ई/g, '$1ी'); // Fix halant+ई → vowel sign ी
convertedText = convertedText.replace(/([क-ह])्उ/g, '$1ु'); // Fix halant+उ → vowel sign ु
convertedText = convertedText.replace(/([क-ह])्ऊ/g, '$1ू'); // Fix halant+ऊ → vowel sign ू
convertedText = convertedText.replace(/([क-ह])्ए/g, '$1े'); // Fix halant+ए → vowel sign े
convertedText = convertedText.replace(/([क-ह])्ऐ/g, '$1ै'); // Fix halant+ऐ → vowel sign ै
convertedText = convertedText.replace(/([क-ह])्ओ/g, '$1ो'); // Fix halant+ओ → vowel sign ो
convertedText = convertedText.replace(/([क-ह])्औ/g, '$1ौ'); // Fix halant+औ → vowel sign ौ
// Apply final spacing and word spacing fixes
// Fix spaces between Nepali words
convertedText = convertedText.replace(/([क-ह])(\s+)([क-ह])/g, '$1 $3');
// Fix post-conversion spacing around punctuation
convertedText = convertedText.replace(/(\s+)(।)/g, '$2');
convertedText = convertedText.replace(/(।)(\s+)/g, '$1 ');
// Process each word to ensure internal consistency
const words = convertedText.split(/\s+/);
convertedText = words.map(word => {
// Fix incorrect half letters at the end of words
if (/[क-ह]्$/.test(word)) {
return word.replace(/([क-ह])्$/, '$1');
}
return word;
}).join(' ');
// Replace placeholders for English text
convertedText = convertedText.replace(/§§(\d+)§§/g, (match, p1) => engParts[parseInt(p1)]);
// Log final output for debugging
console.log('Final Converted Text:', convertedText);
return convertedText;
}
});