mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	Fixed #14240 -- Enabled localization for the filesize filter. Thanks to David Danier for the report and patch.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15290 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
		| @@ -799,19 +799,21 @@ def filesizeformat(bytes): | ||||
|     try: | ||||
|         bytes = float(bytes) | ||||
|     except (TypeError,ValueError,UnicodeDecodeError): | ||||
|         return u"0 bytes" | ||||
|         return ungettext("%(size)d byte", "%(size)d bytes", 0) % {'size': 0} | ||||
|  | ||||
|     filesize_number_format = lambda value: formats.number_format(round(value, 1), 1) | ||||
|  | ||||
|     if bytes < 1024: | ||||
|         return ungettext("%(size)d byte", "%(size)d bytes", bytes) % {'size': bytes} | ||||
|     if bytes < 1024 * 1024: | ||||
|         return ugettext("%.1f KB") % (bytes / 1024) | ||||
|         return ugettext("%s KB") % filesize_number_format(bytes / 1024) | ||||
|     if bytes < 1024 * 1024 * 1024: | ||||
|         return ugettext("%.1f MB") % (bytes / (1024 * 1024)) | ||||
|         return ugettext("%s MB") % filesize_number_format(bytes / (1024 * 1024)) | ||||
|     if bytes < 1024 * 1024 * 1024 * 1024: | ||||
|         return ugettext("%.1f GB") % (bytes / (1024 * 1024 * 1024)) | ||||
|         return ugettext("%s GB") % filesize_number_format(bytes / (1024 * 1024 * 1024)) | ||||
|     if bytes < 1024 * 1024 * 1024 * 1024 * 1024: | ||||
|         return ugettext("%.1f TB") % (bytes / (1024 * 1024 * 1024 * 1024)) | ||||
|     return ugettext("%.1f PB") % (bytes / (1024 * 1024 * 1024 * 1024 * 1024)) | ||||
|         return ugettext("%s TB") % filesize_number_format(bytes / (1024 * 1024 * 1024 * 1024)) | ||||
|     return ugettext("%s PB") % filesize_number_format(bytes / (1024 * 1024 * 1024 * 1024 * 1024)) | ||||
| filesizeformat.is_safe = True | ||||
|  | ||||
| def pluralize(value, arg=u's'): | ||||
|   | ||||
		Reference in New Issue
	
	Block a user