mdsr commited on
Commit
9eedf5d
·
1 Parent(s): dfc8066
Files changed (1) hide show
  1. app.py +180 -7
app.py CHANGED
@@ -20,16 +20,189 @@ TITLE = "Concatenative Synthesis: Rule Based Text to Sign Language Translator"
20
  CUSTOM_JS = """<script>
21
  const rtlLanguages = ["urdu", "arabic"];
22
 
23
- function updateTextareaDir(language) {
24
- const sourceTextarea = document.getElementById("source-textbox").querySelector("textarea");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
- if (rtlLanguages.includes(language)) {
27
- sourceTextarea.setAttribute("dir", "rtl");
28
- } else {
29
- sourceTextarea.setAttribute("dir", "ltr");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
  }
 
 
 
 
 
 
 
31
  }
32
- </script>"""
 
33
  # todo: add dropdown keyboard custom component with key mapping
34
  # todo: output full height
35
 
 
20
  CUSTOM_JS = """<script>
21
  const rtlLanguages = ["urdu", "arabic"];
22
 
23
+ const keyMap = {
24
+ "urdu": {
25
+ "1": "۱",
26
+ "2": "۲",
27
+ "3": "۳",
28
+ "4": "۴",
29
+ "5": "۵",
30
+ "6": "٦",
31
+ "7": "۷",
32
+ "8": "۸",
33
+ "9": "۹",
34
+ "0": "۰",
35
+ "q": "ق",
36
+ "w": "و",
37
+ "e": "ع",
38
+ "r": "ر",
39
+ "t": "ت",
40
+ "y": "ے",
41
+ "u": "ء",
42
+ "i": "ی",
43
+ "o": "ہ",
44
+ "p": "پ",
45
+ "a": "ا",
46
+ "s": "س",
47
+ "d": "د",
48
+ "f": "ف",
49
+ "g": "گ",
50
+ "h": "ح",
51
+ "j": "ج",
52
+ "k": "ک",
53
+ "l": "ل",
54
+ "z": "ز",
55
+ "x": "ش",
56
+ "c": "چ",
57
+ "v": "ط",
58
+ "b": "ب",
59
+ "n": "ن",
60
+ "m": "م",
61
+ "R": "ڑ",
62
+ "T": "ٹ",
63
+ "Y": "َ",
64
+ "U": "ئ",
65
+ "I": "ِ",
66
+ "P": "ُ",
67
+ "A": "آ",
68
+ "S": "ص",
69
+ "D": "ڈ",
70
+ "F": "أ",
71
+ "G": "غ",
72
+ "H": "ھ",
73
+ "J": "ض",
74
+ "K": "خ",
75
+ "Z": "ذ",
76
+ "X": "ژ",
77
+ "C": "ث",
78
+ "V": "ظ",
79
+ "N": "ں",
80
+ ",": "،",
81
+ ".": "۔",
82
+ "?": "؟",
83
+ ";": "؛",
84
+ },
85
+ "hindi": {
86
+ "1": "१",
87
+ "2": "२",
88
+ "3": "३",
89
+ "4": "४",
90
+ "5": "५",
91
+ "6": "६",
92
+ "7": "७",
93
+ "8": "८",
94
+ "9": "९",
95
+ "0": "०",
96
+ "=": "ृ",
97
+ "!": "ऍ",
98
+ "@": "ॅ",
99
+ "#": "्र",
100
+ "$": "र्",
101
+ "%": "ज्ञ",
102
+ "^": "त्र",
103
+ "&": "क्ष",
104
+ "*": "श्र",
105
+ "_": "ः",
106
+ "+": "ऋ",
107
+ "q": "ौ",
108
+ "w": "ै",
109
+ "e": "ा",
110
+ "r": "ी",
111
+ "t": "ू",
112
+ "y": "ब",
113
+ "u": "ह",
114
+ "i": "ग",
115
+ "o": "द",
116
+ "p": "ज",
117
+ "[": "ड",
118
+ "]": "़",
119
+ '\\\\': "ॉ",
120
+ "Q": "औ",
121
+ "W": "ऐ",
122
+ "E": "आ",
123
+ "R": "ई",
124
+ "T": "ऊ",
125
+ "Y": "भ",
126
+ "U": "ङ",
127
+ "I": "घ",
128
+ "O": "ध",
129
+ "P": "झ",
130
+ "{": "ढ",
131
+ "}": "ञ",
132
+ "|": "ऑ",
133
+ "a": "ो",
134
+ "s": "े",
135
+ "d": "्",
136
+ "f": "ि",
137
+ "g": "ु",
138
+ "h": "प",
139
+ "j": "र",
140
+ "k": "क",
141
+ "l": "त",
142
+ ";": "च",
143
+ "'": "ट",
144
+ "A": "ओ",
145
+ "S": "ए",
146
+ "D": "अ",
147
+ "F": "इ",
148
+ "G": "उ",
149
+ "H": "फ",
150
+ "J": "ऱ",
151
+ "K": "ख",
152
+ "L": "थ",
153
+ ":": "छ",
154
+ '"': "ठ",
155
+ "z": "ॆ",
156
+ "x": "ं",
157
+ "c": "म",
158
+ "v": "न",
159
+ "b": "व",
160
+ "n": "ल",
161
+ "m": "स",
162
+ ".": "।",
163
+ "/": "य",
164
+ "Z": "ऎ",
165
+ "X": "ँ",
166
+ "C": "ण",
167
+ "V": "ऩ",
168
+ "B": "ऴ",
169
+ "N": "ळ",
170
+ "M": "श",
171
+ "<": "ष",
172
+ ">": "य़",
173
+ // "?":"य़",
174
+ }
175
+ };
176
 
177
+ function updateTextareaDir(language) {
178
+ const sourceTextarea = document.getElementById("source-textbox").querySelector("textarea");
179
+
180
+ if (rtlLanguages.includes(language)) {
181
+ sourceTextarea.setAttribute("dir", "rtl");
182
+ } else {
183
+ sourceTextarea.setAttribute("dir", "ltr");
184
+ }
185
+
186
+ function keypressHandler(event) {
187
+ const key = event.key;
188
+ if (keyMap[language].hasOwnProperty(key)) {
189
+ event.preventDefault();
190
+ const mappedValue = keyMap[language][key];
191
+ const start = sourceTextarea.selectionStart;
192
+ const end = sourceTextarea.selectionEnd;
193
+ sourceTextarea.value = sourceTextarea.value.slice(0, start) + mappedValue + sourceTextarea.value.slice(end);
194
+ sourceTextarea.selectionStart = sourceTextarea.selectionEnd = start + mappedValue.length;
195
  }
196
+ }
197
+
198
+ sourceTextarea.removeEventListener("keypress", sourceTextarea.keypressHandler);
199
+ sourceTextarea.addEventListener("keypress", keypressHandler);
200
+
201
+ // Save the handler function to the textarea element for future removal
202
+ sourceTextarea.keypressHandler = keypressHandler;
203
  }
204
+ </script>
205
+ """
206
  # todo: add dropdown keyboard custom component with key mapping
207
  # todo: output full height
208