Embed a Transliteration Widget on Your Website
How to add Indian language typing capability to any website using the TranslitHub embeddable widget — embed code, customization options, and use cases for blogs, forums, and portals.
Running a Hindi blog and want your readers to leave comments in Hindi? Building a community forum where members can post in their regional language? Operating a local government portal that needs to accept applications in Marathi? The TranslitHub widget is a drop-in solution that adds Indian language typing to any text input on your website — no backend changes, no complex integration, just a script tag and a few configuration options.
This guide walks through the embed process, customization options, and real-world scenarios where the widget makes the most sense.
What the Widget Does
When you embed the TranslitHub widget on a page, it attaches to text input fields you specify. When a visitor types in those fields, the widget intercepts the Roman keystrokes and converts them to the Indian script in real time — the same phonetic transliteration that powers TranslitHub itself.
From the visitor's perspective: they type "mera naam Priya hai" and the field displays "मेरा नाम प्रिया है". No installation required on their end. No special keyboard. Works on desktop and mobile.
The widget can target:
- Individual
fields elements- Contenteditable elements (rich text editors like WordPress's visual editor or custom CMS fields)
- Multiple fields on the same page
Basic Embed
Add the widget script to your page's
and initialize it with your site key:<script src="https://cdn.transliterate.in/widget/v2/translithub-widget.min.js" data-site-key="YOUR_SITE_KEY" async ></script>Get your site key from the TranslitHub dashboard under Integrations → Widget.
Then initialize it in JavaScript:
document.addEventListener('DOMContentLoaded', function() { TranslitHub.init({ targets: ['#comment-field', '#search-input'], defaultLang: 'hi', showSelector: true }); });That's the minimum setup. The
targetsarray accepts CSS selectors, anddefaultLangsets the initial language. SetshowSelector: trueto show a language dropdown next to each target field.Configuration Options
TranslitHub.init({ // Required targets: ['#my-input'], // CSS selectors for input fields// Language
defaultLang: 'hi', // Default target language
availableLangs: ['hi', 'bn', 'ta', 'te', 'mr'], // Languages to show in selector
showSelector: true, // Show language dropdown near the input// UI
selectorPosition: 'top-right', // 'top-right', 'top-left', 'bottom-right', 'bottom-left'
theme: 'light', // 'light', 'dark', 'auto'
primaryColor: '#ff9933', // Accent color for the selector UI
fontFamily: 'inherit', // Font for the input text (inherits page font by default)// Behavior
autoCapitalize: false, // Whether to capitalize first letter (usually keep false for Indian scripts)
preserveNumbers: true, // Don't convert Arabic numerals
preserveEnglish: false, // Convert or skip recognized English words
suggestionDropdown: true, // Show word suggestions on ambiguous input
maxSuggestions: 3, // Number of suggestions to show// Callbacks
onConvert: function(original, converted, lang) {
console.log('Converted:', original, '->', converted, 'in', lang);
},
onLangChange: function(newLang) {
console.log('Language changed to:', newLang);
}
});Customizing the Widget Appearance
The language selector and suggestion dropdown are styled by default to be minimal and unobtrusive. You can override them with CSS:
/ Customize the language selector / .translithub-lang-selector { font-family: 'Noto Sans', sans-serif; background: #fff; border: 1px solid #ddd; border-radius: 4px; font-size: 13px; }/ Customize the suggestion dropdown /
.translithub-suggestions {
background: #fff;
border: 1px solid #e0e0e0;
border-radius: 6px;
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}.translithub-suggestion-item:hover {
background: #ff993322;
}The widget adds a
translithub-activeclass to any input field it's currently processing, which you can use to show a visual indicator:input.translithub-active { border-color: #ff9933; outline: none; box-shadow: 0 0 0 2px rgba(255,153,51,0.2); }WordPress Integration
WordPress is the most common CMS for Indian language blogs. The widget integrates cleanly with both the Classic Editor and Block Editor (Gutenberg).
For the comment form:Add to your theme's
functions.php:
For custom post type meta boxes (Hindi content fields):function add_translithub_widget() { ?> <script src="https://cdn.transliterate.in/widget/v2/translithub-widget.min.js" data-site-key="<?php echo esc_attr(get_option('translithub_site_key')); ?>" async ></script> <script> document.addEventListener('DOMContentLoaded', function() { if (typeof TranslitHub !== 'undefined') { TranslitHub.init({ targets: ['#comment', '#author'], defaultLang: '<?php echo esc_js(get_option('translithub_default_lang', 'hi')); ?>', showSelector: true }); } }); </script> <?php } add_action('wp_footer', 'add_translithub_widget');// In your admin meta box JavaScript TranslitHub.init({ targets: ['#hindi_title', '#hindi_excerpt', '#hindi_content'], defaultLang: 'hi', showSelector: false // You've already fixed the language });Forum Software Integration
phpBB: Add to your phpBB template'soverall_header.html. Target#message(the main post textarea) and#subject(the thread title input). Discourse: Discourse has a plugin system. Use thecomponent in a theme component to inject the widget script. Target.d-editor-input(the main compose textarea). Simple Machines Forum (SMF): Add to your theme'sheader.template.php. Target#messageand optionally the quick reply field#quickReplytext.Government Portal Use Case
This is worth covering separately because government portal requirements are specific. Forms on government sites typically need to accept text in both English and a regional language — sometimes in the same field, sometimes in separate fields.
A common pattern:
<!-- Name in English --> <div class="form-group"> <label>Name (English)</label> <input type="text" id="name-en" placeholder="Enter your name"> </div><!-- Name in Hindi -->
<div class="form-group">
<label>नाम (हिंदी में)</label>
<input type="text" id="name-hi" placeholder="हिंदी में नाम लिखें">
</div>TranslitHub.init({ targets: ['#name-hi', '#address-hi', '#city-hi'], defaultLang: 'hi', showSelector: false, // Language is fixed for these fields preserveNumbers: true // House numbers, PIN codes stay as Arabic numerals });The
preserveNumbers: trueoption is particularly important for government forms — you don't want phone numbers or ID numbers converting to Devanagari numerals.Handling Multiple Languages on the Same Page
If your site serves multiple regional communities, you might need different default languages for different sections of the page:
// Hindi form section TranslitHub.init({ targets: ['[data-lang="hi"]'], defaultLang: 'hi', showSelector: false });// Tamil section
TranslitHub.init({
targets: ['[data-lang="ta"]'],
defaultLang: 'ta',
showSelector: false
});// Generic section where user picks language
TranslitHub.init({
targets: ['[data-lang="auto"]'],
defaultLang: 'hi',
availableLangs: ['hi', 'ta', 'te', 'bn', 'mr'],
showSelector: true
});Multiple
TranslitHub.init()calls work independently — each one handles its own target set.Mobile Behavior
On mobile devices, the widget behaves slightly differently because phone keyboards have their own input handling:
- On iOS Safari and Chrome for Android, the widget works within the limitations of mobile browser text input. Phonetic conversion still happens, but the native keyboard suggestions may interfere.
- The language selector adapts to a mobile-friendly dropdown that doesn't obscure the input field.
- For touch devices, the suggestion dropdown items are larger for easier tapping.
suggestionDropdown: falseon mobile (detect via user agent) to avoid UI conflicts with the native keyboard:const isMobile = /Mobi|Android/i.test(navigator.userAgent);TranslitHub.init({
targets: ['#user-input'],
defaultLang: 'hi',
suggestionDropdown: !isMobile
});Performance Notes
The widget script is ~28KB minified and gzipped, loaded from TranslitHub's CDN. It defers after the page's main content loads (the
asyncattribute on the script tag ensures this).For pages with many transliterable inputs, the widget batches conversions and debounces input — it doesn't fire a conversion request on every single keystroke. The default debounce is 150ms, which is fast enough to feel real-time while avoiding unnecessary processing.
If you're on a strict Content Security Policy (CSP), add the CDN domain to your
script-src:Content-Security-Policy: script-src 'self' cdn.transliterate.in;Disabling the Widget for Specific Inputs
Add the
data-no-translitattribute to any input you don't want the widget to affect:<input type="text" id="email" data-no-translit placeholder="Email address"> <input type="text" id="phone" data-no-translit placeholder="Phone number"> <input type="text" id="username" data-no-translit placeholder="Username">This is important for fields where you explicitly don't want conversion — email addresses, URLs, numeric fields, passwords.
Detecting Transliteration in Your Backend
When a form is submitted, the converted Indian language text is just regular Unicode. Your backend doesn't need to do anything special — it receives UTF-8 encoded text just like any other text field. Store it in your database, send it in emails, display it back in the UI — it all works without special handling.
The only thing to verify is that your database column and connection are set to UTF-8 or UTF-8MB4 character encoding, which is the default for any modern database setup.
Related Tools
- TranslitHub API — programmatic transliteration for server-side integration
- Browser Extension — type in Indian languages on any site you visit
- Transliteration Editor — standalone editor for document creation
Ad 728x90