This repository was archived by the owner on Jun 6, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathhandlers.py
More file actions
75 lines (66 loc) · 2.12 KB
/
handlers.py
File metadata and controls
75 lines (66 loc) · 2.12 KB
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
from google.appengine.ext import webapp
from google.appengine.api import memcache
from google.appengine.ext.webapp import template
import hyphenate_html
class BaseHandler(webapp.RequestHandler):
def render_template(self, template_name='base.html', values={}):
values.update({
'languages': LANGUAGES
})
return template.render(template_name, values)
class HtmlHyphenator(BaseHandler):
def get(self):
self.response.out.write(self.render_template('base.html', {
'lang': 'en-us',
'lang_name': 'English'
}))
def post(self):
content = self.request.get('content')
lang = self.request.get('lang', 'en-us')
output = hyphenate_html.hyphenate_html(content, lang,
get_hyphenator(lang))
self.response.out.write(self.render_template('base.html', {
'content': content,
'lang': lang,
'output': output
}))
LANGUAGES = [
('cs-cz', 'Czech'),
('da-dk', 'Danish'),
('de-de', 'German'),
('de-ch', 'German (Swiss)'),
('el-gr', 'Greek'),
('en-ca', 'English (Canadian)'),
('en-gb', 'English (UK)'),
('en-us', 'English (US)'),
('es-es', 'Spanish'),
('fi-fi', 'Finish'),
('ga-ie', 'Irish'),
('hu-hu', 'Hungarian'),
('ia', 'Interlingua'),
('id-id', 'Indonesian'),
('is-is', 'Icelandic'),
('it-it', 'Italian'),
('lt-lt', 'Lithuanian'),
('nl-nl', 'Dutch (Standard)'),
('pl-pl', 'Polish'),
('pt-br', 'Portuguese (Brazil)'),
('pt-pt', 'Portuguese (Portugal)'),
('ro-ro', 'Romanian'),
('ru-ru', 'Russian'),
('sh', 'Serbo-Croatian'),
('sk-sk', 'Slovak'),
('sl-si', 'Slovenian'),
('sr', 'Sorbian'),
('sv-se', 'Swedish'),
('uk-ua', 'Ukranian')
]
def get_hyphenator(lang='en-us'):
"""Get the hyphenator for language, defaults to en-us
Uses memcache
"""
hyphenator = memcache.get('hyp-' + lang)
if not hyphenator:
hyphenator = hyphenate_html.get_hyphenator_for_language(lang)
memcache.set('hyp-' + lang, hyphenator)
return hyphenator