Skip to content

Commit

Permalink
Fix i18n messages in neutronclient
Browse files Browse the repository at this point in the history
Using tools/check_i18n.py to scan source directory, and fix most of
the errors.
    - Message internationalization
    - First letter must be capital
    - Using comma instead of percent in LOG.xxx

Partial-Bug: #1217100
Change-Id: I312f999f97e33d84c3f06fa1caacf32affc26a78
  • Loading branch information
Sergio Cazzolato committed Nov 30, 2013
1 parent 607645a commit 6d937f3
Show file tree
Hide file tree
Showing 36 changed files with 355 additions and 329 deletions.
3 changes: 2 additions & 1 deletion neutronclient/client.py
Expand Up @@ -31,6 +31,7 @@

from neutronclient.common import exceptions
from neutronclient.common import utils
from neutronclient.openstack.common.gettextutils import _

_logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -215,7 +216,7 @@ def _extract_service_catalog(self, body):

def authenticate(self):
if self.auth_strategy != 'keystone':
raise exceptions.Unauthorized(message='unknown auth strategy')
raise exceptions.Unauthorized(message=_('Unknown auth strategy'))
if self.tenant_id:
body = {'auth': {'passwordCredentials':
{'username': self.username,
Expand Down
4 changes: 2 additions & 2 deletions neutronclient/common/exceptions.py
Expand Up @@ -120,15 +120,15 @@ class EndpointTypeNotFound(NeutronClientException):
"""Could not find endpoint type in Service Catalog."""

def __str__(self):
msg = "Could not find endpoint type %s in Service Catalog."
msg = _("Could not find endpoint type %s in Service Catalog.")
return msg % repr(self.message)


class AmbiguousEndpoints(NeutronClientException):
"""Found more than one matching endpoint in Service Catalog."""

def __str__(self):
return "AmbiguousEndpoints: %s" % repr(self.message)
return _("AmbiguousEndpoints: %s") % repr(self.message)


class NeutronCLIError(NeutronClientException):
Expand Down
11 changes: 7 additions & 4 deletions neutronclient/common/utils.py
Expand Up @@ -26,6 +26,7 @@
import os
import sys

from neutronclient.common import _
from neutronclient.common import exceptions
from neutronclient.openstack.common import strutils

Expand Down Expand Up @@ -97,8 +98,10 @@ def get_client_class(api_name, version, version_map):
try:
client_path = version_map[str(version)]
except (KeyError, ValueError):
msg = "Invalid %s client version '%s'. must be one of: %s" % (
(api_name, version, ', '.join(version_map.keys())))
msg = _("Invalid %(api_name)s client version '%(version)s'. must be "
"one of: %(map_keys)s")
msg = msg % {'api_name': api_name, 'version': version,
'map_keys': ', '.join(version_map.keys())}
raise exceptions.UnsupportedVersion(msg)

return import_class(client_path)
Expand Down Expand Up @@ -170,13 +173,13 @@ def http_log_req(_logger, args, kwargs):
if 'body' in kwargs and kwargs['body']:
string_parts.append(" -d '%s'" % (kwargs['body']))
string_parts = safe_encode_list(string_parts)
_logger.debug("\nREQ: %s\n" % "".join(string_parts))
_logger.debug(_("\nREQ: %s\n"), "".join(string_parts))


def http_log_resp(_logger, resp, body):
if not _logger.isEnabledFor(logging.DEBUG):
return
_logger.debug("RESP:%s %s\n", resp, body)
_logger.debug(_("RESP:%(resp)s %(body)s\n"), {'resp': resp, 'body': body})


def _safe_encode_without_obj(data):
Expand Down
4 changes: 3 additions & 1 deletion neutronclient/neutron/client.py
Expand Up @@ -17,6 +17,7 @@

from neutronclient.common import exceptions
from neutronclient.common import utils
from neutronclient.openstack.common.gettextutils import _


API_NAME = 'network'
Expand Down Expand Up @@ -49,7 +50,8 @@ def make_client(instance):
ca_cert=instance._ca_cert)
return client
else:
raise exceptions.UnsupportedVersion("API version %s is not supported" %
raise exceptions.UnsupportedVersion(_("API version %s is not "
"supported") %
instance._api_version[API_NAME])


Expand Down
54 changes: 27 additions & 27 deletions neutronclient/neutron/v2_0/__init__.py
Expand Up @@ -90,7 +90,7 @@ def find_resourceid_by_name_or_id(client, resource, name_or_id):
def add_show_list_common_argument(parser):
parser.add_argument(
'-D', '--show-details',
help='show detailed info',
help=_('Show detailed info'),
action='store_true',
default=False, )
parser.add_argument(
Expand All @@ -105,8 +105,8 @@ def add_show_list_common_argument(parser):
parser.add_argument(
'-F', '--field',
dest='fields', metavar='FIELD',
help='specify the field(s) to be returned by server,'
' can be repeated',
help=_('Specify the field(s) to be returned by server,'
' can be repeated'),
action='append',
default=[])

Expand All @@ -115,8 +115,8 @@ def add_pagination_argument(parser):
parser.add_argument(
'-P', '--page-size',
dest='page_size', metavar='SIZE', type=int,
help=("specify retrieve unit of each request, then split one request "
"to several requests"),
help=_("Specify retrieve unit of each request, then split one request "
"to several requests"),
default=None)


Expand All @@ -125,16 +125,16 @@ def add_sorting_argument(parser):
'--sort-key',
dest='sort_key', metavar='FIELD',
action='append',
help=("sort list by specified fields (This option can be repeated), "
"The number of sort_dir and sort_key should match each other, "
"more sort_dir specified will be omitted, less will be filled "
"with asc as default direction "),
help=_("Sort list by specified fields (This option can be repeated), "
"The number of sort_dir and sort_key should match each other, "
"more sort_dir specified will be omitted, less will be filled "
"with asc as default direction "),
default=[])
parser.add_argument(
'--sort-dir',
dest='sort_dir', metavar='{asc,desc}',
help=("sort list in specified directions "
"(This option can be repeated)"),
help=_("Sort list in specified directions "
"(This option can be repeated)"),
action='append',
default=[],
choices=['asc', 'desc'])
Expand All @@ -159,7 +159,7 @@ def _process_previous_argument(current_arg, _value_number, current_type_str,
if _value_number == 0 and (current_type_str or _list_flag):
# This kind of argument should have value
raise exceptions.CommandError(
"invalid values_specs %s" % ' '.join(values_specs))
_("Invalid values_specs %s") % ' '.join(values_specs))
if _value_number > 1 or _list_flag or current_type_str == 'list':
current_arg.update({'nargs': '+'})
elif _value_number == 0:
Expand Down Expand Up @@ -230,15 +230,15 @@ def parse_args_to_dict(values_specs):
_value_number = 0
if _item in _options:
raise exceptions.CommandError(
"duplicated options %s" % ' '.join(values_specs))
_("Duplicated options %s") % ' '.join(values_specs))
else:
_options.update({_item: {}})
current_arg = _options[_item]
_item = current_item
elif _item.startswith('type='):
if current_arg is None:
raise exceptions.CommandError(
"invalid values_specs %s" % ' '.join(values_specs))
_("Invalid values_specs %s") % ' '.join(values_specs))
if 'type' not in current_arg:
current_type_str = _item.split('=', 2)[1]
current_arg.update({'type': eval(current_type_str)})
Expand All @@ -260,7 +260,7 @@ def parse_args_to_dict(values_specs):
if (not current_item or '=' in current_item or
_item.startswith('-') and not is_number(_item)):
raise exceptions.CommandError(
"Invalid values_specs %s" % ' '.join(values_specs))
_("Invalid values_specs %s") % ' '.join(values_specs))
_value_number += 1

_values_specs.append(_item)
Expand Down Expand Up @@ -351,7 +351,7 @@ def get_parser(self, prog_name):
parser = super(NeutronCommand, self).get_parser(prog_name)
parser.add_argument(
'--request-format',
help=_('the xml or json request format'),
help=_('The xml or json request format'),
default='json',
choices=['json', 'xml', ], )
parser.add_argument(
Expand Down Expand Up @@ -396,7 +396,7 @@ def get_parser(self, prog_name):
parser = super(CreateCommand, self).get_parser(prog_name)
parser.add_argument(
'--tenant-id', metavar='TENANT_ID',
help=_('the owner tenant ID'), )
help=_('The owner tenant ID'), )
parser.add_argument(
'--tenant_id',
help=argparse.SUPPRESS)
Expand Down Expand Up @@ -438,12 +438,12 @@ def get_parser(self, prog_name):
parser = super(UpdateCommand, self).get_parser(prog_name)
parser.add_argument(
'id', metavar=self.resource.upper(),
help='ID or name of %s to update' % self.resource)
help=_('ID or name of %s to update') % self.resource)
self.add_known_arguments(parser)
return parser

def run(self, parsed_args):
self.log.debug('run(%s)' % parsed_args)
self.log.debug('run(%s)', parsed_args)
neutron_client = self.get_client()
neutron_client.format = parsed_args.request_format
_extra_values = parse_args_to_dict(self.values_specs)
Expand All @@ -456,7 +456,7 @@ def run(self, parsed_args):
body[self.resource] = _extra_values
if not body[self.resource]:
raise exceptions.CommandError(
"Must specify new values to update %s" % self.resource)
_("Must specify new values to update %s") % self.resource)
if self.allow_names:
_id = find_resourceid_by_name_or_id(
neutron_client, self.resource, parsed_args.id)
Expand Down Expand Up @@ -485,16 +485,16 @@ class DeleteCommand(NeutronCommand):
def get_parser(self, prog_name):
parser = super(DeleteCommand, self).get_parser(prog_name)
if self.allow_names:
help_str = 'ID or name of %s to delete'
help_str = _('ID or name of %s to delete')
else:
help_str = 'ID of %s to delete'
help_str = _('ID of %s to delete')
parser.add_argument(
'id', metavar=self.resource.upper(),
help=help_str % self.resource)
return parser

def run(self, parsed_args):
self.log.debug('run(%s)' % parsed_args)
self.log.debug('run(%s)', parsed_args)
neutron_client = self.get_client()
neutron_client.format = parsed_args.request_format
obj_deleter = getattr(neutron_client,
Expand Down Expand Up @@ -604,7 +604,7 @@ def setup_columns(self, info, parsed_args):
for s in info), )

def get_data(self, parsed_args):
self.log.debug('get_data(%s)' % parsed_args)
self.log.debug('get_data(%s)', parsed_args)
data = self.retrieve_list(parsed_args)
self.extend_list(data, parsed_args)
return self.setup_columns(data, parsed_args)
Expand All @@ -624,16 +624,16 @@ def get_parser(self, prog_name):
parser = super(ShowCommand, self).get_parser(prog_name)
add_show_list_common_argument(parser)
if self.allow_names:
help_str = 'ID or name of %s to look up'
help_str = _('ID or name of %s to look up')
else:
help_str = 'ID of %s to look up'
help_str = _('ID of %s to look up')
parser.add_argument(
'id', metavar=self.resource.upper(),
help=help_str % self.resource)
return parser

def get_data(self, parsed_args):
self.log.debug('get_data(%s)' % parsed_args)
self.log.debug('get_data(%s)', parsed_args)
neutron_client = self.get_client()
neutron_client.format = parsed_args.request_format

Expand Down
28 changes: 14 additions & 14 deletions neutronclient/neutron/v2_0/agentscheduler.py
Expand Up @@ -33,10 +33,10 @@ def get_parser(self, prog_name):
parser = super(AddNetworkToDhcpAgent, self).get_parser(prog_name)
parser.add_argument(
'dhcp_agent',
help='ID of the DHCP agent')
help=_('ID of the DHCP agent'))
parser.add_argument(
'network',
help='network to add')
help=_('Network to add'))
return parser

def run(self, parsed_args):
Expand All @@ -59,10 +59,10 @@ def get_parser(self, prog_name):
parser = super(RemoveNetworkFromDhcpAgent, self).get_parser(prog_name)
parser.add_argument(
'dhcp_agent',
help='ID of the DHCP agent')
help=_('ID of the DHCP agent'))
parser.add_argument(
'network',
help='network to remove')
help=_('Network to remove'))
return parser

def run(self, parsed_args):
Expand All @@ -88,7 +88,7 @@ def get_parser(self, prog_name):
self).get_parser(prog_name)
parser.add_argument(
'dhcp_agent',
help='ID of the DHCP agent')
help=_('ID of the DHCP agent'))
return parser

def call_server(self, neutron_client, search_opts, parsed_args):
Expand All @@ -111,7 +111,7 @@ def get_parser(self, prog_name):
self).get_parser(prog_name)
parser.add_argument(
'network',
help='network to query')
help=_('Network to query'))
return parser

def extend_list(self, data, parsed_args):
Expand All @@ -136,10 +136,10 @@ def get_parser(self, prog_name):
parser = super(AddRouterToL3Agent, self).get_parser(prog_name)
parser.add_argument(
'l3_agent',
help='ID of the L3 agent')
help=_('ID of the L3 agent'))
parser.add_argument(
'router',
help='router to add')
help=_('Router to add'))
return parser

def run(self, parsed_args):
Expand All @@ -163,10 +163,10 @@ def get_parser(self, prog_name):
parser = super(RemoveRouterFromL3Agent, self).get_parser(prog_name)
parser.add_argument(
'l3_agent',
help='ID of the L3 agent')
help=_('ID of the L3 agent'))
parser.add_argument(
'router',
help='router to remove')
help=_('Router to remove'))
return parser

def run(self, parsed_args):
Expand Down Expand Up @@ -196,7 +196,7 @@ def get_parser(self, prog_name):
self).get_parser(prog_name)
parser.add_argument(
'l3_agent',
help='ID of the L3 agent to query')
help=_('ID of the L3 agent to query'))
return parser

def call_server(self, neutron_client, search_opts, parsed_args):
Expand All @@ -218,7 +218,7 @@ def get_parser(self, prog_name):
parser = super(ListL3AgentsHostingRouter,
self).get_parser(prog_name)
parser.add_argument('router',
help='router to query')
help=_('Router to query'))
return parser

def extend_list(self, data, parsed_args):
Expand Down Expand Up @@ -247,7 +247,7 @@ def get_parser(self, prog_name):
parser = super(ListPoolsOnLbaasAgent, self).get_parser(prog_name)
parser.add_argument(
'lbaas_agent',
help='ID of the loadbalancer agent to query')
help=_('ID of the loadbalancer agent to query'))
return parser

def call_server(self, neutron_client, search_opts, parsed_args):
Expand All @@ -272,7 +272,7 @@ def get_parser(self, prog_name):
parser = super(GetLbaasAgentHostingPool,
self).get_parser(prog_name)
parser.add_argument('pool',
help='pool to query')
help=_('Pool to query'))
return parser

def extend_list(self, data, parsed_args):
Expand Down

0 comments on commit 6d937f3

Please sign in to comment.