Skip to content

Instantly share code, notes, and snippets.

@saumikn
Created July 18, 2023 14:25
Show Gist options
  • Save saumikn/4a2916eca4821a87f49aacadc65ba9dd to your computer and use it in GitHub Desktop.
Save saumikn/4a2916eca4821a87f49aacadc65ba9dd to your computer and use it in GitHub Desktop.
# For more information on this transliteration scheme, please go to https://saumikn.com/blog/tamil-transliteration
import re
consonants = {'க்க':'kk','ச்ச':'cc','ட்ட':'ṭṭ','த்த':'tt','ப்ப':'pp',
'ங்க':'ng','ஞ்ச':'nj','ண்ட':'ṇḍ','ந்த':'nd','ம்ப':'mb',
r'(^|\s)க':r'\1k',r'(^|\s)ச':r'\1c',r'(^|\s)ட':r'\1ṭ',r'(^|\s)த':r'\1t',r'(^|\s)ப':r'\1p',
'க':'g','ங':'ng','ச':'s','ஞ':'ñ','ட':'ḍ','ண':'ṇ',
'த':'d','ந':'n','ப':'b','ம':'m','ய':'y','ர':'r',
'ல':'l','வ':'v','ழ':'zh','ள':'ḷ','ற':'r','ன':'n',
'ஜ':'j','ஶ':'s','ஷ':'sh', 'ஸ':'s','ஹ':'h'}
vowels1 = {'ா':'aa','ி':'i','ீ':'ii','ு':'u','ூ':'uu','ெ':'e','ே':'ee','ை':'ai','ொ':'o','ோ':'oo','ௌ':'au','்':'','':'a',}
vowels2 = {'அ':'a','ஆ':'aa','இ':'i','ஈ':'ii','உ':'u','ஊ':'uu',
'எ':'e','ஏ':'ee','ஐ':'ai','ஒ':'o','ஓ':'oo','ஔ':'au',}
def transliterate(str):
for c1, c2 in consonants.items():
for v1, v2 in vowels1.items():
str = re.sub(c1+v1, c2+v2, str)
for v1, v2 in vowels2.items():
str = re.sub(v1, v2, str)
return str
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment