[enh] Retrieve value for current locale and use it for app description

This commit is contained in:
Jérôme Lebleu 2014-06-04 11:58:21 +02:00
parent e3f27e01e0
commit 27a3415964
2 changed files with 25 additions and 9 deletions

23
app.py
View file

@ -211,7 +211,7 @@ def app_info(app, raw=False):
else: else:
return { return {
'name': app_info['manifest']['name'], 'name': app_info['manifest']['name'],
'description': app_info['manifest']['description']['en'], 'description': _value_for_locale(app_info['manifest']['description']),
# FIXME: Temporarly allow undefined license # FIXME: Temporarly allow undefined license
'license': app_info['manifest'].get('license', 'license': app_info['manifest'].get('license',
m18n.n('license_undefined')), m18n.n('license_undefined')),
@ -1112,6 +1112,27 @@ def _is_installed(app):
return False return False
def _value_for_locale(values):
"""
Return proper value for current locale
Keyword arguments:
values -- A dict of values associated to their locale
"""
if not isinstance(values, dict):
return values
for lang in [m18n.locale, m18n.default_locale]:
try:
return values[lang]
except KeyError:
continue
# Fallback to first value
return values.values()[0]
def is_true(arg): def is_true(arg):
""" """
Convert a string into a boolean Convert a string into a boolean

11
hook.py
View file

@ -129,6 +129,8 @@ def hook_exec(file, args=None):
args -- Arguments to pass to the script args -- Arguments to pass to the script
""" """
from yunohost.app import _value_for_locale
if isinstance(args, list): if isinstance(args, list):
arg_list = args arg_list = args
else: else:
@ -146,14 +148,7 @@ def hook_exec(file, args=None):
else: else:
if os.isatty(1) and 'ask' in arg: if os.isatty(1) and 'ask' in arg:
# Retrieve proper ask string # Retrieve proper ask string
ask_string = None ask_string = _value_for_locale(arg['ask'])
for lang in [m18n.locale, m18n.default_locale]:
if lang in arg['ask']:
ask_string = arg['ask'][lang]
break
if not ask_string:
# Fallback to en
ask_string = arg['ask']['en']
# Append extra strings # Append extra strings
if 'choices' in arg: if 'choices' in arg: