from polyglot.transliteration import Transliterator import unicodedata
hindi_text = u"परिवर्तन" print("Original Hindi word:", hindi_text) print("Composed by:") for c in hindi_text: print(c, c.encode("unicode_escape"), unicodedata.name(c))
trans = Transliterator(source_lang="hi", target_lang="la") latin_text = trans.transliterate(hindi_text) print("Hindi trans to Latin:") print(hindi_text, " -> ", latin_text)
trans = Transliterator(source_lang="la", target_lang="hi") hindi_text = trans.transliterate(latin_text)
print("\nLatin trans to Hindi:") print(latin_text, " -> ", hindi_text) print("Composed by:") for c in hindi_text: print(c, c.encode("unicode_escape"), unicodedata.name(c))
Original Hindi word: परिवर्तन Composed by: प b'\\u092a' DEVANAGARI LETTER PA र b'\\u0930' DEVANAGARI LETTER RA ि b'\\u093f' DEVANAGARI VOWEL SIGN I व b'\\u0935' DEVANAGARI LETTER VA र b'\\u0930' DEVANAGARI LETTER RA ् b'\\u094d' DEVANAGARI SIGN VIRAMA त b'\\u0924' DEVANAGARI LETTER TA न b'\\u0928' DEVANAGARI LETTER NA Hindi trans to Latin: परिवर्तन -> privrtn
Latin trans to Hindi: privrtn -> परिवर्टन Composed by: प b'\\u092a' DEVANAGARI LETTER PA र b'\\u0930' DEVANAGARI LETTER RA ि b'\\u093f' DEVANAGARI VOWEL SIGN I व b'\\u0935' DEVANAGARI LETTER VA र b'\\u0930' DEVANAGARI LETTER RA ् b'\\u094d' DEVANAGARI SIGN VIRAMA ट b'\\u091f' DEVANAGARI LETTER TTA न b'\\u0928' DEVANAGARI LETTER NA