Internationalize string-handling functions in src/utils/.

This commit was supposed to be before the two previous ones, but I messed up with Git.
This commit is contained in:
Valentin Lorentz 2013-04-21 16:00:31 +02:00
parent 6b1131bff9
commit caf255afd9
2 changed files with 15 additions and 9 deletions

View File

@ -43,6 +43,9 @@ from file import mktemp
import crypt import crypt
from supybot.i18n import PluginInternationalization
_ = PluginInternationalization()
def abbrev(strings, d=None): def abbrev(strings, d=None):
"""Returns a dictionary mapping unambiguous abbreviations to full forms.""" """Returns a dictionary mapping unambiguous abbreviations to full forms."""
def eachSubstring(s): 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' hours or minutes or seconds, 'One flag must be True'
if years: if years:
(yrs, elapsed) = (elapsed // 31536000, elapsed % 31536000) (yrs, elapsed) = (elapsed // 31536000, elapsed % 31536000)
Format('year', yrs) Format(_('year'), yrs)
if weeks: if weeks:
(wks, elapsed) = (elapsed // 604800, elapsed % 604800) (wks, elapsed) = (elapsed // 604800, elapsed % 604800)
Format('week', wks) Format(_('week'), wks)
if days: if days:
(ds, elapsed) = (elapsed // 86400, elapsed % 86400) (ds, elapsed) = (elapsed // 86400, elapsed % 86400)
Format('day', ds) Format(_('day'), ds)
if hours: if hours:
(hrs, elapsed) = (elapsed // 3600, elapsed % 3600) (hrs, elapsed) = (elapsed // 3600, elapsed % 3600)
Format('hour', hrs) Format(_('hour'), hrs)
if minutes or seconds: if minutes or seconds:
(mins, secs) = (elapsed // 60, elapsed % 60) (mins, secs) = (elapsed // 60, elapsed % 60)
if leadingZeroes or mins: if leadingZeroes or mins:
Format('minute', mins) Format(_('minute'), mins)
if seconds: if seconds:
leadingZeroes = True leadingZeroes = True
Format('second', secs) Format(_('second'), secs)
if not ret: if not ret:
raise ValueError, 'Time difference not great enough to be noted.' raise ValueError, 'Time difference not great enough to be noted.'
result = '' result = ''
@ -119,7 +122,7 @@ def timeElapsed(elapsed, short=False, leadingZeroes=False, years=True,
else: else:
result = format('%L', ret) result = format('%L', ret)
if before: if before:
result += ' ago' result = _('%s ago') % result
return result return result
def findBinaryInPath(s): def findBinaryInPath(s):

View File

@ -42,7 +42,8 @@ from iter import all, any
from structures import TwoWayDictionary from structures import TwoWayDictionary
from supybot.i18n import PluginInternationalization from supybot.i18n import PluginInternationalization
internationalizeFunction=PluginInternationalization().internationalizeFunction _ = PluginInternationalization()
internationalizeFunction = _.internationalizeFunction
def rsplit(s, sep=None, maxsplit=-1): def rsplit(s, sep=None, maxsplit=-1):
"""Equivalent to str.split, except splitting from the right.""" """Equivalent to str.split, except splitting from the right."""
@ -246,11 +247,13 @@ def perlVariableSubstitute(vars, text):
return '$' + unbraced return '$' + unbraced
return _perlVarSubstituteRe.sub(replacer, text) 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. """Given a a sequence, returns an English clause for that sequence.
I.e., given [1, 2, 3], returns '1, 2, and 3' I.e., given [1, 2, 3], returns '1, 2, and 3'
""" """
if And is None:
And = _('and')
L = list(seq) L = list(seq)
if len(L) == 0: if len(L) == 0:
return '' return ''