use dictionaries for translations with multiple arguments

git-svn-id: https://linkchecker.svn.sourceforge.net/svnroot/linkchecker/trunk/linkchecker@3460 e7d03fd6-7b0d-0410-9947-9c21f3af8025
This commit is contained in:
calvin 2006-09-16 09:12:59 +00:00
parent 6741ca5c7f
commit 5ad59225a0
13 changed files with 87 additions and 71 deletions

View file

@ -146,9 +146,10 @@ class FileUrl (urlbase.UrlBase):
path = self.get_os_filename()
realpath = get_nt_filename(path)
if path != realpath:
self.add_warning(_("The URL path %r is not the same as the "
"system path %r. You should always use "
"the system path in URLs.") % (path, realpath),
self.add_warning(_("The URL path %(path)r is not the same as the "
"system path %(realpath)r. You should always use "
"the system path in URLs.") % \
{"path": path, "realpath": realpath},
tag="file-system-path")
def get_content (self):

View file

@ -309,9 +309,10 @@ class UrlBase (object):
# norm base url - can raise UnicodeError from url.idna_encode()
base_url, is_idn = url_norm(self.base_url)
if is_idn:
self.add_warning(_("""URL %r has a unicode domain name which
self.add_warning(_("""URL %(url)r has a unicode domain name which
is not yet widely supported. You should use
the URL %r instead.""") % (self.base_url, base_url),
the URL %(idna_url)r instead.""") % \
{"url": self.base_url, "idna_url": base_url},
tag="url-unicode-domain")
elif self.base_url != base_url:
self.add_warning(
@ -620,9 +621,10 @@ class UrlBase (object):
"""
maxbytes = self.aggregate.config["warnsizebytes"]
if maxbytes is not None and self.dlsize >= maxbytes:
self.add_warning(_("Content size %s is larger than %s.") %
(linkcheck.strformat.strsize(self.dlsize),
linkcheck.strformat.strsize(maxbytes)),
self.add_warning(
_("Content size %(dlsize)s is larger than %(maxbytes)s.") %
{"dlsize": linkcheck.strformat.strsize(self.dlsize),
"maxbytes": linkcheck.strformat.strsize(maxbytes)},
tag="url-content-too-large")
def parse_url (self):

View file

@ -148,7 +148,8 @@ class LCConfigParser (ConfigParser.RawConfigParser, object):
self.config["warningregex"] = re.compile(arg)
except re.error, msg:
raise linkcheck.LinkCheckerError(linkcheck.LOG_CHECK,
_("syntax error in warningregex %r: %s\n"), arg, msg)
_("syntax error in warningregex %(regex)r: %(msg)s\n") % \
{"regex": arg, "msg": msg})
except ConfigParser.Error, msg:
assert None == linkcheck.log.debug(linkcheck.LOG_CHECK, msg)
try:
@ -173,7 +174,8 @@ class LCConfigParser (ConfigParser.RawConfigParser, object):
arg = re.compile(arg)
except re.error, msg:
raise linkcheck.LinkCheckerError(linkcheck.LOG_CHECK,
_("syntax error in noproxyfor%d %r: %s"), i, arg, msg)
_("syntax error in noproxyfor%(num)d %(arg)r: %(msg)s") % \
["num": i, "arg": arg, "msg": msg})
self.config["noproxyfor"].append(arg)
i += 1
except ConfigParser.Error, msg:
@ -199,7 +201,8 @@ class LCConfigParser (ConfigParser.RawConfigParser, object):
auth[0] = re.compile(auth[0])
except re.error, msg:
raise linkcheck.LinkCheckerError(linkcheck.LOG_CHECK,
_("syntax error in entry%d %r: %s"), i, auth[0], msg)
_("syntax error in entry%(num)d %(arg)r: %(msg)s") % \
{"num": i, "arg": auth[0], "msg": msg})
self.config["authentication"].insert(0, {'pattern': auth[0],
'user': auth[1],
'password': auth[2]})

View file

@ -62,7 +62,8 @@ def print_app_info ():
"""
print >> stderr, _("System info:")
print >> stderr, linkcheck.configuration.App
print >> stderr, _("Python %s on %s") % (sys.version, sys.platform)
print >> stderr, _("Python %(version)s on %(platform)s") % \
{"version": sys.version, "platform": sys.platform}
for key in ("LC_ALL", "LC_MESSAGES", "http_proxy", "ftp_proxy"):
value = os.getenv(key)
if value is not None:

View file

@ -56,9 +56,9 @@ class CSVLogger (linkcheck.logger.Logger):
self.starttime = time.time()
row = []
if self.has_part("intro"):
self.comment(_("created by %s at %s") %
(linkcheck.configuration.AppName,
linkcheck.strformat.strtime(self.starttime)))
self.comment(_("created by %(app)s at %(time)s") %
{"app": linkcheck.configuration.AppName,
"time": linkcheck.strformat.strtime(self.starttime}))
self.comment(_("Get the newest version at %(url)s") %
{'url': linkcheck.configuration.Url})
self.comment(_("Write comments and bugs to %(email)s") %
@ -119,7 +119,7 @@ class CSVLogger (linkcheck.logger.Logger):
self.stoptime = time.time()
if self.has_part("outro"):
duration = self.stoptime - self.starttime
self.comment(_("Stopped checking at %s (%s)") %
(linkcheck.strformat.strtime(self.stoptime),
linkcheck.strformat.strduration_long(duration)))
self.comment(_("Stopped checking at %(time)s (%(duration)s)") %
{"time": linkcheck.strformat.strtime(self.stoptime),
"duration": linkcheck.strformat.strduration_long(duration)})
self.close_fileoutput()

View file

@ -45,9 +45,9 @@ class DOTLogger (linkcheck.logger.Logger):
super(DOTLogger, self).start_output()
self.starttime = time.time()
if self.has_part("intro"):
self.comment(_("created by %s at %s") %
(linkcheck.configuration.AppName,
linkcheck.strformat.strtime(self.starttime)))
self.comment(_("created by %(app)s at %(time)s") %
{"app": linkcheck.configuration.AppName,
"time": linkcheck.strformat.strtime(self.starttime}))
self.comment(_("Get the newest version at %(url)s") %
{'url': linkcheck.configuration.Url})
self.comment(_("Write comments and bugs to %(email)s") %
@ -111,9 +111,9 @@ class DOTLogger (linkcheck.logger.Logger):
if self.has_part("outro"):
self.stoptime = time.time()
duration = self.stoptime - self.starttime
self.comment(_("Stopped checking at %s (%s)") %
(linkcheck.strformat.strtime(self.stoptime),
linkcheck.strformat.strduration_long(duration)))
self.comment(_("Stopped checking at %(time)s (%(duration)s)") %
{"time": linkcheck.strformat.strtime(self.stoptime),
"duration": linkcheck.strformat.strduration_long(duration)})
self.close_fileoutput()

View file

@ -45,9 +45,9 @@ class GMLLogger (linkcheck.logger.Logger):
super(GMLLogger, self).start_output()
self.starttime = time.time()
if self.has_part("intro"):
self.comment(_("created by %s at %s") %
(linkcheck.configuration.AppName,
linkcheck.strformat.strtime(self.starttime)))
self.comment(_("created by %(app)s at %(time)s") %
{"app": linkcheck.configuration.AppName,
"time": linkcheck.strformat.strtime(self.starttime}))
self.comment(_("Get the newest version at %(url)s") %
{'url': linkcheck.configuration.Url})
self.comment(_("Write comments and bugs to %(email)s") %
@ -115,7 +115,7 @@ class GMLLogger (linkcheck.logger.Logger):
if self.has_part("outro"):
self.stoptime = time.time()
duration = self.stoptime - self.starttime
self.comment(_("Stopped checking at %s (%s)") %
(linkcheck.strformat.strtime(self.stoptime),
linkcheck.strformat.strduration_long(duration)))
self.comment(_("Stopped checking at %(time)s (%(duration)s)") %
{"time": linkcheck.strformat.strtime(self.stoptime),
"duration": linkcheck.strformat.strduration_long(duration)})
self.close_fileoutput()

View file

@ -291,9 +291,9 @@ class HtmlLogger (linkcheck.logger.Logger):
self.writeln(u"<br>")
self.stoptime = time.time()
duration = self.stoptime - self.starttime
self.writeln(_("Stopped checking at %s (%s)") %
(linkcheck.strformat.strtime(self.stoptime),
linkcheck.strformat.strduration_long(duration)))
self.writeln(_("Stopped checking at %(time)s (%(duration)s)") %
{"time": linkcheck.strformat.strtime(self.stoptime),
"duration": linkcheck.strformat.strduration_long(duration)})
self.writeln(u'</blockquote><br><hr noshade size="1"><small>'+
linkcheck.configuration.HtmlAppInfo+u"<br>")
self.writeln(_("Get the newest version at %s") %

View file

@ -77,9 +77,9 @@ class SQLLogger (linkcheck.logger.Logger):
linkcheck.logger.Logger.start_output(self)
self.starttime = time.time()
if self.has_part("intro"):
self.comment(_("created by %s at %s") %
(linkcheck.configuration.AppName,
linkcheck.strformat.strtime(self.starttime)))
self.comment(_("created by %(app)s at %(time)s") %
{"app": linkcheck.configuration.AppName,
"time": linkcheck.strformat.strtime(self.starttime}))
self.comment(_("Get the newest version at %s") %
linkcheck.configuration.Url)
self.comment(_("Write comments and bugs to %s") %
@ -142,7 +142,7 @@ class SQLLogger (linkcheck.logger.Logger):
if self.has_part("outro"):
self.stoptime = time.time()
duration = self.stoptime - self.starttime
self.comment(_("Stopped checking at %s (%s)") %
(linkcheck.strformat.strtime(self.stoptime),
linkcheck.strformat.strduration_long(duration)))
self.comment(_("Stopped checking at %(time)s (%(duration)s)") %
{"time": linkcheck.strformat.strtime(self.stoptime),
"duration": linkcheck.strformat.strduration_long(duration)})
self.close_fileoutput()

View file

@ -98,10 +98,10 @@ class TextLogger (linkcheck.logger.Logger):
if self.has_part('intro'):
self.writeln(linkcheck.configuration.AppInfo)
self.writeln(linkcheck.configuration.Freeware)
self.writeln(_("Get the newest version at %s") %
linkcheck.configuration.Url)
self.writeln(_("Write comments and bugs to %s") %
linkcheck.configuration.Email)
self.writeln(_("Get the newest version at %(url)s") %
{'url': linkcheck.configuration.Url})
self.writeln(_("Write comments and bugs to %(email)s") %
{'email': linkcheck.configuration.Email})
self.check_date()
self.writeln()
self.writeln(_("Start checking at %s") %
@ -252,7 +252,7 @@ class TextLogger (linkcheck.logger.Logger):
self.errors) % self.errors)
self.stoptime = time.time()
duration = self.stoptime - self.starttime
self.writeln(_("Stopped checking at %s (%s)") %
(linkcheck.strformat.strtime(self.stoptime),
linkcheck.strformat.strduration_long(duration)))
self.writeln(_("Stopped checking at %(time)s (%(duration)s)") %
{"time": linkcheck.strformat.strtime(self.stoptime),
"duration": linkcheck.strformat.strduration_long(duration)})
self.close_fileoutput()

View file

@ -79,13 +79,13 @@ class XMLLogger (linkcheck.logger.Logger):
self.writeln(u'<?xml version="%s" encoding="%s"?>' %
(xmlquoteattr(version), xmlquoteattr(encoding)))
if self.has_part("intro"):
self.comment(_("created by %s at %s") %
(linkcheck.configuration.AppName,
linkcheck.strformat.strtime(self.starttime)))
self.comment(_("Get the newest version at %s") %
linkcheck.configuration.Url)
self.comment(_("Write comments and bugs to %s") %
linkcheck.configuration.Email)
self.comment(_("created by %(app)s at %(time)s") %
{"app": linkcheck.configuration.AppName,
"time": linkcheck.strformat.strtime(self.starttime}))
self.comment(_("Get the newest version at %(url)s") %
{'url': linkcheck.configuration.Url})
self.comment(_("Write comments and bugs to %(email)s") %
{'email': linkcheck.configuration.Email})
self.check_date()
self.writeln()
@ -96,9 +96,9 @@ class XMLLogger (linkcheck.logger.Logger):
if self.has_part("outro"):
self.stoptime = time.time()
duration = self.stoptime - self.starttime
self.comment(_("Stopped checking at %s (%s)") %
(linkcheck.strformat.strtime(self.stoptime),
linkcheck.strformat.strduration_long(duration)))
self.comment(_("Stopped checking at %(time)s (%(duration)s)") %
{"time": linkcheck.strformat.strtime(self.stoptime),
"duration": linkcheck.strformat.strduration_long(duration)})
def xml_starttag (self, name, attrs=None):
"""

View file

@ -251,7 +251,8 @@ def strduration_long (duration):
else:
prefix = ""
if duration < 1:
return _("%s%.02f seconds") % (prefix, duration)
return _("%(prefix)s%(duration).02f seconds") % \
{"prefix": prefix, "duration": duration}
# translation dummies
_n("%d second", "%d seconds", 1)
_n("%d minute", "%d minutes", 1)

View file

@ -238,7 +238,7 @@ def try_compile_re (arg):
return re.compile(arg)
except re.error, msg:
linkcheck.log.error(linkcheck.LOG_CMDLINE,
_("Syntax error in %r: %s", arg, msg))
_("Syntax error in %(arg)r: %(msg)s") % {"arg": arg, "msg": msg})
sys.exit(1)
@ -522,7 +522,8 @@ if options.debug:
print_usage(_("Invalid debug level %(level)r") % {'level': _name})
config.init_logging(debug=options.debug)
assert None == linkcheck.log.debug(linkcheck.LOG_CMDLINE,
_("Python %s on %s"), sys.version, sys.platform)
_("Python %(version)s on %(platform)s") % \
{"version": sys.version, "platform": sys.platform})
# read configuration files
try:
files = []
@ -570,11 +571,14 @@ if options.output:
else:
logtype, encoding = options.output, linkcheck.i18n.default_encoding
if not linkcheck.Loggers.has_key(logtype.lower()):
print_usage(_("Unknown logger type %r in %r for option %s") % \
(logtype, options.output, "'-o, --output'"))
print_usage(
_("Unknown logger type %(type)r in %(output)r for option %(option)s") % \
{"type": logtype, "output": options.output, "option": "'-o, --output'"})
if logtype != 'none' and not has_encoding(encoding):
print_usage(_("Unknown encoding %r in %r for option %s") % \
(encoding, options.output, "'-o, --output'"))
print_usage(
_("Unknown encoding %(encoding)r in %(output)r for option %(option)s") % \
{"encoding": encoding, "output": options.output,
"option": "'-o, --output'"})
config['logger'] = config.logger_new(logtype.lower(), encoding=encoding)
if options.fileoutput:
ns = {'fileoutput': 1}
@ -598,12 +602,16 @@ if options.fileoutput:
else:
ns['filename'] = suffix
if not linkcheck.Loggers.has_key(ftype):
print_usage(_("Unknown logger type %r in %r for option %s") % \
(ftype, options.output, "'-F, --file-output'"))
print_usage(
_("Unknown logger type %(type)r in %(output)r for option %(option)s") % \
{"type": ftype, "output": options.output,
"option": "'-F, --file-output'"})
if ftype != 'none' and 'encoding' in ns and \
not has_encoding(ns['encoding']):
print_usage(_("Unknown encoding %r in %r for option %s") % \
ns['encoding'], options.output, "'-F, --file-output'")
print_usage(
_("Unknown encoding %(encoding)r in %(output)r for option %(option)s") % \
{"encoding": ns['encoding'], "output": options.output,
"option": "'-F, --file-output'"})
logger = config.logger_new(ftype, **ns)
config['fileoutput'].append(logger)
if options.interactive is not None:
@ -619,8 +627,8 @@ if options.pause is not None:
if options.pause >= 0:
config["wait"] = options.pause
else:
print_usage(_("Illegal argument %r for option %s") % \
(options.pause, "'-P, --pause'"))
print_usage(_("Illegal argument %(arg)r for option %(option)s") % \
{"arg": options.pause, "option": "'-P, --pause'"})
if options.profile is not None:
do_profile = options.profile
if options.quiet is not None:
@ -637,8 +645,8 @@ if options.timeout is not None:
if options.timeout > 0:
config["timeout"] = options.timeout
else:
print_usage(_("Illegal argument %r for option %s") % \
(options.timeout, "'--timeout'"))
print_usage(_("Illegal argument %(arg)r for option %(option)s") % \
{"arg": options.timeout, "option": "'--timeout'"})
socket.setdefaulttimeout(config["timeout"])
if options.username is not None:
_username = options.username