diff --git a/bin/yunohost b/bin/yunohost index 6b253334..a8c1e88a 100755 --- a/bin/yunohost +++ b/bin/yunohost @@ -28,19 +28,23 @@ if __name__ == '__main__': use_cache = False sys.argv.remove('--no-cache') - try: - args = list(sys.argv) - args.pop(0) + args = list(sys.argv) + args.pop(0) - # Check that YunoHost is installed - if not os.path.isfile('/etc/yunohost/installed') \ - and (len(args) < 2 or args[1] != 'tools' or args[2] != 'postinstall'): - raise YunoHostError(17, _("YunoHost is not correctly installed, please execute 'yunohost tools postinstall'")) + # Check that YunoHost is installed + if not os.path.isfile('/etc/yunohost/installed') and \ + (len(args) < 2 or args[1] != 'tools' or args[2] != 'postinstall'): + from moulinette.interfaces.cli import colorize, get_locale - # Execute the action - ret = cli(['yunohost'], args, use_cache) - except YunoHostError as e: - # TODO: Remove this and associated import when yunohost package has been revisited - print(colorize(_("Error: "), 'red') + e.message) - sys.exit(e.code) + # Init i18n + m18n.load_namespace('yunohost') + m18n.set_locale(get_locale()) + + # Print error and exit + print('%s %s' % (colorize(m18n.g('error'), 'red'), + m18n.n('yunohost_not_installed'))) + sys.exit(1) + + # Execute the action + ret = cli(['yunohost'], args, use_cache) sys.exit(ret) diff --git a/bin/yunohost-api b/bin/yunohost-api index 744e16b7..df29b144 100755 --- a/bin/yunohost-api +++ b/bin/yunohost-api @@ -47,6 +47,6 @@ if __name__ == '__main__': {('GET', '/installed'): is_installed}, use_cache) except MoulinetteError as e: from moulinette.interfaces.cli import colorize - print(_('%s: %s' % (colorize(_('Error'), 'red'), e.strerror))) + print('%s %s' % (colorize(m18n.g('error'), 'red'), e.strerror)) sys.exit(e.errno) sys.exit(0) diff --git a/lib/yunohost/locales/en.json b/lib/yunohost/locales/en.json index 40b1f9a4..2c25aacf 100644 --- a/lib/yunohost/locales/en.json +++ b/lib/yunohost/locales/en.json @@ -1,5 +1,6 @@ { "yunohost" : "YunoHost", + "yunohost_not_installed" : "YunoHost is not or not correctly installed. Please execute 'yunohost tools postinstall'.", "upgrade_complete" : "Upgrade complete", "installation_complete" : "Installation complete", diff --git a/moulinette/interfaces/cli.py b/moulinette/interfaces/cli.py index c5b6b3c6..528a4d7f 100644 --- a/moulinette/interfaces/cli.py +++ b/moulinette/interfaces/cli.py @@ -4,6 +4,7 @@ import os import errno import getpass import argparse +import locale from moulinette.core import MoulinetteError from moulinette.interfaces import (BaseActionsMapParser, BaseInterface) @@ -63,6 +64,10 @@ def pretty_print_dict(d, depth=0): v = str(v) print((" ") * depth + "%s: %s" % (str(k), v)) +def get_locale(): + """Return current user locale""" + lang = locale.getdefaultlocale()[0] + return lang[:2] # CLI Classes Implementation ------------------------------------------- @@ -157,11 +162,8 @@ class Interface(BaseInterface): """ def __init__(self, actionsmap): - import locale - # Set user locale - lang = locale.getdefaultlocale()[0] - m18n.set_locale(lang[:2]) + m18n.set_locale(get_locale()) # Connect signals to handlers msignals.set_handler('authenticate', self._do_authenticate)