[fix] Proper handling locale in api and cli

This commit is contained in:
Jérôme Lebleu 2014-05-16 23:49:53 +02:00
parent d7f2151d78
commit dcdc4cff8e
2 changed files with 11 additions and 6 deletions

View file

@ -165,12 +165,6 @@ class _ActionsMapPlugin(object):
context -- An instance of Route
"""
try:
# Attempt to retrieve and set locale
m18n.set_locale(request.params.pop('locale'))
except:
pass
def wrapper(*args, **kwargs):
# Bring arguments together
params = kwargs
@ -449,8 +443,17 @@ class Interface(BaseInterface):
return json_encode(callback(*args, **kwargs))
return wrapper
## Attempt to retrieve and set locale
def api18n(callback):
try:
m18n.set_locale(request.params.pop('locale'))
except:
pass
return callback
# Install plugins
app.install(apiheader)
app.install(api18n)
app.install(_ActionsMapPlugin(actionsmap))
# Append default routes

View file

@ -67,6 +67,8 @@ def pretty_print_dict(d, depth=0):
def get_locale():
"""Return current user locale"""
lang = locale.getdefaultlocale()[0]
if not lang:
return ''
return lang[:2]
# CLI Classes Implementation -------------------------------------------