by
Changes to 4 files · Browse files at 0d5e347012e8 Showing diff from parent 5a8c15e64db4 9f9c5eb5cd35 Diff from another changeset...
@@ -164,14 +164,39 @@ l = l[7:]
msgctxt = ''
# Now we are in a msgid section, output previous section
- elif l.startswith('msgid'):
+ elif l.startswith('msgid') and not l.startswith('msgid_plural'):
+ if section == STR:
+ add(msgid, msgstr, fuzzy)
section = ID
l = l[5:]
msgid = msgstr = ''
+ is_plural = False
+ # This is a message with plural forms
+ elif l.startswith('msgid_plural'):
+ if section != ID:
+ print >> sys.stderr, 'msgid_plural not preceeded by msgid on %s:%d' %\
+ (infile, lno)
+ sys.exit(1)
+ l = l[12:]
+ msgid += '\0' # separator of singular and plural
+ is_plural = True
# Now we are in a msgstr section
elif l.startswith('msgstr'):
section = STR
- l = l[6:]
+ if l.startswith('msgstr['):
+ if not is_plural:
+ print >> sys.stderr, 'plural without msgid_plural on %s:%d' %\
+ (infile, lno)
+ sys.exit(1)
+ l = l.split(']', 1)[1]
+ if msgstr:
+ msgstr += '\0' # Separator of the various plural forms
+ else:
+ if is_plural:
+ print >> sys.stderr, 'indexed msgstr required for plural on %s:%d' %\
+ (infile, lno)
+ sys.exit(1)
+ l = l[6:]
# Skip empty lines
l = l.strip()
if not l:
|
@@ -155,7 +155,7 @@ elif item == 'age':
date = ctx.date()
if date:
- return hglib.age(date)
+ return hglib.age(date).decode('utf-8')
return None
elif item == 'rawbranch':
return ctx.branch() or None
|
@@ -108,7 +108,7 @@ 'Tags': self.gettags,
'Branch': self.getbranch,
'Filename': lambda ctx, gnode: gnode.extra[0],
- 'Age': lambda ctx, gnode: hglib.age(ctx.date()),
+ 'Age': lambda ctx, gnode: hglib.age(ctx.date()).decode('utf-8'),
'LocalTime':lambda ctx, gnode: hglib.displaytime(ctx.date()),
'UTCTime': lambda ctx, gnode: hglib.utctime(ctx.date()),
'Changes': self.getchanges,
|
@@ -25,6 +25,7 @@
from tortoisehg.util import paths
from tortoisehg.util.hgversion import hgversion
+from tortoisehg.util.i18n import _, ngettext
def tounicode(s):
"""
@@ -275,7 +276,6 @@ Returns the dict {name: message} of extensions expected to be disabled.
message is 'utf-8'-encoded string.
"""
- from tortoisehg.util.i18n import _ # avoid cyclic dependency
exts = {}
if os.name != 'posix':
exts['inotify'] = _('inotify is not supported on this platform')
@@ -476,8 +476,33 @@def utctime(date):
return time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(date[0]))
+agescales = [((lambda n: ngettext("%d year", "%d years", n)), 3600 * 24 * 365),
+ ((lambda n: ngettext("%d month", "%d months", n)), 3600 * 24 * 30),
+ ((lambda n: ngettext("%d week", "%d weeks", n)), 3600 * 24 * 7),
+ ((lambda n: ngettext("%d day", "%d days", n)), 3600 * 24),
+ ((lambda n: ngettext("%d hour", "%d hours", n)), 3600),
+ ((lambda n: ngettext("%d minute", "%d minutes", n)), 60),
+ ((lambda n: ngettext("%d second", "%d seconds", n)), 1)]
+
def age(date):
- return templatefilters.age(date)
+ '''turn a (timestamp, tzoff) tuple into an age string.'''
+ # This is i18n-ed version of mercurial.templatefilters.age().
+
+ now = time.time()
+ then = date[0]
+ if then > now:
+ return _('in the future')
+
+ delta = int(now - then)
+ if delta == 0:
+ return _('now')
+ if delta > agescales[0][1] * 2:
+ return util.shortdate(date)
+
+ for t, s in agescales:
+ n = delta // s
+ if n >= 2 or s == 1:
+ return _('%s ago') % (t(n) % n)
def username(user):
author = templatefilters.person(user)
|
Loading...