ambuda-org / vidyut

Infrastructure for Sanskrit software. For Python bindings, see `vidyut-py`.
49 stars 21 forks source link

Add support for toggling / suspending transliteration #94

Open akprasad opened 9 months ago

akprasad commented 9 months ago

Problem

Sanscript supports a handy feature: if the user types ##, transliteration is disabled until the ## block is seen again. Or for another version of this, some transliterators support suspending transliteration when < is seen and enabling it again when > is seen.

vidyut-lipi does not support this behavior, so it does not have parity with Sanscript.js

Proposed solution

Don't modify our core transliteration logic (transliterate_from_alphabet, transliterate_from_abugida) directly. Instead, modify the transliterate function to create a string slice if a toggler/suspender is seen, perhaps like so:

if let Some(i) = chars.position(|c| c == '<') {
  let slice = input[..i];
  // then, transliterate `slice` and append it to the output.
}

Supporting this behavior will also require updating the transliterate API to support an Options argument that lets the user set various flags. Rather than update transliterate, I suggest creating a new transliterate_with_options function (or method, if updating Lipika as well).

akprasad commented 7 months ago

On reflection, this seems right for the application layer but wrong for the library layer. But, perhaps we need some basic support of ## for ITRANS.