summaryrefslogtreecommitdiff
path: root/openstackclient/api
diff options
context:
space:
mode:
authorHuanxuan Ao <huanxuan.ao@easystack.cn>2016-06-12 19:59:10 +0800
committerDean Troyer <dtroyer@gmail.com>2016-06-14 11:03:56 -0500
commitf25a3519c525cd8f3ff04c841b63c10f640c27f6 (patch)
tree9618055b28918d7bca63e2fad78e4351c8a4cc48 /openstackclient/api
parent769baf329e6aa619e7d9a5e48a5230bcf4399228 (diff)
downloadpython-openstackclient-f25a3519c525cd8f3ff04c841b63c10f640c27f6.tar.gz
Fix missing i18n supports in api/ and shell.py
Change-Id: I28d79d7f44b27d2b600dedad2a3601180650ad83 Partial-bug: #1574965
Diffstat (limited to 'openstackclient/api')
-rw-r--r--openstackclient/api/api.py22
-rw-r--r--openstackclient/api/auth.py18
-rw-r--r--openstackclient/api/auth_plugin.py6
3 files changed, 28 insertions, 18 deletions
diff --git a/openstackclient/api/api.py b/openstackclient/api/api.py
index 0b00ff50..04d88f31 100644
--- a/openstackclient/api/api.py
+++ b/openstackclient/api/api.py
@@ -19,6 +19,8 @@ from keystoneauth1 import exceptions as ks_exceptions
from keystoneauth1 import session as ks_session
from osc_lib import exceptions
+from openstackclient.i18n import _
+
class KeystoneSession(object):
"""Wrapper for the Keystone Session
@@ -254,9 +256,11 @@ class BaseAPI(KeystoneSession):
if len(data) == 1:
return data[0]
if len(data) > 1:
- msg = "Multiple %s exist with %s='%s'"
+ msg = _("Multiple %(resource)s exist with %(attr)s='%(value)s'")
raise exceptions.CommandError(
- msg % (resource, attr, value),
+ msg % {'resource': resource,
+ 'attr': attr,
+ 'value': value}
)
# Search by id
@@ -264,8 +268,12 @@ class BaseAPI(KeystoneSession):
data = getlist(kwargs)
if len(data) == 1:
return data[0]
- msg = "No %s with a %s or ID of '%s' found"
- raise exceptions.CommandError(msg % (resource, attr, value))
+ msg = _("No %(resource)s with a %(attr)s or ID of '%(value)s' found")
+ raise exceptions.CommandError(
+ msg % {'resource': resource,
+ 'attr': attr,
+ 'value': value}
+ )
def find_bulk(
self,
@@ -313,10 +321,10 @@ class BaseAPI(KeystoneSession):
bulk_list = self.find_bulk(path, **kwargs)
num_bulk = len(bulk_list)
if num_bulk == 0:
- msg = "none found"
+ msg = _("none found")
raise exceptions.NotFound(msg)
elif num_bulk > 1:
- msg = "many found"
+ msg = _("many found")
raise RuntimeError(msg)
return bulk_list[0]
@@ -343,7 +351,7 @@ class BaseAPI(KeystoneSession):
try:
ret = self.find_one("/%s/detail" % (path), **kwargs)
except ks_exceptions.NotFound:
- msg = "%s not found" % value
+ msg = _("%s not found") % value
raise exceptions.NotFound(msg)
return ret
diff --git a/openstackclient/api/auth.py b/openstackclient/api/auth.py
index a55af293..b56035e4 100644
--- a/openstackclient/api/auth.py
+++ b/openstackclient/api/auth.py
@@ -171,7 +171,8 @@ def check_valid_auth_options(options, auth_plugin_name, required_scope=True):
'auth.url'))
if msgs:
- raise exc.CommandError('Missing parameter(s): \n%s' % '\n'.join(msgs))
+ raise exc.CommandError(
+ _('Missing parameter(s): \n%s') % '\n'.join(msgs))
def build_auth_plugins_option_parser(parser):
@@ -187,10 +188,9 @@ def build_auth_plugins_option_parser(parser):
metavar='<auth-type>',
dest='auth_type',
default=utils.env('OS_AUTH_TYPE'),
- help='Select an authentication type. Available types: ' +
- ', '.join(available_plugins) +
- '. Default: selected based on --os-username/--os-token' +
- ' (Env: OS_AUTH_TYPE)',
+ help=_('Select an authentication type. Available types: %s.'
+ ' Default: selected based on --os-username/--os-token'
+ ' (Env: OS_AUTH_TYPE)') % ', '.join(available_plugins),
choices=available_plugins
)
# Maintain compatibility with old tenant env vars
@@ -215,10 +215,10 @@ def build_auth_plugins_option_parser(parser):
OPTIONS_LIST[o]['env'],
utils.env(OPTIONS_LIST[o]['env']),
),
- help='%s\n(Env: %s)' % (
- OPTIONS_LIST[o]['help'],
- OPTIONS_LIST[o]['env'],
- ),
+ help=_('%(help)s\n(Env: %(env)s)') % {
+ 'help': OPTIONS_LIST[o]['help'],
+ 'env': OPTIONS_LIST[o]['env'],
+ },
)
# add tenant-related options for compatibility
# this is deprecated but still used in some tempest tests...
diff --git a/openstackclient/api/auth_plugin.py b/openstackclient/api/auth_plugin.py
index 44d3b38e..36dc5160 100644
--- a/openstackclient/api/auth_plugin.py
+++ b/openstackclient/api/auth_plugin.py
@@ -21,6 +21,8 @@ from six.moves.urllib import parse as urlparse
from keystoneauth1.loading._plugins import admin_token as token_endpoint
from keystoneauth1.loading._plugins.identity import generic as ksa_password
+from openstackclient.i18n import _
+
LOG = logging.getLogger(__name__)
@@ -51,10 +53,10 @@ class TokenEndpoint(token_endpoint.AdminToken):
options.extend([
# Maintain name 'url' for compatibility
cfg.StrOpt('url',
- help='Specific service endpoint to use'),
+ help=_('Specific service endpoint to use')),
cfg.StrOpt('token',
secret=True,
- help='Authentication token to use'),
+ help=_('Authentication token to use')),
])
return options