Translating file size

Bonjour,

For the record the library http://babel.pocoo.org/en/latest/api/units.html can be used to implement a localized version of the filesizeformat jinja filter like so:

def filesizeformat(value):
    prefixes = [
        'digital-kilobyte',
        'digital-megabyte',
        'digital-gigabyte',
        'digital-terabyte',
    ]
    locale = get_locale()
    base = 1024
    #
    # we are using the long length because the short length has no
    # plural variant and it reads like a bug instead of something
    # on purpose
    #
    if value < base:
        return units.format_unit(value, "byte", locale=locale, length="long")
    else:
        i = min(int(math.log(value, base)), len(prefixes)) - 1
        prefix = prefixes[i]
        bytes = float(value) / base ** (i + 1)
        return units.format_unit(bytes, prefix, locale=locale, length="short")