Fix missing i18n supports in api/ and shell.py

Change-Id: I28d79d7f44b27d2b600dedad2a3601180650ad83
Partial-bug: #1574965
This commit is contained in:
Huanxuan Ao 2016-06-12 19:59:10 +08:00 committed by Dean Troyer
parent 769baf329e
commit f25a3519c5
4 changed files with 52 additions and 37 deletions

View File

@ -19,6 +19,8 @@ from keystoneauth1 import exceptions as ks_exceptions
from keystoneauth1 import session as ks_session from keystoneauth1 import session as ks_session
from osc_lib import exceptions from osc_lib import exceptions
from openstackclient.i18n import _
class KeystoneSession(object): class KeystoneSession(object):
"""Wrapper for the Keystone Session """Wrapper for the Keystone Session
@ -254,9 +256,11 @@ class BaseAPI(KeystoneSession):
if len(data) == 1: if len(data) == 1:
return data[0] return data[0]
if len(data) > 1: if len(data) > 1:
msg = "Multiple %s exist with %s='%s'" msg = _("Multiple %(resource)s exist with %(attr)s='%(value)s'")
raise exceptions.CommandError( raise exceptions.CommandError(
msg % (resource, attr, value), msg % {'resource': resource,
'attr': attr,
'value': value}
) )
# Search by id # Search by id
@ -264,8 +268,12 @@ class BaseAPI(KeystoneSession):
data = getlist(kwargs) data = getlist(kwargs)
if len(data) == 1: if len(data) == 1:
return data[0] return data[0]
msg = "No %s with a %s or ID of '%s' found" msg = _("No %(resource)s with a %(attr)s or ID of '%(value)s' found")
raise exceptions.CommandError(msg % (resource, attr, value)) raise exceptions.CommandError(
msg % {'resource': resource,
'attr': attr,
'value': value}
)
def find_bulk( def find_bulk(
self, self,
@ -313,10 +321,10 @@ class BaseAPI(KeystoneSession):
bulk_list = self.find_bulk(path, **kwargs) bulk_list = self.find_bulk(path, **kwargs)
num_bulk = len(bulk_list) num_bulk = len(bulk_list)
if num_bulk == 0: if num_bulk == 0:
msg = "none found" msg = _("none found")
raise exceptions.NotFound(msg) raise exceptions.NotFound(msg)
elif num_bulk > 1: elif num_bulk > 1:
msg = "many found" msg = _("many found")
raise RuntimeError(msg) raise RuntimeError(msg)
return bulk_list[0] return bulk_list[0]
@ -343,7 +351,7 @@ class BaseAPI(KeystoneSession):
try: try:
ret = self.find_one("/%s/detail" % (path), **kwargs) ret = self.find_one("/%s/detail" % (path), **kwargs)
except ks_exceptions.NotFound: except ks_exceptions.NotFound:
msg = "%s not found" % value msg = _("%s not found") % value
raise exceptions.NotFound(msg) raise exceptions.NotFound(msg)
return ret return ret

View File

@ -171,7 +171,8 @@ def check_valid_auth_options(options, auth_plugin_name, required_scope=True):
'auth.url')) 'auth.url'))
if msgs: 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): def build_auth_plugins_option_parser(parser):
@ -187,10 +188,9 @@ def build_auth_plugins_option_parser(parser):
metavar='<auth-type>', metavar='<auth-type>',
dest='auth_type', dest='auth_type',
default=utils.env('OS_AUTH_TYPE'), default=utils.env('OS_AUTH_TYPE'),
help='Select an authentication type. Available types: ' + help=_('Select an authentication type. Available types: %s.'
', '.join(available_plugins) + ' Default: selected based on --os-username/--os-token'
'. Default: selected based on --os-username/--os-token' + ' (Env: OS_AUTH_TYPE)') % ', '.join(available_plugins),
' (Env: OS_AUTH_TYPE)',
choices=available_plugins choices=available_plugins
) )
# Maintain compatibility with old tenant env vars # Maintain compatibility with old tenant env vars
@ -215,10 +215,10 @@ def build_auth_plugins_option_parser(parser):
OPTIONS_LIST[o]['env'], OPTIONS_LIST[o]['env'],
utils.env(OPTIONS_LIST[o]['env']), utils.env(OPTIONS_LIST[o]['env']),
), ),
help='%s\n(Env: %s)' % ( help=_('%(help)s\n(Env: %(env)s)') % {
OPTIONS_LIST[o]['help'], 'help': OPTIONS_LIST[o]['help'],
OPTIONS_LIST[o]['env'], 'env': OPTIONS_LIST[o]['env'],
), },
) )
# add tenant-related options for compatibility # add tenant-related options for compatibility
# this is deprecated but still used in some tempest tests... # this is deprecated but still used in some tempest tests...

View File

@ -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 import admin_token as token_endpoint
from keystoneauth1.loading._plugins.identity import generic as ksa_password from keystoneauth1.loading._plugins.identity import generic as ksa_password
from openstackclient.i18n import _
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -51,10 +53,10 @@ class TokenEndpoint(token_endpoint.AdminToken):
options.extend([ options.extend([
# Maintain name 'url' for compatibility # Maintain name 'url' for compatibility
cfg.StrOpt('url', cfg.StrOpt('url',
help='Specific service endpoint to use'), help=_('Specific service endpoint to use')),
cfg.StrOpt('token', cfg.StrOpt('token',
secret=True, secret=True,
help='Authentication token to use'), help=_('Authentication token to use')),
]) ])
return options return options

View File

@ -36,6 +36,7 @@ from oslo_utils import strutils
import openstackclient import openstackclient
from openstackclient.common import clientmanager from openstackclient.common import clientmanager
from openstackclient.common import commandmanager from openstackclient.common import commandmanager
from openstackclient.i18n import _
from os_client_config import config as cloud_config from os_client_config import config as cloud_config
@ -63,9 +64,8 @@ def prompt_for_password(prompt=None):
pass pass
# No password because we did't have a tty or nothing was entered # No password because we did't have a tty or nothing was entered
if not pw: if not pw:
raise exc.CommandError( raise exc.CommandError(_("No password entered, or found via"
"No password entered, or found via --os-password or OS_PASSWORD", " --os-password or OS_PASSWORD"),)
)
return pw return pw
@ -185,7 +185,7 @@ class OpenStackShell(app.App):
metavar='<cloud-config-name>', metavar='<cloud-config-name>',
dest='cloud', dest='cloud',
default=utils.env('OS_CLOUD'), default=utils.env('OS_CLOUD'),
help='Cloud name in clouds.yaml (Env: OS_CLOUD)', help=_('Cloud name in clouds.yaml (Env: OS_CLOUD)'),
) )
# Global arguments # Global arguments
parser.add_argument( parser.add_argument(
@ -193,37 +193,41 @@ class OpenStackShell(app.App):
metavar='<auth-region-name>', metavar='<auth-region-name>',
dest='region_name', dest='region_name',
default=utils.env('OS_REGION_NAME'), default=utils.env('OS_REGION_NAME'),
help='Authentication region name (Env: OS_REGION_NAME)') help=_('Authentication region name (Env: OS_REGION_NAME)'),
)
parser.add_argument( parser.add_argument(
'--os-cacert', '--os-cacert',
metavar='<ca-bundle-file>', metavar='<ca-bundle-file>',
dest='cacert', dest='cacert',
default=utils.env('OS_CACERT'), default=utils.env('OS_CACERT'),
help='CA certificate bundle file (Env: OS_CACERT)') help=_('CA certificate bundle file (Env: OS_CACERT)'),
)
parser.add_argument( parser.add_argument(
'--os-cert', '--os-cert',
metavar='<certificate-file>', metavar='<certificate-file>',
dest='cert', dest='cert',
default=utils.env('OS_CERT'), default=utils.env('OS_CERT'),
help='Client certificate bundle file (Env: OS_CERT)') help=_('Client certificate bundle file (Env: OS_CERT)'),
)
parser.add_argument( parser.add_argument(
'--os-key', '--os-key',
metavar='<key-file>', metavar='<key-file>',
dest='key', dest='key',
default=utils.env('OS_KEY'), default=utils.env('OS_KEY'),
help='Client certificate key file (Env: OS_KEY)') help=_('Client certificate key file (Env: OS_KEY)'),
)
verify_group = parser.add_mutually_exclusive_group() verify_group = parser.add_mutually_exclusive_group()
verify_group.add_argument( verify_group.add_argument(
'--verify', '--verify',
action='store_true', action='store_true',
default=None, default=None,
help='Verify server certificate (default)', help=_('Verify server certificate (default)'),
) )
verify_group.add_argument( verify_group.add_argument(
'--insecure', '--insecure',
action='store_true', action='store_true',
default=None, default=None,
help='Disable server certificate verification', help=_('Disable server certificate verification'),
) )
parser.add_argument( parser.add_argument(
'--os-default-domain', '--os-default-domain',
@ -232,28 +236,29 @@ class OpenStackShell(app.App):
default=utils.env( default=utils.env(
'OS_DEFAULT_DOMAIN', 'OS_DEFAULT_DOMAIN',
default=DEFAULT_DOMAIN), default=DEFAULT_DOMAIN),
help='Default domain ID, default=' + help=_('Default domain ID, default=%s. '
DEFAULT_DOMAIN + '(Env: OS_DEFAULT_DOMAIN)') % DEFAULT_DOMAIN,
' (Env: OS_DEFAULT_DOMAIN)') )
parser.add_argument( parser.add_argument(
'--os-interface', '--os-interface',
metavar='<interface>', metavar='<interface>',
dest='interface', dest='interface',
choices=['admin', 'public', 'internal'], choices=['admin', 'public', 'internal'],
default=utils.env('OS_INTERFACE'), default=utils.env('OS_INTERFACE'),
help='Select an interface type.' help=_('Select an interface type.'
' Valid interface types: [admin, public, internal].' ' Valid interface types: [admin, public, internal].'
' (Env: OS_INTERFACE)') ' (Env: OS_INTERFACE)'),
)
parser.add_argument( parser.add_argument(
'--timing', '--timing',
default=False, default=False,
action='store_true', action='store_true',
help="Print API call timing info", help=_("Print API call timing info"),
) )
parser.add_argument( parser.add_argument(
'--os-beta-command', '--os-beta-command',
action='store_true', action='store_true',
help="Enable beta commands which are subject to change", help=_("Enable beta commands which are subject to change"),
) )
# osprofiler HMAC key argument # osprofiler HMAC key argument
@ -262,7 +267,7 @@ class OpenStackShell(app.App):
'--os-profile', '--os-profile',
metavar='hmac-key', metavar='hmac-key',
dest='profile', dest='profile',
help='HMAC key for encrypting profiling context data', help=_('HMAC key for encrypting profiling context data'),
) )
# NOTE(dtroyer): This global option should have been named # NOTE(dtroyer): This global option should have been named
# --os-profile as --profile interferes with at # --os-profile as --profile interferes with at