mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-23 02:49:27 +01:00
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:
parent
6b1131bff9
commit
caf255afd9
@ -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):
|
||||
|
@ -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 ''
|
||||
|
Loading…
Reference in New Issue
Block a user