This repository has been archived by the owner on Sep 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
i18n_controller.py
50 lines (36 loc) · 1.56 KB
/
i18n_controller.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
#!/usr/bin/python
# -*- coding: utf-8 -*-
# use json in Python 2.7, fallback to simplejson for Python 2.5
from google.appengine.ext.webapp.util import run_wsgi_app
import webapp2
# It's important to have this prior to the imports below that require imports
# to request_handler.py. The structure of the imports are such that this
# module causes a lot of circular imports to happen, so including it once out
# the way at first seems to fix some of those issues.
import request_cache
from gae_mini_profiler import profiler
from gae_bingo.middleware import GAEBingoWSGIMiddleware
import request_handler
import user_util
import wsgi_compat
class ShowJson(request_handler.RequestHandler):
@user_util.open_access
def get(self, language, namespace):
try:
with open('./locale/' + language + "/" + namespace + ".json") as file:
#Open JSON file and return it
self.response.out.write(file.read())
self.response.headers['Content-Type'] = "application/json"
except IOError as e:
self.response.out.write("{}")
application = webapp2.WSGIApplication([
('/locale/(.*)/(.*)', ShowJson),
], debug=True)
application = profiler.ProfilerWSGIMiddleware(application)
application = GAEBingoWSGIMiddleware(application)
application = request_cache.RequestCacheMiddleware(application)
application = wsgi_compat.WSGICompatHeaderMiddleware(application)
def main():
run_wsgi_app(application)
if __name__ == '__main__':
main()