python - Can we do global setting with i18n in webapp2? -
i have category list, , i'd use i18n can change language locale.
my python code following:
from webapp2_extras import i18n category_list = {} category_list['bikes'] = {'value': i18n.gettext('category_bikes')} class categorieshandler(basehandler): """list categories""" def get(self, **kwargs): """list categories""" self.response.write(self.json_output(category_list)) and cause error:
file "/users/user/developer/gae/project/categorieshandler.py", line 11, in <module> category_list['bikes'] = {'value': i18n.gettext('category_bikes')} file "/users/user/developer/gae/project/webapp2_extras/i18n.py", line 713, in gettext return get_i18n().gettext(string, **variables) file "/users/user/developer/gae/project/webapp2_extras/i18n.py", line 894, in get_i18n request = request or webapp2.get_request() file "/applications/googleappenginelauncher.app/contents/resources/googleappengine-default.bundle/contents/resources/google_appengine/lib/webapp2/webapp2.py", line 1720, in get_request assert getattr(_local, 'request', none) not none, _get_request_error assertionerror: request global variable not set. however if move category_list class method, fine.
class categorieshandler(basehandler): """list categories""" def get(self, **kwargs): """list categories""" category_list = {} category_list['bikes'] = {'value': i18n.gettext('category_bikes')} self.response.write(self.json_output(category_list)) pass the problem need separate category_list config file can maintain code easily. there way solve problem? thanks!
try gettext_lazy instead, won't actual translation lookup until later (when know language want translate to).
a common convention is
from webapp2_extras.i18n import _lazy _ category_list['bikes'] = {'value': _('category_bikes')}
Comments
Post a Comment