-
Notifications
You must be signed in to change notification settings - Fork 4
/
loma.py
238 lines (204 loc) · 7.07 KB
/
loma.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# -*- coding: utf-8 -*-
#!/usr/bin/env python
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import os
import webapp2
import base
from google.appengine.ext.webapp import template
Language = 'Loma'
Language_native = 'Löömàgòòi'
LanguageCode = 'lom'
ScriptCode = 'Loma'
encoding_font_list = [
# {
# 'family': 'JGLoma41',
# 'font_name': 'JGLoma41',
# 'longName': 'JG Loma 41',
# 'source': '/fonts/African_font_encodings/JG Loma41.ttf',
# 'font_path': '/fonts/African_font_encodings/JG Loma41.ttf',
# 'note': "Not Unicode"
# },
{
'family': 'JGLoma',
'font_name': 'JGLoma',
'longName': 'JG Loma',
'source': '/fonts/African_font_encodings/JGLoma.ttf',
'font_path': '/fonts/African_font_encodings/JGLoma.ttf',
},
{
'family': 'JGLomaPUA',
'font_name': 'JGLomaPUA',
'longName': 'JG Loma PUA',
'source': '/fonts/African_font_encodings/JGLOMAPUA-Regular.ttf',
'font_path': '/fonts/African_font_encodings/JGLOMAPUA-Regular.ttf',
},]
# Until we have a Unicode font.
unicode_font_list = encoding_font_list
kb_list = [
{'shortName': 'lom_Loma_PUA',
'longName': 'Loma PUA',
'fontFamily': 'JGLomaPUA',
'inputFontFamily': "Arial",
},
{'shortName': LanguageCode + '_' + ScriptCode,
'longName': Language + ' ' + ScriptCode,
'fontFamily': 'JGLoma',
'inputFontFamily': "Arial",
},
]
links = [
{'linkText': 'Keyboard',
'ref': '/' + LanguageCode + '/',
},
# {'linkText': 'Converter',
# 'ref': '/' + LanguageCode + '/convertUI/'},
# {'linkText': 'Font conversion summary',
# 'ref': '/' + LanguageCode + '/encodingRules/'
# },
{'linkText': 'Keyboard transforms',
'ref': '/' + LanguageCode + '/kbtransforms/'
},
{'linkText': 'Phonetic table',
'ref': '/' + LanguageCode + '/phonetickb/'
},
{'linkText': 'Unicode proposal',
'ref': 'http://www.unicode.org/L2/L2017/17233-n4837-loma.pdf'
},
{'linkText': 'Omniglot Loma syllabary',
'ref': 'https://www.omniglot.com/writing/lomasyllabary.htm'
},
{'linkText': 'Loma Wikipedia',
'ref': 'https://en.wikipedia.org/wiki/Loma_language'
},
]
encodedRanges = [
[0xa2, 0x1C5],
[0x1C7, 0x1d6],
]
class langInfo():
def __init__(self):
self.LanguageCode = LanguageCode
self.Language = Language
self.Language_native = Language_native
self.test_data = u''
self.unicode_font_list = unicode_font_list
self.encoding_font_list = encoding_font_list
self.lang_list = {'shortName': LanguageCode,
'longName': Language,
#'reference': 'https://tau.olunga.to/keyboard.html'
},
# For attaching sorting, etc.
self.text_functions = 'js/lom.js'
self.kb_list = kb_list
self.links = links
# For additional resources for download
self.text_file_list = []
self.encoded_ranges = encodedRanges
self.converters = None
self.kb_messages = [
'The phonetic input codes used for each Loma syllable can be changed easily. Use feedback to suggest changes.'
]
self.unicode_database = 'unicode_data/kpelle_char_data.txt'
# TODO: Fill in the rest of the common data.
# TODO: Fill in with diacritics
diacritic_list = []
#TODO: Fill in base consonant
default_base_consonant = u'\u1c00'
# Presents UI for conversions from font encoding to Unicode.
class ConvertUIHandler(webapp2.RequestHandler):
def get(self):
# All old characters
oldCharList = []
for run in encodedRanges:
oldCharList.extend([unichr(x) + ' ' for x in xrange(run[0], run[1])])
oldChars = ''.join(oldCharList)
text = self.request.get('text', oldChars)
font = self.request.get('font')
testStringList = [
{'name': 'Test 1', # Note: must escape the single quote.
'string': u'\u0004\u0005\u0006\u0007\u0008\u0009' +
'\u000a\u000b'},
]
oldInput = text
unicodeChars = ''
unicodeCombiningChars = ''
template_values = {
'font': font,
'language': Language,
'langTag': LanguageCode,
'encodingList': encoding_font_list,
'encoding': encoding_font_list[0],
'kb_list': kb_list,
'unicodeFonts': unicode_font_list,
'links': links,
'oldChars': oldChars,
'oldInput': oldInput,
'text': text,
'textStrings': testStringList,
'showTools': self.request.get('tools', None),
'unicodeChars': unicodeChars,
'combiningChars': unicodeCombiningChars,
}
path = os.path.join(os.path.dirname(__file__), 'HTML/translit_general.html')
self.response.out.write(template.render(path, template_values))
class DiacriticHandler(webapp2.RequestHandler):
def get(self):
global default_base_consonant
# Generate combinations of base + diacritic pairs
inchars = self.request.get('base', None)
if not inchars:
base_consonant = default_base_consonant
elif inchars[0] == 'u':
base_consonant = unichr(int(''.join(inchars[1:]), 16))
else:
# A unicode character
base_consonant = inchars
combos = []
table = []
singles = [' ', 'none']
for y in diacritic_list:
row = [y + ' (%4x)' %ord(y[0])]
singles.append(base_consonant + y)
for x in diacritic_list:
text = base_consonant + y + x
combos.append({'text': text,
'codes': ['%4x ' % ord(c) for c in text]})
row.append(text)
table.append(row)
template_values = {
'language': Language,
'base_char': base_consonant.encode('utf-8'),
'base_hex': ['%4x' % ord(x) for x in base_consonant],
'diacritics': [x for x in diacritic_list],
'diacritics_hex': ['%4x ' % ord(y[0]) for y in diacritic_list],
'singles': singles,
'combinations': combos,
'table': table,
'unicode_font_list': unicode_font_list,
}
path = os.path.join(os.path.dirname(__file__), 'HTML/diacritics.html')
self.response.out.write(template.render(path, template_values))
langInstance = langInfo()
app = webapp2.WSGIApplication([
('/' + LanguageCode + '/', base.LanguagesHomeHandler),
('/' + LanguageCode + '/convertUI/', ConvertUIHandler),
('/' + LanguageCode + '/downloads/', base.Downloads),
('/' + LanguageCode + '/encodingRules/', base.EncodingRules),
('/' + LanguageCode + '/diacritic/', DiacriticHandler),
('/lom/phonetickb/', base.PhoneticKbHandler),
('/' + langInstance.LanguageCode + '/kbtransforms/', base.KeyboardTransforms),
], debug=True,
config={'langInfo': langInstance}
)