From 735ca3af87e95e98453e9754b629cdae89f994cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lebleu?= Date: Mon, 2 Jun 2014 18:17:56 +0200 Subject: [PATCH] [i18n] Allow translation of some parameters in the action map --- moulinette/actionsmap.py | 10 +++++++--- moulinette/interfaces/__init__.py | 4 ++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/moulinette/actionsmap.py b/moulinette/actionsmap.py index c9ba392d..471a8de8 100644 --- a/moulinette/actionsmap.py +++ b/moulinette/actionsmap.py @@ -96,7 +96,7 @@ class AskParameter(_ExtraParameter): try: # Ask for the argument value - return msignals.prompt(message) + return msignals.prompt(m18n.n(message)) except NotImplementedError: return arg_value @@ -128,7 +128,7 @@ class PasswordParameter(AskParameter): try: # Ask for the password - return msignals.prompt(message, True, True) + return msignals.prompt(m18n.n(message), True, True) except NotImplementedError: return arg_value @@ -146,7 +146,7 @@ class PatternParameter(_ExtraParameter): pattern, message = (arguments[0], arguments[1]) if arg_value and not re.match(pattern, arg_value or ''): - raise MoulinetteError(errno.EINVAL, message) + raise MoulinetteError(errno.EINVAL, m18n.n(message)) return arg_value @staticmethod @@ -340,6 +340,10 @@ class ActionsMap(object): with open('%s/actionsmap/%s.yml' % (pkg.datadir, n)) as f: actionsmaps[n] = yaml.load(f) + # Load translations + # FIXME: Allow several namespaces in m18n + m18n.load_namespace(n) + # Generate parsers self.extraparser = ExtraArgumentParser(parser.interface) self._parser = self._construct_parser(actionsmaps) diff --git a/moulinette/interfaces/__init__.py b/moulinette/interfaces/__init__.py index 724a98ae..5cd5612b 100644 --- a/moulinette/interfaces/__init__.py +++ b/moulinette/interfaces/__init__.py @@ -291,6 +291,10 @@ class BaseActionsMapParser(object): """ if name == 'authenticator' and value: (identifier, configuration, parameters) = value + # Translate help + h = configuration['help'] + if h: + configuration['help'] = m18n.n(h) # Return global configuration and an authenticator # instanciator as a 2-tuple