Skip to content

Go

Lipi Lekhika provides a fast Go transliteration package with a realtime typing module. Requires Go 1.23+.

Terminal window
go get github.com/shubhattin/lipilekhika/packages/go/lipilekhika

Use Transliterate to convert text between scripts.

package main
import (
"fmt"
"github.com/shubhattin/lipilekhika/packages/go/lipilekhika"
)
func main() {
out, err := lipilekhika.Transliterate(
"na jAyatE mriyatE vA",
"Normal",
"Devanagari",
nil,
)
if err != nil {
panic(err)
}
fmt.Println(out) // न जायते म्रियते वा
}

Transliterate signature:

func Transliterate(
text string,
fromScript string,
toScript string,
transOptions map[string]bool,
) (string, error)
  • text — text to transliterate
  • fromScript — source script/language name
  • toScript — target script/language name
  • transOptions — optional custom option map (nil to skip)
package main
import (
"fmt"
"github.com/shubhattin/lipilekhika/packages/go/lipilekhika"
)
func main() {
out, err := lipilekhika.Transliterate(
"गङ्गा",
"Devanagari",
"Gujarati",
map[string]bool{
"brahmic_to_brahmic:replace_pancham_varga_varna_with_anusvAra": true,
},
)
if err != nil {
panic(err)
}
fmt.Println(out) // ગંગા
}

Use the typing package for character-by-character input.

package main
import (
"fmt"
"github.com/shubhattin/lipilekhika/packages/go/lipilekhika/typing"
)
func main() {
ctx, err := typing.NewTypingContext("Devanagari", nil)
if err != nil {
panic(err)
}
diff, err := ctx.TakeKeyInput("k")
if err != nil {
panic(err)
}
fmt.Printf("delete=%d add=%q\n", diff.ToDeleteCharsCount, diff.DiffAddText)
}

In an editor-like workflow, apply each returned diff as:

  • delete ToDeleteCharsCount runes from the current buffer tail
  • append DiffAddText
package main
import "github.com/shubhattin/lipilekhika/packages/go/lipilekhika/typing"
func main() {
useNative := false
includeInherent := true
clearMs := 3000
ctx, _ := typing.NewTypingContext("Devanagari", &typing.TypingContextOptions{
AutoContextClearTimeMs: &clearMs,
UseNativeNumerals: &useNative,
IncludeInherentVowel: &includeInherent,
})
_ = ctx
}

Key types:

  • typing.TypingContext
  • typing.TypingContextOptions
  • typing.TypingDiff

Runtime updates on context:

  • UpdateUseNativeNumerals(bool)
  • UpdateIncludeInherentVowel(bool)
  • ClearContext()