From caf255afd9268178e9a18842699668a812f6710d Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Sun, 21 Apr 2013 16:00:31 +0200 Subject: [PATCH] Internationalize string-handling functions in src/utils/. This commit was supposed to be before the two previous ones, but I messed up with Git. --- src/utils/gen.py | 17 ++++++++++------- src/utils/str.py | 7 +++++-- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/utils/gen.py b/src/utils/gen.py index 330aaf53d..4a4c92f00 100644 --- a/src/utils/gen.py +++ b/src/utils/gen.py @@ -43,6 +43,9 @@ from file import mktemp import crypt +from supybot.i18n import PluginInternationalization +_ = PluginInternationalization() + def abbrev(strings, d=None): """Returns a dictionary mapping unambiguous abbreviations to full forms.""" def eachSubstring(s): @@ -94,23 +97,23 @@ def timeElapsed(elapsed, short=False, leadingZeroes=False, years=True, hours or minutes or seconds, 'One flag must be True' if years: (yrs, elapsed) = (elapsed // 31536000, elapsed % 31536000) - Format('year', yrs) + Format(_('year'), yrs) if weeks: (wks, elapsed) = (elapsed // 604800, elapsed % 604800) - Format('week', wks) + Format(_('week'), wks) if days: (ds, elapsed) = (elapsed // 86400, elapsed % 86400) - Format('day', ds) + Format(_('day'), ds) if hours: (hrs, elapsed) = (elapsed // 3600, elapsed % 3600) - Format('hour', hrs) + Format(_('hour'), hrs) if minutes or seconds: (mins, secs) = (elapsed // 60, elapsed % 60) if leadingZeroes or mins: - Format('minute', mins) + Format(_('minute'), mins) if seconds: leadingZeroes = True - Format('second', secs) + Format(_('second'), secs) if not ret: raise ValueError, 'Time difference not great enough to be noted.' result = '' @@ -119,7 +122,7 @@ def timeElapsed(elapsed, short=False, leadingZeroes=False, years=True, else: result = format('%L', ret) if before: - result += ' ago' + result = _('%s ago') % result return result def findBinaryInPath(s): diff --git a/src/utils/str.py b/src/utils/str.py index cc04f4b6c..e411eacf0 100644 --- a/src/utils/str.py +++ b/src/utils/str.py @@ -42,7 +42,8 @@ from iter import all, any from structures import TwoWayDictionary from supybot.i18n import PluginInternationalization -internationalizeFunction=PluginInternationalization().internationalizeFunction +_ = PluginInternationalization() +internationalizeFunction = _.internationalizeFunction def rsplit(s, sep=None, maxsplit=-1): """Equivalent to str.split, except splitting from the right.""" @@ -246,11 +247,13 @@ def perlVariableSubstitute(vars, text): return '$' + unbraced return _perlVarSubstituteRe.sub(replacer, text) -def commaAndify(seq, comma=',', And='and'): +def commaAndify(seq, comma=',', And=None): """Given a a sequence, returns an English clause for that sequence. I.e., given [1, 2, 3], returns '1, 2, and 3' """ + if And is None: + And = _('and') L = list(seq) if len(L) == 0: return ''