The transliteration module converts Romanised Hindi (Hinglish) input into Devanagari suggestions in real time. When the Hindi Typing (A:अ) toggle is enabled and the user is on a desktop or tablet, every word typed in an editor field is sent to the Google Input Tools API and up to five Devanagari candidates are displayed in a floating suggestion box. The feature requires internet connectivity; typing without suggestions still works offline.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/arverma/Bihar-Police-Notebook/llms.txt
Use this file to discover all available pages before exploring further.
On screens ≤ 768 px the transliteration toggle is hidden and
isTransliterationEnabled() in main.js always returns false. Mobile users are expected to use their OS keyboard’s own transliteration or microphone.Exported Functions
fetchSuggestions(word)
data[1][0][1].slice(0, 5) — the first five suggestions for the input word. Devanagari numerals (०–९) in the response are normalised to ASCII digits via the private toAsciiDigits helper before the suggestions are cached and returned.
Caching: Results are stored in a plain module-level object keyed by the trimmed input word. The cache lives for the lifetime of the page and is never explicitly evicted — it is bounded in practice because each unique word is only a few bytes and the cache is reset on every navigation.
Returns: An empty array [] when:
wordis empty or whitespace.shouldSkipTransliteration(word)returnstrue.- The cached result is already available (returns the cache hit instead).
- The fetch fails or the API returns a non-
SUCCESSstatus.
A single Hinglish word (no spaces). The function trims the value before use.
shouldSkipTransliteration(word)
true when the word should be left as-is without sending a transliteration request.
Skip conditions:
| Condition | Regex | Example |
|---|---|---|
| Empty or whitespace | — | "", " " |
Pure number (digits, ,, ., -, /) | /^[\d.,\-\/]+$/ | "302", "4/2024" |
| Contains any uppercase Latin letter | /[A-Z]/ | "IPC", "FIR", "Section" |
IPC, FIR, BNS, and Section 302 that officers routinely type in diary entries. These terms are Shift-typed and must remain in ASCII.
The current word at the cursor position. Trimmed internally before evaluation.
Private Helper: toAsciiDigits(s)
U+0966–U+096F, i.e. ०–९) with their ASCII equivalents (0–9). Applied to every suggestion returned by the API before it enters the cache, so suggestion lists always use standard digits even when the API returns Devanagari numerals.
Integration in main.js
attachTransliteration(el) in main.js wires the suggestion flow onto each editable field. It is called for every <textarea>, <input>, and Quill .ql-editor element inside .editor-letter and .editor-diary.
- input event
- Space key — auto-accept
- click event
On each
input event (trusted only — programmatic updates are ignored), the function:- Reads the current word at the cursor via
getWordBoundaries(value, cursor). - Waits 50 ms (debounce) then calls
fetchSuggestions(currentWord). - If suggestions are returned, calls
showSuggestions(suggestions, wordStart, wordEnd, el)to render the floating popup.
Toggle Gate
isTransliterationEnabled() is evaluated before every suggestion fetch and before the Space intercept:
isHindiMode = true) or the viewport is mobile (≤ 768 px), no API calls are made and the suggestion box is hidden immediately.
Dictation Guard
When dictated text is being inserted programmatically,isDictatedInput is set to true for the duration of the insertion. The input event handler checks this flag and skips suggestion fetching, preventing the suggestion box from appearing over dictated text.
Suggestion Popup Positioning
showSuggestions positions the #suggestions box using position: fixed coordinates calculated from:
- The editable element’s
getBoundingClientRect(). - The line number and horizontal offset derived from the text before the current word.
- The current page scale factor from
pageScale.getScale()(so the popup tracks correctly when the A4 page is zoomed).
--chrome-top height to avoid overlapping the fixed header.