-
Notifications
You must be signed in to change notification settings - Fork 0
/
converter.py
111 lines (78 loc) · 3.33 KB
/
converter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# -*- coding: utf-8 -*-
import sys
consonants= []
consonantsUni= []
vowels= []
vowelsUni= []
vowelModifiersUni= []
specialConsonants= []
specialConsonantsUni= []
specialCharUni= []
specialChar= []
vowelsUni.extend(['ඌ','ඕ','ඕ','ආ','ආ','ඈ','ඈ','ඈ','ඊ','ඊ','ඊ','ඊ','ඒ','ඒ','ඒ','ඌ','ඌ','ඖ','ඇ'])
vowels.extend(['oo','o\\)','oe','aa','a\\)','Aa','A\\)','ae','ii','i\\)','ie','ee','ea','e\\)','ei','uu','u\\)','au','/\a'])
vowelModifiersUni.extend(['ූ','ෝ','ෝ','ා','ා','ෑ','ෑ','ෑ','ී','ී','ී','ී','ේ','ේ','ේ','ූ','ූ','ෞ','ැ'])
vowelsUni.extend(['අ','ඇ','ඉ','එ','උ','ඔ','ඓ'])
vowels.extend(['a','A','i','e','u','o','I'])
vowelModifiersUni.extend(['','ැ','ි','ෙ','ු','ො','ෛ'])
nVowels=26;
specialConsonantsUni.extend(['ං','ඃ','ඞ','ඍ'])
specialConsonants.extend(["\n","\h","\N","\R"])
# special characher Repaya
specialConsonantsUni.append('ර්'+'\u200D')
specialConsonantsUni.append('ර්'+'\u200D')
specialConsonants.append("/R")
specialConsonants.append("\r")
consonantsUni.extend(['ඬ','ඳ','ඟ','ථ','ධ','ඝ','ඡ','ඵ','භ','ශ','ෂ','ඥ','ඤ','ළු','ද','ච','ඛ','ත'])
consonants.extend(['nnd','nndh','nng','Th','Dh','gh','Ch','ph','bh','sh','Sh','GN','KN','Lu','dh','ch','kh','th'])
consonantsUni.extend(['ට','ක','ඩ','න','ප','බ','ම','ය','ය','ය','ජ','ල','ව','ව','ස','හ','ණ','ළ','ඛ','ඝ','ඨ','ඪ','ඵ','ඹ','ෆ','ඣ','ග'])
consonants.extend(['t','k','d','n','p','b','m','\\u005C' + 'y','Y','y','j','l','v','w','s','h','N','L','K','G','T','D','P','B','f','q','g'])
consonantsUni.append('ර')
consonants.append('r')
specialCharUni.append('ෲ')
specialChar.append('ruu')
specialCharUni.append('ෘ')
specialChar.append('ru')
# specialCharUni.append('්ර')
# specialChar.append('ra')
def Translate(text):
# special consonents
for i in range (0,len(specialConsonants)):
text = text.replace(specialConsonants[i], specialConsonantsUni[i])
# consonents + special
for i in range (0,len(specialCharUni)):
for j in range(0,len(consonants)):
s = consonants[j] + specialChar[i]
v = consonantsUni[j] + specialCharUni[i]
r = s
text = text.replace(r, v)
# consonants + Rakaransha + vowel modifiers
for j in range(0,len(consonants)):
for i in range(0,len(vowels)):
s = consonants[j] + "r" + vowels[i]
v = consonantsUni[j] + "්ර" + vowelModifiersUni[i]
r = s
# r = new RegExp(s, "g")
text = text.replace(r, v)
s = consonants[j] + "r"
v = consonantsUni[j] + "්ර"
r = v
text = text.replace(r, v)
# constants with vowels modifiers
for i in range(0,len(consonants)):
for j in range(0,nVowels):
s = consonants[i]+vowels[j]
v = consonantsUni[i] + vowelModifiersUni[j]
r = s
text = text.replace(r, v)
# Hal kirima
for i in range(0, len(consonants)):
r = consonants[i]
text = text.replace(r, consonantsUni[i]+"්")
# adding vowels
for i in range(0,len(vowels)):
r = vowels[i]
text = text.replace(r, vowelsUni[i])
return text
if __name__ == '__main__':
print Translate(sys.argv[1])