Skip to main content

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.

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.
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)

export async function fetchSuggestions(word: string): Promise<string[]>
Fetches up to five Devanagari transliteration suggestions for a single Hinglish word from the Google Input Tools API. Endpoint:
https://inputtools.google.com/request
  ?text={word}
  &itc=hi-t-i0-und
  &num=5
  &cp=0
  &cs=1
  &ie=utf-8
  &oe=utf-8
Response shape:
[
  "SUCCESS",
  [
    [
      "namaste",
      ["नमस्ते", "नमस्त", "नमस्थे", "नमस्टे", "नमस्"],
      [],
      {}
    ]
  ]
]
The function extracts 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:
  • word is empty or whitespace.
  • shouldSkipTransliteration(word) returns true.
  • The cached result is already available (returns the cache hit instead).
  • The fetch fails or the API returns a non-SUCCESS status.
word
string
required
A single Hinglish word (no spaces). The function trims the value before use.

shouldSkipTransliteration(word)

export function shouldSkipTransliteration(word: string): boolean
Returns true when the word should be left as-is without sending a transliteration request. Skip conditions:
ConditionRegexExample
Empty or whitespace"", " "
Pure number (digits, ,, ., -, /)/^[\d.,\-\/]+$/"302", "4/2024"
Contains any uppercase Latin letter/[A-Z]/"IPC", "FIR", "Section"
The uppercase-letter rule preserves legal acronyms like IPC, FIR, BNS, and Section 302 that officers routinely type in diary entries. These terms are Shift-typed and must remain in ASCII.
word
string
required
The current word at the cursor position. Trimmed internally before evaluation.

Private Helper: toAsciiDigits(s)

function toAsciiDigits(s: string): string
Replaces Devanagari digit characters (Unicode U+0966U+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.
On each input event (trusted only — programmatic updates are ignored), the function:
  1. Reads the current word at the cursor via getWordBoundaries(value, cursor).
  2. Waits 50 ms (debounce) then calls fetchSuggestions(currentWord).
  3. If suggestions are returned, calls showSuggestions(suggestions, wordStart, wordEnd, el) to render the floating popup.
typingTimer = setTimeout(async () => {
  if (!isTransliterationEnabled()) return;
  const suggestions = await fetchSuggestions(currentWord);
  if (suggestions && suggestions.length > 0) {
    showSuggestions(suggestions, start, end, el);
  } else {
    suggestionsBox.style.display = 'none';
  }
}, doneTypingInterval); // 50 ms

Toggle Gate

isTransliterationEnabled() is evaluated before every suggestion fetch and before the Space intercept:
function isTransliterationEnabled() {
  return !isHindiMode && !mobileInputMq.matches;
}
When the toggle is OFF (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).
If the popup would overflow the right edge or the bottom of the viewport, it is repositioned to stay fully visible. It is also kept below the --chrome-top height to avoid overlapping the fixed header.
Clicking a suggestion item calls replaceEditableRange(targetEl, wordStart, wordEnd, suggestion), which uses the Quill API for Quill editors (preserving formatting around the replaced word) and direct value manipulation for plain <textarea> / <input> fields.

Build docs developers (and LLMs) love