Skip to content

Instantly share code, notes, and snippets.

@tzuryby
Created March 6, 2011 10:50
Show Gist options
  • Save tzuryby/857202 to your computer and use it in GitHub Desktop.
Save tzuryby/857202 to your computer and use it in GitHub Desktop.
root@precision:/home/tzury/Desktop# python i18n.py
Te AMO
ERROR:root:i18n.html code:
1 def _execute():
2 _buffer = []
3 _tmp = _("I love you")
4 if isinstance(_tmp, str): _buffer.append(_tmp)
5 elif isinstance(_tmp, unicode): _buffer.append(_tmp.encode('utf-8'))
6 else: _buffer.append(str(_tmp))
7 _buffer.append('\n')
8 return ''.join(_buffer)
ERROR:root:Uncaught exception GET / (127.0.0.1)
HTTPRequest(protocol='http', host='localhost:8888', method='GET', uri='/', version='HTTP/1.1', remote_ip='127.0.0.1', remote_ip='127.0.0.1', body='', headers={'Accept-Language': 'en-US,en;q=0.8', 'Accept-Encoding': 'gzip,deflate,sdch', 'Host': 'localhost:8888', 'Accept': 'application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5', 'User-Agent': 'Mozilla/5.0 (X11; U; Linux x86_64; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.126 Safari/534.16', 'Accept-Charset': 'UTF-8,*;q=0.5', 'Connection': 'keep-alive', 'Cookie': '_xsrf=f27d54c221c341c3a75ee334b05d3bcb; usename=c2hyYWdh|1298441218|43e3f95345ed402cd60d3f7a5ae5d11476116859; fullname=c2hyYWdh|1298441218|dd73068e8b2f89e0af4e571c75e8dd44e4535638; user=YWRtaW4=|1298777252|e680934a492c8a41552bbaf34e62e95eba17d21d; ui-tabs-5=2; ui-tabs-4=0; ui-tabs-3=0; ui-tabs-2=1; ui-tabs-1=0', 'Cache-Control': 'max-age=0'})
Traceback (most recent call last):
File "/usr/local/lib/python2.6/dist-packages/tornado-0.2-py2.6.egg/tornado/web.py", line 732, in _execute
getattr(self, self.request.method.lower())(*args, **kwargs)
File "i18n.py", line 15, in get
self.render('i18n.html')
File "/usr/local/lib/python2.6/dist-packages/tornado-0.2-py2.6.egg/tornado/web.py", line 332, in render
html = self.render_string(template_name, **kwargs)
File "/usr/local/lib/python2.6/dist-packages/tornado-0.2-py2.6.egg/tornado/web.py", line 440, in render_string
return t.generate(**args)
File "/usr/local/lib/python2.6/dist-packages/tornado-0.2-py2.6.egg/tornado/template.py", line 126, in generate
return execute()
File "i18n.html", line 3, in _execute
ValueError: translation table must be 256 characters long
ERROR:root:500 GET / (127.0.0.1) 5.69ms
WARNING:root:404 GET /favicon.ico (127.0.0.1) 0.32ms
I love you Te AMO
{{_("I love you")}}
import os
import tornado
import tornado.httpserver
import tornado.ioloop
import tornado.web
from tornado import locale
class MainHandler(tornado.web.RequestHandler):
def get_user_locale(self):
return "es_ES"
def get(self):
user_locale = locale.get("es_ES")
print user_locale.translate("I love you")
self.render('i18n.html')
application = tornado.web.Application(
[(r"/", MainHandler),],
**dict(template_path=os.path.join(os.path.dirname(__file__), "templates"))
)
if __name__ == "__main__":
tornado.locale.load_translations(
os.path.join(os.path.dirname(__file__), "translations"))
http_server = tornado.httpserver.HTTPServer(application)
http_server.listen(8888, '')
tornado.ioloop.IOLoop.instance().start()
@fanzeyi
Copy link

fanzeyi commented Feb 10, 2012

should be:

return tornado.locale.get('es_ES')

XD

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment