Skip to content

Instantly share code, notes, and snippets.

@rahul1990gupta
Created August 9, 2020 05:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rahul1990gupta/6f84dd20b3b95c4a9318b16e3426727e to your computer and use it in GitHub Desktop.
Save rahul1990gupta/6f84dd20b3b95c4a9318b16e3426727e to your computer and use it in GitHub Desktop.
Transliteration from Hindi to english
from indic_transliteration import sanscript
from indic_transliteration.sanscript import SchemeMap, SCHEMES, transliterate
def to_hindi(text):
return transliterate(text, sanscript.HK, sanscript.DEVANAGARI)
def to_roman(text):
return transliterate(text, sanscript.DEVANAGARI, sanscript.HK)
hindi_sentence = "मैं खाना खा रहा हूँ"
print(hindi_sentence)
sent2 = to_roman(hindi_sentence)
print(sent2)
sent3 = to_hindi(sent2)
print(sent3)
sent4 = to_roman(sent3)
print(sent4)
assert hindi_sentence == sent3
assert sent2 == sent4
@rahul1990gupta
Copy link
Author

output of the program

मैं खाना खा रहा हूँ
maiM khAnA khA rahA hU~
मैं खाना खा रहा हूँ
maiM khAnA khA rahA hU~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment