Skip to content

Instantly share code, notes, and snippets.

@piyush-json
Last active August 30, 2023 08:19
Show Gist options
  • Select an option

  • Save piyush-json/10cb14da9046aa8a44075f9c41fd560a to your computer and use it in GitHub Desktop.

Select an option

Save piyush-json/10cb14da9046aa8a44075f9c41fd560a to your computer and use it in GitHub Desktop.
englishToHindiTransliterate
def joinStr(str):
ans=""
for item in str:
ans+=item
return ans
def findCharec(text,size,dict):
output_result = {}
for i in range(0,len(text)):
if (len(text)-i>=size):
char3=text[i:i+size]
if char3 in dict:
text=text.replace(char3,"+"*size,1)
output_result[i]=dict[char3]
# print([output_result,text],"size",size)
return [output_result,text]
def transliterate(text, e2hdict):
output_result = {}
final_text = ""
for i in range(3,0,-1):
o,t=findCharec(text,i,e2hdict)
output_result.update(o)
text=t
output_list = list(output_result.keys())
output_list.sort()
output_result = {i: output_result[i] for i in output_list}
final_text=joinStr(output_result.values())
return final_text
english_to_hindi_dict= {
'chh': 'छ',
'shh': 'ष',
'ksh': 'क्ष',
'aa': 'आ',
'ai': 'ऐ',
'au': 'औ',
'ii': 'ई',
'uu': 'ऊ',
'am': 'अं',
'kh': 'ख',
'gh': 'घ',
'ng': 'ङ',
'ch': 'च',
'jh': 'झ',
'ny': 'ञ',
'th': 'ठ',
'dh': 'ढ',
'ph': 'फ',
'bh': 'भ',
'sh': 'श',
'tr': 'त्र',
'gy': 'ज्ञ',
'a': 'अ',
'i': 'इ',
'u': 'उ',
'e': 'ए',
'o': 'ओ',
'k': 'क',
'g': 'ग',
'j': 'ज',
't': 'ट',
'd': 'ड',
'n': '',
'p': 'प',
'b': 'ब',
'm': 'म',
'y': 'य',
'r': 'र',
'l': 'ल',
'v': 'व',
's': 'स',
'h': 'ह',
'0': '०',
'1': '१',
'2': '२',
'3': '३',
'4': '४',
'5': '५',
'6': '६',
'7': '७',
'8': '८',
'9': '९',
'.': '।',
',': '़',
' ': ' '
}
input_text = input("Enter English text: ")
transliterated_text = transliterate(input_text.lower(), english_to_hindi_dict)
print("Transliterated text in Hindi:", transliterated_text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment