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
|
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):
|
def wrapper(*args, **kwargs):
|
||||||
# Bring arguments together
|
# Bring arguments together
|
||||||
params = kwargs
|
params = kwargs
|
||||||
|
@ -449,8 +443,17 @@ class Interface(BaseInterface):
|
||||||
return json_encode(callback(*args, **kwargs))
|
return json_encode(callback(*args, **kwargs))
|
||||||
return wrapper
|
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
|
# Install plugins
|
||||||
app.install(apiheader)
|
app.install(apiheader)
|
||||||
|
app.install(api18n)
|
||||||
app.install(_ActionsMapPlugin(actionsmap))
|
app.install(_ActionsMapPlugin(actionsmap))
|
||||||
|
|
||||||
# Append default routes
|
# Append default routes
|
||||||
|
|
|
@ -67,6 +67,8 @@ def pretty_print_dict(d, depth=0):
|
||||||
def get_locale():
|
def get_locale():
|
||||||
"""Return current user locale"""
|
"""Return current user locale"""
|
||||||
lang = locale.getdefaultlocale()[0]
|
lang = locale.getdefaultlocale()[0]
|
||||||
|
if not lang:
|
||||||
|
return ''
|
||||||
return lang[:2]
|
return lang[:2]
|
||||||
|
|
||||||
# CLI Classes Implementation -------------------------------------------
|
# CLI Classes Implementation -------------------------------------------
|
||||||
|
|
Loading…
Add table
Reference in a new issue