mirror of
https://github.com/YunoHost/moulinette.git
synced 2024-09-03 20:06:31 +02:00
[fix] Proper handling locale in api and cli
This commit is contained in:
parent
d7f2151d78
commit
dcdc4cff8e
2 changed files with 11 additions and 6 deletions
|
@ -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
|
||||
|
|
|
@ -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 -------------------------------------------
|
||||
|
|
Loading…
Add table
Reference in a new issue