From 27a34159647c4e5fce8153cdc0cc4dde0cb92073 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lebleu?= Date: Wed, 4 Jun 2014 11:58:21 +0200 Subject: [PATCH] [enh] Retrieve value for current locale and use it for app description --- app.py | 23 ++++++++++++++++++++++- hook.py | 11 +++-------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/app.py b/app.py index 4e2e4763c..b13dd098d 100644 --- a/app.py +++ b/app.py @@ -211,7 +211,7 @@ def app_info(app, raw=False): else: return { 'name': app_info['manifest']['name'], - 'description': app_info['manifest']['description']['en'], + 'description': _value_for_locale(app_info['manifest']['description']), # FIXME: Temporarly allow undefined license 'license': app_info['manifest'].get('license', m18n.n('license_undefined')), @@ -1112,6 +1112,27 @@ def _is_installed(app): 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): """ Convert a string into a boolean diff --git a/hook.py b/hook.py index f49a4b732..9fa4457ed 100644 --- a/hook.py +++ b/hook.py @@ -129,6 +129,8 @@ def hook_exec(file, args=None): args -- Arguments to pass to the script """ + from yunohost.app import _value_for_locale + if isinstance(args, list): arg_list = args else: @@ -146,14 +148,7 @@ def hook_exec(file, args=None): else: if os.isatty(1) and 'ask' in arg: # Retrieve proper ask string - ask_string = None - 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'] + ask_string = _value_for_locale(arg['ask']) # Append extra strings if 'choices' in arg: