Output Strings of bin/*.py should support i18n

Many more output strings in cinder/bin/*.py don't support i18n,
which should be fixed as visible message.

Change-Id: I863c09a0a398b99360e5a080091e320b594d4024
Closes-Bug: #1257613
This commit is contained in:
ling-yun 2013-12-04 15:22:57 +08:00
parent e128cffb9c
commit 801401787b
2 changed files with 25 additions and 20 deletions

View File

@ -197,8 +197,7 @@ class HostCommands(object):
"""Show a list of all physical hosts. Filter by zone.
args: [zone]
"""
print("%-25s\t%-15s" % (_('host'),
_('zone')))
print(_("%(host)-25s\t%(zone)-15s") % {'host': 'host', 'zone': 'zone'})
ctxt = context.get_admin_context()
services = db.service_get_all(ctxt)
if zone:
@ -209,7 +208,9 @@ class HostCommands(object):
hosts.append(srv)
for h in hosts:
print("%-25s\t%-15s" % (h['host'], h['availability_zone']))
print(_("%(host)-25s\t%(availability_zone)-15s")
% {'host': h['host'],
'availability_zone': h['availability_zone']})
class DbCommands(object):
@ -256,14 +257,14 @@ class VolumeCommands(object):
host = volume['host']
if not host:
print("Volume not yet assigned to host.")
print("Deleting volume from database and skipping rpc.")
print(_("Volume not yet assigned to host."))
print(_("Deleting volume from database and skipping rpc."))
db.volume_destroy(ctxt, param2id(volume_id))
return
if volume['status'] == 'in-use':
print("Volume is in-use.")
print("Detach volume from instance and then try again.")
print(_("Volume is in-use."))
print(_("Detach volume from instance and then try again."))
return
rpc.cast(ctxt,
@ -281,7 +282,7 @@ class VolumeCommands(object):
ctxt = context.get_admin_context()
volume = db.volume_get(ctxt, param2id(volume_id))
if not volume['instance_id']:
print("volume is not attached to an instance")
print(_("volume is not attached to an instance"))
return
instance = db.instance_get(ctxt, volume['instance_id'])
host = instance['host']
@ -336,9 +337,10 @@ class GetLogCommands(object):
if print_name == 0:
print(log_file + ":-")
print_name = 1
print("Line %d : %s" % (len(lines) - index, line))
print(_("Line %(dis)d : %(line)s") %
{'dis': len(lines) - index, 'line': line})
if error_found == 0:
print("No errors in logfiles!")
print(_("No errors in logfiles!"))
@args('num_entries', nargs='?', type=int, default=10,
help='Number of entries to list (default: %(default)d)')
@ -352,20 +354,20 @@ class GetLogCommands(object):
elif os.path.exists('/var/log/messages'):
log_file = '/var/log/messages'
else:
print("Unable to find system log file!")
print(_("Unable to find system log file!"))
sys.exit(1)
lines = [line.strip() for line in open(log_file, "r")]
lines.reverse()
print("Last %s cinder syslog entries:-" % (entries))
print(_("Last %s cinder syslog entries:-") % (entries))
for line in lines:
if line.find("cinder") > 0:
count += 1
print("%s" % (line))
print(_("%s") % (line))
if count == entries:
break
if count == 0:
print("No cinder entries in syslog!")
print(_("No cinder entries in syslog!"))
class BackupCommands(object):
@ -514,7 +516,7 @@ def main():
print(script_name + " category action [<args>]")
print(_("Available categories:"))
for category in CATEGORIES:
print("\t%s" % category)
print(_("\t%s") % category)
sys.exit(2)
try:

View File

@ -57,7 +57,8 @@ def _subprocess_setup():
def _exit_error(execname, message, errorcode, log=True):
print("%s: %s" % (execname, message))
print(_("%(execname)s: %(message)s") %
{'execname': execname, 'message': message})
if log:
logging.error(message)
sys.exit(errorcode)
@ -86,7 +87,8 @@ if __name__ == '__main__':
rawconfig.read(configfile)
config = wrapper.RootwrapConfig(rawconfig)
except ValueError as exc:
msg = "Incorrect value in %s: %s" % (configfile, exc.message)
msg = (_("Incorrect value in %(configfile)s: %(message)s")
% {'configfile': configfile, 'message': exc.message})
_exit_error(execname, msg, RC_BADCONFIG, log=False)
except ConfigParser.Error:
_exit_error(execname, "Incorrect configuration file: %s" % configfile,
@ -120,11 +122,12 @@ if __name__ == '__main__':
sys.exit(obj.returncode)
except wrapper.FilterMatchNotExecutable as exc:
msg = ("Executable not found: %s (filter match = %s)"
% (exc.match.exec_path, exc.match.name))
msg = (_("Executable not found: %(exec_path)s "
"(filter match = %(name)s)")
% {'exec_path': exc.match.exec_path, 'name': exc.match.name})
_exit_error(execname, msg, RC_NOEXECFOUND, log=config.use_syslog)
except wrapper.NoFilterMatched:
msg = ("Unauthorized command: %s (no filter matched)"
msg = (_("Unauthorized command: %s (no filter matched)")
% ' '.join(userargs))
_exit_error(execname, msg, RC_UNAUTHORIZED, log=config.use_syslog)