Fixed #20246 -- Added non-breaking spaces between values an units

This commit is contained in:
Emil Stenström 2013-05-18 13:58:45 +02:00 committed by Claude Paroz
parent caf56ad174
commit 7d77e9786a
9 changed files with 155 additions and 130 deletions

View file

@ -194,17 +194,20 @@ def naturaltime(value):
return _('now')
elif delta.seconds < 60:
return ungettext(
'a second ago', '%(count)s seconds ago', delta.seconds
# Translators: \\u00a0 is non-breaking space
'a second ago', '%(count)s\u00a0seconds ago', delta.seconds
) % {'count': delta.seconds}
elif delta.seconds // 60 < 60:
count = delta.seconds // 60
return ungettext(
'a minute ago', '%(count)s minutes ago', count
# Translators: \\u00a0 is non-breaking space
'a minute ago', '%(count)s\u00a0minutes ago', count
) % {'count': count}
else:
count = delta.seconds // 60 // 60
return ungettext(
'an hour ago', '%(count)s hours ago', count
# Translators: \\u00a0 is non-breaking space
'an hour ago', '%(count)s\u00a0hours ago', count
) % {'count': count}
else:
delta = value - now
@ -216,15 +219,18 @@ def naturaltime(value):
return _('now')
elif delta.seconds < 60:
return ungettext(
'a second from now', '%(count)s seconds from now', delta.seconds
# Translators: \\u00a0 is non-breaking space
'a second from now', '%(count)s\u00a0seconds from now', delta.seconds
) % {'count': delta.seconds}
elif delta.seconds // 60 < 60:
count = delta.seconds // 60
return ungettext(
'a minute from now', '%(count)s minutes from now', count
# Translators: \\u00a0 is non-breaking space
'a minute from now', '%(count)s\u00a0minutes from now', count
) % {'count': count}
else:
count = delta.seconds // 60 // 60
return ungettext(
'an hour from now', '%(count)s hours from now', count
# Translators: \\u00a0 is non-breaking space
'an hour from now', '%(count)s\u00a0hours from now', count
) % {'count': count}

View file

@ -195,22 +195,22 @@ class HumanizeTests(TestCase):
result_list = [
'now',
'a second ago',
'30 seconds ago',
'30\xa0seconds ago',
'a minute ago',
'2 minutes ago',
'2\xa0minutes ago',
'an hour ago',
'23 hours ago',
'1 day ago',
'1 year, 4 months ago',
'23\xa0hours ago',
'1\xa0day ago',
'1\xa0year, 4\xa0months ago',
'a second from now',
'30 seconds from now',
'30\xa0seconds from now',
'a minute from now',
'2 minutes from now',
'2\xa0minutes from now',
'an hour from now',
'23 hours from now',
'1 day from now',
'2 days, 6 hours from now',
'1 year, 4 months from now',
'23\xa0hours from now',
'1\xa0day from now',
'2\xa0days, 6\xa0hours from now',
'1\xa0year, 4\xa0months from now',
'now',
'now',
]
@ -218,8 +218,8 @@ class HumanizeTests(TestCase):
# date in naive arithmetic is only 2 days and 5 hours after in
# aware arithmetic.
result_list_with_tz_support = result_list[:]
assert result_list_with_tz_support[-4] == '2 days, 6 hours from now'
result_list_with_tz_support[-4] == '2 days, 5 hours from now'
assert result_list_with_tz_support[-4] == '2\xa0days, 6\xa0hours from now'
result_list_with_tz_support[-4] == '2\xa0days, 5\xa0hours from now'
orig_humanize_datetime, humanize.datetime = humanize.datetime, MockDateTime
try: