From 6cfe67fb9c2aafb351421eea59a4fb9ce00afb51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Lebleu?= Date: Sat, 9 Apr 2016 22:46:49 +0200 Subject: [PATCH] [i18n] Use named variables in translations --- locales/en.json | 10 +++++----- moulinette/actionsmap.py | 10 ++++++---- moulinette/authenticators/ldap.py | 2 +- moulinette/interfaces/api.py | 2 +- moulinette/interfaces/cli.py | 2 +- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/locales/en.json b/locales/en.json index bede54c5..d737f944 100644 --- a/locales/en.json +++ b/locales/en.json @@ -17,20 +17,20 @@ "unable_retrieve_session" : "Unable to retrieve the session", "ldap_server_down" : "Unable to reach LDAP server", "ldap_operation_error" : "An error occured during LDAP operation", - "ldap_attribute_already_exists" : "Attribute already exists: '{:s}={:s}'", + "ldap_attribute_already_exists" : "Attribute '{attribute}' already exists with value '{value}'", "invalid_usage" : "Invalid usage, pass --help to see help", "deprecated_command" : "'{prog} {old}' is deprecated and will be removed in the future, use '{prog} {new}' instead", - "argument_required" : "Argument {:s} is required", - "invalid_argument": "Invalid argument '{:s}': {:s}", + "argument_required" : "Argument '{argument}' is required", + "invalid_argument": "Invalid argument '{argument}': {error}", "pattern_not_match": "Does not match pattern", "password" : "Password", "invalid_password" : "Invalid password", - "confirm" : "Confirm {:s}", + "confirm" : "Confirm {prompt}", "values_mismatch" : "Values don't match", "authentication_required_long" : "Authentication is required to perform this action", "authentication_required" : "Authentication required", - "authentication_profile_required" : "Authentication to profile '{:s}' required", + "authentication_profile_required" : "Authentication to profile '{profile}' required", "operation_interrupted" : "Operation interrupted", "logged_in" : "Logged in", diff --git a/moulinette/actionsmap.py b/moulinette/actionsmap.py index 0d696b36..7ece6718 100644 --- a/moulinette/actionsmap.py +++ b/moulinette/actionsmap.py @@ -163,8 +163,9 @@ class PatternParameter(_ExtraParameter): if msg == message: msg = m18n.g(message) - raise MoulinetteError(errno.EINVAL, m18n.g('invalid_argument', - arg_name, msg)) + raise MoulinetteError(errno.EINVAL, + m18n.g('invalid_argument', + argument=arg_name, error=msg)) return arg_value @staticmethod @@ -192,8 +193,9 @@ class RequiredParameter(_ExtraParameter): if required and (arg_value is None or arg_value == ''): logger.debug("argument '%s' is required", v, arg_name, pattern) - raise MoulinetteError(errno.EINVAL, m18n.g('argument_required', - arg_name)) + raise MoulinetteError(errno.EINVAL, + m18n.g('argument_required', + argument=arg_name)) return arg_value @staticmethod diff --git a/moulinette/authenticators/ldap.py b/moulinette/authenticators/ldap.py index b4ddfca3..a14248fb 100644 --- a/moulinette/authenticators/ldap.py +++ b/moulinette/authenticators/ldap.py @@ -214,5 +214,5 @@ class Authenticator(BaseAuthenticator): attr, value) raise MoulinetteError(errno.EEXIST, m18n.g('ldap_attribute_already_exists', - attr, value)) + attribute=attr, value=value)) return True diff --git a/moulinette/interfaces/api.py b/moulinette/interfaces/api.py index f80a30ad..2b715b31 100644 --- a/moulinette/interfaces/api.py +++ b/moulinette/interfaces/api.py @@ -410,7 +410,7 @@ class _ActionsMapPlugin(object): msg = m18n.g('authentication_required') else: msg = m18n.g('authentication_profile_required', - authenticator.name) + profile=authenticator.name) raise HTTPUnauthorizedResponse(msg) else: return authenticator(token=(s_id, s_hash)) diff --git a/moulinette/interfaces/cli.py b/moulinette/interfaces/cli.py index 68940fa5..3623e96f 100644 --- a/moulinette/interfaces/cli.py +++ b/moulinette/interfaces/cli.py @@ -393,7 +393,7 @@ class Interface(BaseInterface): if confirm: m = message[0].lower() + message[1:] - if prompt(m18n.g('confirm', m)) != value: + if prompt(m18n.g('confirm', prompt=m)) != value: raise MoulinetteError(errno.EINVAL, m18n.g('values_mismatch')) return value