humanize-0.5.1/0000775000175000017500000000000012431157636014523 5ustar jmoironjmoiron00000000000000humanize-0.5.1/setup.cfg0000664000175000017500000000015012431157636016340 0ustar jmoironjmoiron00000000000000[upload_docs] upload-dir = docs/_build/html [egg_info] tag_build = tag_date = 0 tag_svn_revision = 0 humanize-0.5.1/LICENCE0000664000175000017500000000206112145257311015500 0ustar jmoironjmoiron00000000000000Copyright (c) 2010 Jason Moiron and Contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. humanize-0.5.1/setup.py0000664000175000017500000000225612431157466016243 0ustar jmoironjmoiron00000000000000#!/usr/bin/env python # -*- coding: utf-8 -*- """Setup script for humanize.""" from setuptools import setup, find_packages import sys, os import io version = '0.5.1' # some trove classifiers: setup( name='humanize', version=version, description="python humanize utilities", long_description=io.open('README.rst', 'r', encoding="UTF-8").read(), # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers classifiers=[ 'Development Status :: 4 - Beta', 'Intended Audience :: Developers', 'License :: OSI Approved :: MIT License', 'Operating System :: POSIX', 'Programming Language :: Python :: 3', 'Programming Language :: Python', ], keywords='humanize time size', author='Jason Moiron', author_email='jmoiron@jmoiron.net', url='http://github.com/jmoiron/humanize', license='MIT', packages=find_packages(exclude=['ez_setup', 'examples', 'tests']), include_package_data=True, zip_safe=False, test_suite="tests", tests_require=['mock'], install_requires=[ # -*- Extra requirements: -*- ], entry_points=""" # -*- Entry points: -*- """, ) humanize-0.5.1/MANIFEST.in0000664000175000017500000000010712145257311016250 0ustar jmoironjmoiron00000000000000include README.rst include LICENCE recursive-include humanize/locale * humanize-0.5.1/humanize.egg-info/0000775000175000017500000000000012431157636020035 5ustar jmoironjmoiron00000000000000humanize-0.5.1/humanize.egg-info/top_level.txt0000664000175000017500000000001112431157636022557 0ustar jmoironjmoiron00000000000000humanize humanize-0.5.1/humanize.egg-info/not-zip-safe0000664000175000017500000000000112145257324022260 0ustar jmoironjmoiron00000000000000 humanize-0.5.1/humanize.egg-info/dependency_links.txt0000664000175000017500000000000112431157636024103 0ustar jmoironjmoiron00000000000000 humanize-0.5.1/humanize.egg-info/SOURCES.txt0000664000175000017500000000117112431157636021721 0ustar jmoironjmoiron00000000000000LICENCE MANIFEST.in README.rst setup.cfg setup.py humanize/__init__.py humanize/compat.py humanize/filesize.py humanize/i18n.py humanize/number.py humanize/time.py humanize.egg-info/PKG-INFO humanize.egg-info/SOURCES.txt humanize.egg-info/dependency_links.txt humanize.egg-info/entry_points.txt humanize.egg-info/not-zip-safe humanize.egg-info/top_level.txt humanize/locale/fr_FR/LC_MESSAGES/humanize.mo humanize/locale/fr_FR/LC_MESSAGES/humanize.po humanize/locale/ko_KR/LC_MESSAGES/humanize.mo humanize/locale/ko_KR/LC_MESSAGES/humanize.po humanize/locale/ru_RU/LC_MESSAGES/humanize.mo humanize/locale/ru_RU/LC_MESSAGES/humanize.pohumanize-0.5.1/humanize.egg-info/entry_points.txt0000664000175000017500000000004112431157636023326 0ustar jmoironjmoiron00000000000000 # -*- Entry points: -*- humanize-0.5.1/humanize.egg-info/PKG-INFO0000664000175000017500000001050412431157636021132 0ustar jmoironjmoiron00000000000000Metadata-Version: 1.1 Name: humanize Version: 0.5.1 Summary: python humanize utilities Home-page: http://github.com/jmoiron/humanize Author: Jason Moiron Author-email: jmoiron@jmoiron.net License: MIT Description: humanize -------- .. image:: https://secure.travis-ci.org/jmoiron/humanize.png?branch=master :target: http://travis-ci.org/jmoiron/humanize This modest package contains various common humanization utilities, like turning a number into a fuzzy human readable duration ('3 minutes ago') or into a human readable size or throughput. It works with python 2.7 and 3.3 and is localized to Russian, French, and Korean. usage ----- Integer humanization:: >>> import humanize >>> humanize.intcomma(12345) '12,345' >>> humanize.intword(123455913) '123.5 million' >>> humanize.intword(12345591313) '12.3 billion' >>> humanize.apnumber(4) 'four' >>> humanize.apnumber(41) '41' Date & time humanization:: >>> import datetime >>> humanize.naturalday(datetime.datetime.now()) 'today' >>> humanize.naturalday(datetime.datetime.now() - datetime.timedelta(days=1)) 'yesterday' >>> humanize.naturalday(datetime.date(2007, 6, 5)) 'Jun 05' >>> humanize.naturaldate(datetime.date(2007, 6, 5)) 'Jun 05 2007' >>> humanize.naturaltime(datetime.datetime.now() - datetime.timedelta(seconds=1)) 'a second ago' >>> humanize.naturaltime(datetime.datetime.now() - datetime.timedelta(seconds=3600)) 'an hour ago' Filesize humanization:: >>> humanize.naturalsize(1000000) '1.0 MB' >>> humanize.naturalsize(1000000, binary=True) '976.6 KiB' >>> humanize.naturalsize(1000000, gnu=True) '976.6K' Human readable floating point numbers:: >>> humanize.fractional(1/3) '1/3' >>> humanize.fractional(1.5) '1 1/2' >>> humanize.fractional(0.3) '3/10' >>> humanize.fractional(0.333) '1/3' >>> humanize.fractional(1) '1' Localization ------------ How to change locale in runtime :: >>> print humanize.naturaltime(datetime.timedelta(seconds=3)) 3 seconds ago >>> _t = humanize.i18n.activate('ru_RU') >>> print humanize.naturaltime(datetime.timedelta(seconds=3)) 3 секунды назад >>> humanize.i18n.deactivate() >>> print humanize.naturaltime(datetime.timedelta(seconds=3)) 3 seconds ago You can pass additional parameter *path* to :func:`activate` to specify a path to search locales in. :: >>> humanize.i18n.activate('pt_BR') IOError: [Errno 2] No translation file found for domain: 'humanize' >>> humanize.i18n.activate('pt_BR', path='path/to/my/portuguese/translation/') How to add new phrases to existing locale files :: $ xgettext -o humanize.pot -k'_' -k'N_' -k'P_:1c,2' -l python humanize/*.py # extract new phrases $ msgmerge -U humanize/locale/ru_RU/LC_MESSAGES/humanize.po humanize.pot # add them to locale files $ msgfmt --check -o humanize/locale/ru_RU/LC_MESSAGES/humanize{.po,.mo} # compile to binary .mo How to add new locale :: $ msginit -i humanize.pot -o humanize/locale//LC_MESSAGES/humanize.po --locale Where is locale abbreviation, eg 'en_GB', 'pt_BR' or just 'ru', 'fr' etc. Keywords: humanize time size Platform: UNKNOWN Classifier: Development Status :: 4 - Beta Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: MIT License Classifier: Operating System :: POSIX Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python humanize-0.5.1/humanize/0000775000175000017500000000000012431157636016343 5ustar jmoironjmoiron00000000000000humanize-0.5.1/humanize/filesize.py0000644000175000017500000000300312305011657020511 0ustar jmoironjmoiron00000000000000#!/usr/bin/env python # -*- coding: utf-8 -*- """Bits & Bytes related humanization.""" suffixes = { 'decimal': ('kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'), 'binary': ('KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB'), 'gnu': "KMGTPEZY", } def naturalsize(value, binary=False, gnu=False, format='%.1f'): """Format a number of byteslike a human readable filesize (eg. 10 kB). By default, decimal suffixes (kB, MB) are used. Passing binary=true will use binary suffixes (KiB, MiB) are used and the base will be 2**10 instead of 10**3. If ``gnu`` is True, the binary argument is ignored and GNU-style (ls -sh style) prefixes are used (K, M) with the 2**10 definition. Non-gnu modes are compatible with jinja2's ``filesizeformat`` filter.""" if gnu: suffix = suffixes['gnu'] elif binary: suffix = suffixes['binary'] else: suffix = suffixes['decimal'] base = 1024 if (gnu or binary) else 1000 bytes = float(value) if bytes == 1 and not gnu: return '1 Byte' elif bytes < base and not gnu: return '%d Bytes' % bytes elif bytes < base and gnu: return '%dB' % bytes for i,s in enumerate(suffix): unit = base ** (i+2) if bytes < unit and not gnu: return (format + ' %s') % ((base * bytes / unit), s) elif bytes < unit and gnu: return (format + '%s') % ((base * bytes / unit), s) if gnu: return (format + '%s') % ((base * bytes / unit), s) return (format + ' %s') % ((base * bytes / unit), s) humanize-0.5.1/humanize/__init__.py0000664000175000017500000000053212167315560020452 0ustar jmoironjmoiron00000000000000VERSION = (0,4) from humanize.time import * from humanize.number import * from humanize.filesize import * from humanize.i18n import activate, deactivate __all__ = ['VERSION', 'naturalday', 'naturaltime', 'ordinal', 'intword', 'naturaldelta', 'intcomma', 'apnumber', 'fractional', 'naturalsize', 'activate', 'deactivate', 'naturaldate'] humanize-0.5.1/humanize/time.py0000664000175000017500000001275512431157416017661 0ustar jmoironjmoiron00000000000000#!/usr/bin/env python # -*- coding: utf-8 -*- """Time humanizing functions. These are largely borrowed from Django's ``contrib.humanize``.""" import time from datetime import datetime, timedelta, date from .i18n import ngettext, gettext as _ __all__ = ['naturaldelta', 'naturaltime', 'naturalday', 'naturaldate'] def _now(): return datetime.now() def abs_timedelta(delta): """Returns an "absolute" value for a timedelta, always representing a time distance.""" if delta.days < 0: now = _now() return now - (now + delta) return delta def date_and_delta(value): """Turn a value into a date and a timedelta which represents how long ago it was. If that's not possible, return (None, value).""" now = _now() if isinstance(value, datetime): date = value delta = now - value elif isinstance(value, timedelta): date = now - value delta = value else: try: value = int(value) delta = timedelta(seconds=value) date = now - delta except (ValueError, TypeError): return (None, value) return date, abs_timedelta(delta) def naturaldelta(value, months=True): """Given a timedelta or a number of seconds, return a natural representation of the amount of time elapsed. This is similar to ``naturaltime``, but does not add tense to the result. If ``months`` is True, then a number of months (based on 30.5 days) will be used for fuzziness between years.""" now = _now() date, delta = date_and_delta(value) if date is None: return value use_months = months seconds = abs(delta.seconds) days = abs(delta.days) years = days // 365 days = days % 365 months = int(days // 30.5) if not years and days < 1: if seconds == 0: return _("a moment") elif seconds == 1: return _("a second") elif seconds < 60: return ngettext("%d second", "%d seconds", seconds) % seconds elif 60 <= seconds < 120: return _("a minute") elif 120 <= seconds < 3600: minutes = seconds // 60 return ngettext("%d minute", "%d minutes", minutes) % minutes elif 3600 <= seconds < 3600 * 2: return _("an hour") elif 3600 < seconds: hours = seconds // 3600 return ngettext("%d hour", "%d hours", hours) % hours elif years == 0: if days == 1: return _("a day") if not use_months: return ngettext("%d day", "%d days", days) % days else: if not months: return ngettext("%d day", "%d days", days) % days elif months == 1: return _("a month") else: return ngettext("%d month", "%d months", months) % months elif years == 1: if not months and not days: return _("a year") elif not months: return ngettext("1 year, %d day", "1 year, %d days", days) % days elif use_months: if months == 1: return _("1 year, 1 month") else: return ngettext("1 year, %d month", "1 year, %d months", months) % months else: return ngettext("1 year, %d day", "1 year, %d days", days) % days else: return ngettext("%d year", "%d years", years) % years def naturaltime(value, future=False, months=True): """Given a datetime or a number of seconds, return a natural representation of that time in a resolution that makes sense. This is more or less compatible with Django's ``naturaltime`` filter. ``future`` is ignored for datetimes, where the tense is always figured out based on the current time. If an integer is passed, the return value will be past tense by default, unless ``future`` is set to True.""" now = _now() date, delta = date_and_delta(value) if date is None: return value # determine tense by value only if datetime/timedelta were passed if isinstance(value, (datetime, timedelta)): future = date > now ago = _('%s from now') if future else _('%s ago') delta = naturaldelta(delta, months) if delta == _("a moment"): return _("now") return ago % delta def naturalday(value, format='%b %d'): """For date values that are tomorrow, today or yesterday compared to present day returns representing string. Otherwise, returns a string formatted according to ``format``.""" try: value = date(value.year, value.month, value.day) except AttributeError: # Passed value wasn't date-ish return value except (OverflowError, ValueError): # Date arguments out of range return value delta = value - date.today() if delta.days == 0: return _('today') elif delta.days == 1: return _('tomorrow') elif delta.days == -1: return _('yesterday') return value.strftime(format) def naturaldate(value): """Like naturalday, but will append a year for dates that are a year ago or more.""" try: value = date(value.year, value.month, value.day) except AttributeError: # Passed value wasn't date-ish return value except (OverflowError, ValueError): # Date arguments out of range return value delta = abs_timedelta(value - date.today()) if delta.days >= 365: return naturalday(value, '%b %d %Y') return naturalday(value) humanize-0.5.1/humanize/compat.py0000664000175000017500000000015212145257311020167 0ustar jmoironjmoiron00000000000000import sys if sys.version_info < (3,): string_types = (basestring,) else: string_types = (str,) humanize-0.5.1/humanize/i18n.py0000664000175000017500000000335312431157416017474 0ustar jmoironjmoiron00000000000000# -*- coding: utf-8 -*- import gettext as gettext_module from threading import local import os.path __all__ = ['activate', 'deactivate', 'gettext', 'ngettext'] _TRANSLATIONS = {None: gettext_module.NullTranslations()} _CURRENT = local() _DEFAULT_LOCALE_PATH = os.path.join(os.path.dirname(__file__), 'locale') def get_translation(): try: return _TRANSLATIONS[_CURRENT.locale] except (AttributeError, KeyError): return _TRANSLATIONS[None] def activate(locale, path=None): """Set 'locale' as current locale. Search for locale in directory 'path' @param locale: language name, eg 'en_GB'""" if path is None: path = _DEFAULT_LOCALE_PATH if locale not in _TRANSLATIONS: translation = gettext_module.translation('humanize', path, [locale]) _TRANSLATIONS[locale] = translation _CURRENT.locale = locale return _TRANSLATIONS[locale] def deactivate(): _CURRENT.locale = None def gettext(message): return get_translation().gettext(message) def pgettext(msgctxt, message): """'Particular gettext' function. It works with 'msgctxt' .po modifiers and allow duplicate keys with different translations. Python 2 don't have support for this GNU gettext function, so we reimplement it. It works by joining msgctx and msgid by '4' byte.""" key = msgctxt + '\x04' + message translation = get_translation().gettext(key) return message if translation == key else translation def ngettext(message, plural, num): return get_translation().ngettext(message, plural, num) def gettext_noop(message): """Example usage: CONSTANTS = [gettext_noop('first'), gettext_noop('second')] def num_name(n): return gettext(CONSTANTS[n])""" return message humanize-0.5.1/humanize/locale/0000775000175000017500000000000012431157636017602 5ustar jmoironjmoiron00000000000000humanize-0.5.1/humanize/locale/ko_KR/0000775000175000017500000000000012431157636020607 5ustar jmoironjmoiron00000000000000humanize-0.5.1/humanize/locale/ko_KR/LC_MESSAGES/0000775000175000017500000000000012431157636022374 5ustar jmoironjmoiron00000000000000humanize-0.5.1/humanize/locale/ko_KR/LC_MESSAGES/humanize.po0000664000175000017500000001104112431157416024545 0ustar jmoironjmoiron00000000000000# Korean (Korea) translations for humanize. # Copyright (C) 2013 # This file is distributed under the same license as the humanize project. # @youngrok, 2013. # msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2014-03-24 21:07+0400\n" "PO-Revision-Date: 2013-07-10 11:38+0900\n" "Last-Translator: @youngrok\n" "Language-Team: ko_KR \n" "Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" "Generated-By: Babel 0.9.6\n" "X-Generator: Poedit 1.5.7\n" #: humanize/number.py:20 #, fuzzy msgctxt "0" msgid "th" msgstr "번째" #: humanize/number.py:21 #, fuzzy msgctxt "1" msgid "st" msgstr "번째" #: humanize/number.py:22 #, fuzzy msgctxt "2" msgid "nd" msgstr "번째" #: humanize/number.py:23 #, fuzzy msgctxt "3" msgid "rd" msgstr "번째" #: humanize/number.py:24 #, fuzzy msgctxt "4" msgid "th" msgstr "번째" #: humanize/number.py:25 #, fuzzy msgctxt "5" msgid "th" msgstr "번째" #: humanize/number.py:26 #, fuzzy msgctxt "6" msgid "th" msgstr "번째" #: humanize/number.py:27 #, fuzzy msgctxt "7" msgid "th" msgstr "번째" #: humanize/number.py:28 #, fuzzy msgctxt "8" msgid "th" msgstr "번째" #: humanize/number.py:29 #, fuzzy msgctxt "9" msgid "th" msgstr "번째" #: humanize/number.py:55 msgid "million" msgstr "%(value)s million" #: humanize/number.py:55 msgid "billion" msgstr "milliard" #: humanize/number.py:55 #, fuzzy msgid "trillion" msgstr "%(value)s billion" #: humanize/number.py:55 #, fuzzy msgid "quadrillion" msgstr "%(value)s quadrillion" #: humanize/number.py:56 #, fuzzy msgid "quintillion" msgstr "%(value)s quintillion" #: humanize/number.py:56 #, fuzzy msgid "sextillion" msgstr "%(value)s sextillion" #: humanize/number.py:56 #, fuzzy msgid "septillion" msgstr "%(value)s septillion" #: humanize/number.py:57 #, fuzzy msgid "octillion" msgstr "%(value)s octillion" #: humanize/number.py:57 #, fuzzy msgid "nonillion" msgstr "%(value)s nonillion" #: humanize/number.py:57 #, fuzzy msgid "decillion" msgstr "%(value)s décillion" #: humanize/number.py:57 #, fuzzy msgid "googol" msgstr "%(value)s gogol" #: humanize/number.py:91 msgid "one" msgstr "하나" #: humanize/number.py:91 msgid "two" msgstr "둘" #: humanize/number.py:91 msgid "three" msgstr "셋" #: humanize/number.py:91 msgid "four" msgstr "넷" #: humanize/number.py:91 msgid "five" msgstr "다섯" #: humanize/number.py:91 msgid "six" msgstr "여섯" #: humanize/number.py:92 msgid "seven" msgstr "일곱" #: humanize/number.py:92 msgid "eight" msgstr "여덟" #: humanize/number.py:92 msgid "nine" msgstr "아홉" #: humanize/time.py:64 humanize/time.py:126 msgid "a moment" msgstr "잠깐" #: humanize/time.py:66 msgid "a second" msgstr "1초" #: humanize/time.py:68 #, python-format msgid "%d second" msgid_plural "%d seconds" msgstr[0] "%d초" msgstr[1] "%d초" #: humanize/time.py:70 msgid "a minute" msgstr "1분" #: humanize/time.py:73 #, python-format msgid "%d minute" msgid_plural "%d minutes" msgstr[0] "%d분" msgstr[1] "%d분" #: humanize/time.py:75 msgid "an hour" msgstr "1시간" #: humanize/time.py:78 #, python-format msgid "%d hour" msgid_plural "%d hours" msgstr[0] "%d heure" msgstr[1] "%d시간" #: humanize/time.py:81 msgid "a day" msgstr "하루" #: humanize/time.py:83 humanize/time.py:86 #, python-format msgid "%d day" msgid_plural "%d days" msgstr[0] "%d jour" msgstr[1] "%d일" #: humanize/time.py:88 msgid "a month" msgstr "한달" #: humanize/time.py:90 #, python-format msgid "%d month" msgid_plural "%d months" msgstr[0] "%d mois" msgstr[1] "%d개월" #: humanize/time.py:93 msgid "a year" msgstr "1년" #: humanize/time.py:95 humanize/time.py:103 #, python-format msgid "1 year, %d day" msgid_plural "1 year, %d days" msgstr[0] "1년 %d일" msgstr[1] "1년 %d일" #: humanize/time.py:98 msgid "1 year, 1 month" msgstr "1년, 1개월" #: humanize/time.py:100 #, python-format msgid "1 year, %d month" msgid_plural "1 year, %d months" msgstr[0] "1년, %d개월" msgstr[1] "1년, %d개월" #: humanize/time.py:105 #, python-format msgid "%d year" msgid_plural "%d years" msgstr[0] "%d 년" msgstr[1] "%d ans" #: humanize/time.py:123 #, python-format msgid "%s from now" msgstr "%s 후" #: humanize/time.py:123 #, python-format msgid "%s ago" msgstr "%s 전" #: humanize/time.py:127 msgid "now" msgstr "방금" #: humanize/time.py:145 msgid "today" msgstr "오늘" #: humanize/time.py:147 msgid "tomorrow" msgstr "내일" #: humanize/time.py:149 msgid "yesterday" msgstr "어제" humanize-0.5.1/humanize/locale/ko_KR/LC_MESSAGES/humanize.mo0000664000175000017500000000345212431157416024551 0ustar jmoironjmoiron00000000000000",/<.AVg nz" $)-17;AGP T^   ' 3AHOe  #!  "    %d day%d days%d hour%d hours%d minute%d minutes%d month%d months%d second%d seconds%d year%d years%s ago%s from now1 year, %d day1 year, %d days1 year, %d month1 year, %d months1 year, 1 montha daya minutea momenta montha seconda yearan hourbillioneightfivefourmillionninenowonesevensixthreetodaytomorrowtwoyesterdayProject-Id-Version: PROJECT VERSION Report-Msgid-Bugs-To: POT-Creation-Date: 2014-03-24 21:07+0400 PO-Revision-Date: 2013-07-10 11:38+0900 Last-Translator: @youngrok Language-Team: ko_KR Language: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Plural-Forms: nplurals=2; plural=(n > 1); Generated-By: Babel 0.9.6 X-Generator: Poedit 1.5.7 %d jour%d일%d heure%d시간%d분%d분%d mois%d개월%d초%d초%d 년%d ans%s 전%s 후1년 %d일1년 %d일1년, %d개월1년, %d개월1년, 1개월하루1분잠깐한달1초1년1시간milliard여덟다섯넷%(value)s million아홉방금하나일곱여섯셋오늘내일둘어제humanize-0.5.1/humanize/locale/ru_RU/0000775000175000017500000000000012431157636020636 5ustar jmoironjmoiron00000000000000humanize-0.5.1/humanize/locale/ru_RU/LC_MESSAGES/0000775000175000017500000000000012431157636022423 5ustar jmoironjmoiron00000000000000humanize-0.5.1/humanize/locale/ru_RU/LC_MESSAGES/humanize.po0000664000175000017500000001330212431157416024576 0ustar jmoironjmoiron00000000000000# Russian (Russia) translations for PROJECT. # Copyright (C) 2013 ORGANIZATION # This file is distributed under the same license as the PROJECT project. # FIRST AUTHOR , 2013. # msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2014-03-24 21:07+0400\n" "PO-Revision-Date: 2014-03-24 20:32+0300\n" "Last-Translator: Sergey Prokhorov \n" "Language-Team: ru_RU \n" "Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n" "%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n" "Generated-By: Babel 0.9.6\n" "X-Generator: Poedit 1.5.4\n" # в Django тут "ий" но на самом деле оба варианта работают плохо #: humanize/number.py:20 msgctxt "0" msgid "th" msgstr "ой" #: humanize/number.py:21 msgctxt "1" msgid "st" msgstr "ый" #: humanize/number.py:22 msgctxt "2" msgid "nd" msgstr "ой" #: humanize/number.py:23 msgctxt "3" msgid "rd" msgstr "ий" # в Django тут "ий" но на самом деле оба варианта работают плохо #: humanize/number.py:24 msgctxt "4" msgid "th" msgstr "ый" # в Django тут "ий" но на самом деле оба варианта работают плохо #: humanize/number.py:25 msgctxt "5" msgid "th" msgstr "ый" # в Django тут "ий" но на самом деле оба варианта работают плохо #: humanize/number.py:26 msgctxt "6" msgid "th" msgstr "ой" # в Django тут "ий" но на самом деле оба варианта работают плохо #: humanize/number.py:27 msgctxt "7" msgid "th" msgstr "ой" # в Django тут "ий" но на самом деле оба варианта работают плохо #: humanize/number.py:28 msgctxt "8" msgid "th" msgstr "ой" # в Django тут "ий" но на самом деле оба варианта работают плохо #: humanize/number.py:29 msgctxt "9" msgid "th" msgstr "ый" #: humanize/number.py:55 msgid "million" msgstr "миллиона" #: humanize/number.py:55 msgid "billion" msgstr "миллиарда" #: humanize/number.py:55 msgid "trillion" msgstr "триллиона" #: humanize/number.py:55 msgid "quadrillion" msgstr "квадриллиона" #: humanize/number.py:56 msgid "quintillion" msgstr "квинтиллиона" #: humanize/number.py:56 msgid "sextillion" msgstr "сикстиллиона" #: humanize/number.py:56 msgid "septillion" msgstr "септиллиона" #: humanize/number.py:57 msgid "octillion" msgstr "октиллиона" #: humanize/number.py:57 msgid "nonillion" msgstr "нониллиона" #: humanize/number.py:57 msgid "decillion" msgstr "децилиона" #: humanize/number.py:57 msgid "googol" msgstr "гогола" #: humanize/number.py:91 msgid "one" msgstr "один" #: humanize/number.py:91 msgid "two" msgstr "два" #: humanize/number.py:91 msgid "three" msgstr "три" #: humanize/number.py:91 msgid "four" msgstr "четыре" #: humanize/number.py:91 msgid "five" msgstr "пять" #: humanize/number.py:91 msgid "six" msgstr "шесть" #: humanize/number.py:92 msgid "seven" msgstr "семь" #: humanize/number.py:92 msgid "eight" msgstr "восемь" #: humanize/number.py:92 msgid "nine" msgstr "девять" #: humanize/time.py:64 humanize/time.py:126 msgid "a moment" msgstr "только что" #: humanize/time.py:66 msgid "a second" msgstr "секунду" #: humanize/time.py:68 #, python-format msgid "%d second" msgid_plural "%d seconds" msgstr[0] "%d секунда" msgstr[1] "%d секунды" msgstr[2] "%d секунд" #: humanize/time.py:70 msgid "a minute" msgstr "минуту" #: humanize/time.py:73 #, python-format msgid "%d minute" msgid_plural "%d minutes" msgstr[0] "%d минута" msgstr[1] "%d минуты" msgstr[2] "%d минут" #: humanize/time.py:75 msgid "an hour" msgstr "час" #: humanize/time.py:78 #, python-format msgid "%d hour" msgid_plural "%d hours" msgstr[0] "%d час" msgstr[1] "%d часа" msgstr[2] "%d часов" #: humanize/time.py:81 msgid "a day" msgstr "день" #: humanize/time.py:83 humanize/time.py:86 #, python-format msgid "%d day" msgid_plural "%d days" msgstr[0] "%d день" msgstr[1] "%d дня" msgstr[2] "%d дней" #: humanize/time.py:88 msgid "a month" msgstr "месяц" #: humanize/time.py:90 #, python-format msgid "%d month" msgid_plural "%d months" msgstr[0] "%d месяц" msgstr[1] "%d месяца" msgstr[2] "%d месяцев" #: humanize/time.py:93 msgid "a year" msgstr "год" #: humanize/time.py:95 humanize/time.py:103 #, python-format msgid "1 year, %d day" msgid_plural "1 year, %d days" msgstr[0] "1 год, %d день" msgstr[1] "1 год, %d дня" msgstr[2] "1 год, %d дней" #: humanize/time.py:98 msgid "1 year, 1 month" msgstr "1 год, 1 месяц" #: humanize/time.py:100 #, python-format msgid "1 year, %d month" msgid_plural "1 year, %d months" msgstr[0] "1 год, %d месяц" msgstr[1] "1 год, %d месяца" msgstr[2] "1 год, %d месяцев" #: humanize/time.py:105 #, python-format msgid "%d year" msgid_plural "%d years" msgstr[0] "%d год" msgstr[1] "%d года" msgstr[2] "%d лет" #: humanize/time.py:123 #, python-format msgid "%s from now" msgstr "через %s" #: humanize/time.py:123 #, python-format msgid "%s ago" msgstr "%s назад" #: humanize/time.py:127 msgid "now" msgstr "сейчас" #: humanize/time.py:145 msgid "today" msgstr "сегодня" #: humanize/time.py:147 msgid "tomorrow" msgstr "завтра" #: humanize/time.py:149 msgid "yesterday" msgstr "вчера" humanize-0.5.1/humanize/locale/ru_RU/LC_MESSAGES/humanize.mo0000664000175000017500000000601612431157416024577 0ustar jmoironjmoiron000000000000005Gl  "3Vfkpuz     $ 0; ALPV\en r|!_#-/3 7 W e s x ?} M  " ' , 1 6 ; @ E J S ` t          % 2 G P i         *  &45! )$%2+1"3./- (#0',%d day%d days%d hour%d hours%d minute%d minutes%d month%d months%d second%d seconds%d year%d years%s ago%s from now0th1st1 year, %d day1 year, %d days1 year, %d month1 year, %d months1 year, 1 month2nd3rd4th5th6th7th8th9tha daya minutea momenta montha seconda yearan hourbilliondecillioneightfivefourgoogolmillionninenonillionnowoctilliononequadrillionquintillionseptillionsevensextillionsixthreetodaytomorrowtrilliontwoyesterdayProject-Id-Version: PROJECT VERSION Report-Msgid-Bugs-To: POT-Creation-Date: 2014-03-24 20:26+0400 PO-Revision-Date: 2014-03-24 20:32+0300 Last-Translator: Sergey Prokhorov Language-Team: ru_RU MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2); Generated-By: Babel 0.9.6 X-Generator: Poedit 1.5.4 %d день%d дня%d дней%d час%d часа%d часов%d минута%d минуты%d минут%d месяц%d месяца%d месяцев%d секунда%d секунды%d секунд%d год%d года%d лет%s назадчерез %sойый1 год, %d день1 год, %d дня1 год, %d дней1 год, %d месяц1 год, %d месяца1 год, %d месяцев1 год, 1 месяцойийыйыйойойойыйденьминутутолько чтомесяцсекундугодчасмиллиардадецилионавосемьпятьчетырегоголамиллионадевятьнониллионасейчасоктиллионаодинквадриллионаквинтиллионасептиллионасемьсикстиллионашестьтрисегоднязавтратриллионадвавчераhumanize-0.5.1/humanize/locale/fr_FR/0000775000175000017500000000000012431157636020600 5ustar jmoironjmoiron00000000000000humanize-0.5.1/humanize/locale/fr_FR/LC_MESSAGES/0000775000175000017500000000000012431157636022365 5ustar jmoironjmoiron00000000000000humanize-0.5.1/humanize/locale/fr_FR/LC_MESSAGES/humanize.po0000664000175000017500000001115612431157416024545 0ustar jmoironjmoiron00000000000000# French (France) translations for PROJECT. # Copyright (C) 2013 ORGANIZATION # This file is distributed under the same license as the PROJECT project. # FIRST AUTHOR , 2013. # msgid "" msgstr "" "Project-Id-Version: PROJECT VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2014-03-24 21:07+0400\n" "PO-Revision-Date: 2013-06-22 08:52+0100\n" "Last-Translator: Olivier Cortès \n" "Language-Team: fr_FR \n" "Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=utf-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n > 1);\n" "Generated-By: Babel 0.9.6\n" "X-Generator: Poedit 1.5.5\n" #: humanize/number.py:20 #, fuzzy msgctxt "0" msgid "th" msgstr "e" #: humanize/number.py:21 #, fuzzy msgctxt "1" msgid "st" msgstr "er" #: humanize/number.py:22 #, fuzzy msgctxt "2" msgid "nd" msgstr "e" #: humanize/number.py:23 #, fuzzy msgctxt "3" msgid "rd" msgstr "e" #: humanize/number.py:24 #, fuzzy msgctxt "4" msgid "th" msgstr "e" #: humanize/number.py:25 #, fuzzy msgctxt "5" msgid "th" msgstr "e" #: humanize/number.py:26 #, fuzzy msgctxt "6" msgid "th" msgstr "e" #: humanize/number.py:27 #, fuzzy msgctxt "7" msgid "th" msgstr "e" #: humanize/number.py:28 #, fuzzy msgctxt "8" msgid "th" msgstr "e" #: humanize/number.py:29 #, fuzzy msgctxt "9" msgid "th" msgstr "e" #: humanize/number.py:55 #, fuzzy msgid "million" msgstr "%(value)s million" #: humanize/number.py:55 msgid "billion" msgstr "milliard" #: humanize/number.py:55 #, fuzzy msgid "trillion" msgstr "%(value)s billion" #: humanize/number.py:55 #, fuzzy msgid "quadrillion" msgstr "%(value)s quadrillion" #: humanize/number.py:56 #, fuzzy msgid "quintillion" msgstr "%(value)s quintillion" #: humanize/number.py:56 #, fuzzy msgid "sextillion" msgstr "%(value)s sextillion" #: humanize/number.py:56 #, fuzzy msgid "septillion" msgstr "%(value)s septillion" #: humanize/number.py:57 #, fuzzy msgid "octillion" msgstr "%(value)s octillion" #: humanize/number.py:57 #, fuzzy msgid "nonillion" msgstr "%(value)s nonillion" #: humanize/number.py:57 #, fuzzy msgid "decillion" msgstr "%(value)s décillion" #: humanize/number.py:57 #, fuzzy msgid "googol" msgstr "%(value)s gogol" #: humanize/number.py:91 msgid "one" msgstr "un" #: humanize/number.py:91 msgid "two" msgstr "deux" #: humanize/number.py:91 msgid "three" msgstr "trois" #: humanize/number.py:91 msgid "four" msgstr "quatre" #: humanize/number.py:91 msgid "five" msgstr "cinq" #: humanize/number.py:91 msgid "six" msgstr "six" #: humanize/number.py:92 msgid "seven" msgstr "sept" #: humanize/number.py:92 msgid "eight" msgstr "huit" #: humanize/number.py:92 msgid "nine" msgstr "neuf" #: humanize/time.py:64 humanize/time.py:126 msgid "a moment" msgstr "un moment" #: humanize/time.py:66 msgid "a second" msgstr "une seconde" #: humanize/time.py:68 #, python-format msgid "%d second" msgid_plural "%d seconds" msgstr[0] "%d seconde" msgstr[1] "%d secondes" #: humanize/time.py:70 msgid "a minute" msgstr "une minute" #: humanize/time.py:73 #, python-format msgid "%d minute" msgid_plural "%d minutes" msgstr[0] "%d minute" msgstr[1] "%d minutes" #: humanize/time.py:75 msgid "an hour" msgstr "une heure" #: humanize/time.py:78 #, python-format msgid "%d hour" msgid_plural "%d hours" msgstr[0] "%d heure" msgstr[1] "%d heures" #: humanize/time.py:81 msgid "a day" msgstr "un jour" #: humanize/time.py:83 humanize/time.py:86 #, python-format msgid "%d day" msgid_plural "%d days" msgstr[0] "%d jour" msgstr[1] "%d jours" #: humanize/time.py:88 msgid "a month" msgstr "un mois" #: humanize/time.py:90 #, python-format msgid "%d month" msgid_plural "%d months" msgstr[0] "%d mois" msgstr[1] "%d mois" #: humanize/time.py:93 msgid "a year" msgstr "un an" #: humanize/time.py:95 humanize/time.py:103 #, python-format msgid "1 year, %d day" msgid_plural "1 year, %d days" msgstr[0] "un an et %d jour" msgstr[1] "un an et %d jours" #: humanize/time.py:98 msgid "1 year, 1 month" msgstr "un an et un mois" #: humanize/time.py:100 #, python-format msgid "1 year, %d month" msgid_plural "1 year, %d months" msgstr[0] "un an et %d mois" msgstr[1] "un an et %d mois" #: humanize/time.py:105 #, python-format msgid "%d year" msgid_plural "%d years" msgstr[0] "%d an" msgstr[1] "%d ans" #: humanize/time.py:123 #, python-format msgid "%s from now" msgstr "dans %s" #: humanize/time.py:123 #, python-format msgid "%s ago" msgstr "il y a %s" #: humanize/time.py:127 msgid "now" msgstr "maintenant" #: humanize/time.py:145 msgid "today" msgstr "aujourd'hui" #: humanize/time.py:147 msgid "tomorrow" msgstr "demain" #: humanize/time.py:149 msgid "yesterday" msgstr "hier" humanize-0.5.1/humanize/locale/fr_FR/LC_MESSAGES/humanize.mo0000664000175000017500000000352512431157416024543 0ustar jmoironjmoiron00000000000000!$/, 1FW ^j" #)/8 <F / F S]"e!      &).2 8DKP !     %d day%d days%d hour%d hours%d minute%d minutes%d month%d months%d second%d seconds%d year%d years%s ago%s from now1 year, %d day1 year, %d days1 year, %d month1 year, %d months1 year, 1 montha daya minutea momenta montha seconda yearan hourbillioneightfivefourninenowonesevensixthreetodaytomorrowtwoyesterdayProject-Id-Version: PROJECT VERSION Report-Msgid-Bugs-To: POT-Creation-Date: 2014-03-24 21:07+0400 PO-Revision-Date: 2013-06-22 08:52+0100 Last-Translator: Olivier Cortès Language-Team: fr_FR Language: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Plural-Forms: nplurals=2; plural=(n > 1); Generated-By: Babel 0.9.6 X-Generator: Poedit 1.5.5 %d jour%d jours%d heure%d heures%d minute%d minutes%d mois%d mois%d seconde%d secondes%d an%d ansil y a %sdans %sun an et %d jourun an et %d joursun an et %d moisun an et %d moisun an et un moisun jourune minuteun momentun moisune secondeun anune heuremilliardhuitcinqquatreneufmaintenantunseptsixtroisaujourd'huidemaindeuxhierhumanize-0.5.1/humanize/number.py0000664000175000017500000001072712431157416020210 0ustar jmoironjmoiron00000000000000#!/usr/bin/env python # -*- coding: utf-8 -*- """Humanizing functions for numbers.""" import re from fractions import Fraction from .import compat from .i18n import gettext as _, gettext_noop as N_, pgettext as P_ def ordinal(value): """Converts an integer to its ordinal as a string. 1 is '1st', 2 is '2nd', 3 is '3rd', etc. Works for any integer or anything int() will turn into an integer. Anything other value will have nothing done to it.""" try: value = int(value) except (TypeError, ValueError): return value t = (P_('0', 'th'), P_('1', 'st'), P_('2', 'nd'), P_('3', 'rd'), P_('4', 'th'), P_('5', 'th'), P_('6', 'th'), P_('7', 'th'), P_('8', 'th'), P_('9', 'th')) if value % 100 in (11, 12, 13): # special case return "%d%s" % (value, t[0]) return '%d%s' % (value, t[value % 10]) def intcomma(value): """Converts an integer to a string containing commas every three digits. For example, 3000 becomes '3,000' and 45000 becomes '45,000'. To maintain some compatability with Django's intcomma, this function also accepts floats.""" try: if isinstance(value, compat.string_types): float(value.replace(',', '')) else: float(value) except (TypeError, ValueError): return value orig = str(value) new = re.sub("^(-?\d+)(\d{3})", '\g<1>,\g<2>', orig) if orig == new: return new else: return intcomma(new) powers = [10 ** x for x in (6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 100)] human_powers = (N_('million'), N_('billion'), N_('trillion'), N_('quadrillion'), N_('quintillion'), N_('sextillion'), N_('septillion'), N_('octillion'), N_('nonillion'), N_('decillion'), N_('googol')) def intword(value, format='%.1f'): """Converts a large integer to a friendly text representation. Works best for numbers over 1 million. For example, 1000000 becomes '1.0 million', 1200000 becomes '1.2 million' and '1200000000' becomes '1.2 billion'. Supports up to decillion (33 digits) and googol (100 digits). You can pass format to change the number of decimal or general format of the number portion. This function returns a string unless the value passed was unable to be coaxed into an int.""" try: value = int(value) except (TypeError, ValueError): return value if value < powers[0]: return str(value) for ordinal, power in enumerate(powers[1:], 1): if value < power: chopped = value / float(powers[ordinal - 1]) return (' '.join([format, _(human_powers[ordinal - 1])])) % chopped return str(value) def apnumber(value): """For numbers 1-9, returns the number spelled out. Otherwise, returns the number. This follows Associated Press style. This always returns a string unless the value was not int-able, unlike the Django filter.""" try: value = int(value) except (TypeError, ValueError): return value if not 0 < value < 10: return str(value) return (_('one'), _('two'), _('three'), _('four'), _('five'), _('six'), _('seven'), _('eight'), _('nine'))[value - 1] def fractional(value): ''' There will be some cases where one might not want to show ugly decimal places for floats and decimals. This function returns a human readable fractional number in form of fractions and mixed fractions. Pass in a string, or a number or a float, and this function returns a string representation of a fraction or whole number or a mixed fraction Examples: fractional(0.3) will return '1/3' fractional(1.3) will return '1 3/10' fractional(float(1/3)) will return '1/3' fractional(1) will return '1' This will always return a string. ''' try: number = float(value) except (TypeError, ValueError): return value wholeNumber = int(number) frac = Fraction(number - wholeNumber).limit_denominator(1000) numerator = frac._numerator denominator = frac._denominator if wholeNumber and not numerator and denominator == 1: return '%.0f' % wholeNumber # this means that an integer was passed in (or variants of that integer like 1.0000) elif not wholeNumber: return '%.0f/%.0f' % (numerator, denominator) else: return '%.0f %.0f/%.0f' % (wholeNumber, numerator, denominator) humanize-0.5.1/README.rst0000664000175000017500000000602312431157416016207 0ustar jmoironjmoiron00000000000000humanize -------- .. image:: https://secure.travis-ci.org/jmoiron/humanize.png?branch=master :target: http://travis-ci.org/jmoiron/humanize This modest package contains various common humanization utilities, like turning a number into a fuzzy human readable duration ('3 minutes ago') or into a human readable size or throughput. It works with python 2.7 and 3.3 and is localized to Russian, French, and Korean. usage ----- Integer humanization:: >>> import humanize >>> humanize.intcomma(12345) '12,345' >>> humanize.intword(123455913) '123.5 million' >>> humanize.intword(12345591313) '12.3 billion' >>> humanize.apnumber(4) 'four' >>> humanize.apnumber(41) '41' Date & time humanization:: >>> import datetime >>> humanize.naturalday(datetime.datetime.now()) 'today' >>> humanize.naturalday(datetime.datetime.now() - datetime.timedelta(days=1)) 'yesterday' >>> humanize.naturalday(datetime.date(2007, 6, 5)) 'Jun 05' >>> humanize.naturaldate(datetime.date(2007, 6, 5)) 'Jun 05 2007' >>> humanize.naturaltime(datetime.datetime.now() - datetime.timedelta(seconds=1)) 'a second ago' >>> humanize.naturaltime(datetime.datetime.now() - datetime.timedelta(seconds=3600)) 'an hour ago' Filesize humanization:: >>> humanize.naturalsize(1000000) '1.0 MB' >>> humanize.naturalsize(1000000, binary=True) '976.6 KiB' >>> humanize.naturalsize(1000000, gnu=True) '976.6K' Human readable floating point numbers:: >>> humanize.fractional(1/3) '1/3' >>> humanize.fractional(1.5) '1 1/2' >>> humanize.fractional(0.3) '3/10' >>> humanize.fractional(0.333) '1/3' >>> humanize.fractional(1) '1' Localization ------------ How to change locale in runtime :: >>> print humanize.naturaltime(datetime.timedelta(seconds=3)) 3 seconds ago >>> _t = humanize.i18n.activate('ru_RU') >>> print humanize.naturaltime(datetime.timedelta(seconds=3)) 3 секунды назад >>> humanize.i18n.deactivate() >>> print humanize.naturaltime(datetime.timedelta(seconds=3)) 3 seconds ago You can pass additional parameter *path* to :func:`activate` to specify a path to search locales in. :: >>> humanize.i18n.activate('pt_BR') IOError: [Errno 2] No translation file found for domain: 'humanize' >>> humanize.i18n.activate('pt_BR', path='path/to/my/portuguese/translation/') How to add new phrases to existing locale files :: $ xgettext -o humanize.pot -k'_' -k'N_' -k'P_:1c,2' -l python humanize/*.py # extract new phrases $ msgmerge -U humanize/locale/ru_RU/LC_MESSAGES/humanize.po humanize.pot # add them to locale files $ msgfmt --check -o humanize/locale/ru_RU/LC_MESSAGES/humanize{.po,.mo} # compile to binary .mo How to add new locale :: $ msginit -i humanize.pot -o humanize/locale//LC_MESSAGES/humanize.po --locale Where is locale abbreviation, eg 'en_GB', 'pt_BR' or just 'ru', 'fr' etc. humanize-0.5.1/PKG-INFO0000664000175000017500000001050412431157636015620 0ustar jmoironjmoiron00000000000000Metadata-Version: 1.1 Name: humanize Version: 0.5.1 Summary: python humanize utilities Home-page: http://github.com/jmoiron/humanize Author: Jason Moiron Author-email: jmoiron@jmoiron.net License: MIT Description: humanize -------- .. image:: https://secure.travis-ci.org/jmoiron/humanize.png?branch=master :target: http://travis-ci.org/jmoiron/humanize This modest package contains various common humanization utilities, like turning a number into a fuzzy human readable duration ('3 minutes ago') or into a human readable size or throughput. It works with python 2.7 and 3.3 and is localized to Russian, French, and Korean. usage ----- Integer humanization:: >>> import humanize >>> humanize.intcomma(12345) '12,345' >>> humanize.intword(123455913) '123.5 million' >>> humanize.intword(12345591313) '12.3 billion' >>> humanize.apnumber(4) 'four' >>> humanize.apnumber(41) '41' Date & time humanization:: >>> import datetime >>> humanize.naturalday(datetime.datetime.now()) 'today' >>> humanize.naturalday(datetime.datetime.now() - datetime.timedelta(days=1)) 'yesterday' >>> humanize.naturalday(datetime.date(2007, 6, 5)) 'Jun 05' >>> humanize.naturaldate(datetime.date(2007, 6, 5)) 'Jun 05 2007' >>> humanize.naturaltime(datetime.datetime.now() - datetime.timedelta(seconds=1)) 'a second ago' >>> humanize.naturaltime(datetime.datetime.now() - datetime.timedelta(seconds=3600)) 'an hour ago' Filesize humanization:: >>> humanize.naturalsize(1000000) '1.0 MB' >>> humanize.naturalsize(1000000, binary=True) '976.6 KiB' >>> humanize.naturalsize(1000000, gnu=True) '976.6K' Human readable floating point numbers:: >>> humanize.fractional(1/3) '1/3' >>> humanize.fractional(1.5) '1 1/2' >>> humanize.fractional(0.3) '3/10' >>> humanize.fractional(0.333) '1/3' >>> humanize.fractional(1) '1' Localization ------------ How to change locale in runtime :: >>> print humanize.naturaltime(datetime.timedelta(seconds=3)) 3 seconds ago >>> _t = humanize.i18n.activate('ru_RU') >>> print humanize.naturaltime(datetime.timedelta(seconds=3)) 3 секунды назад >>> humanize.i18n.deactivate() >>> print humanize.naturaltime(datetime.timedelta(seconds=3)) 3 seconds ago You can pass additional parameter *path* to :func:`activate` to specify a path to search locales in. :: >>> humanize.i18n.activate('pt_BR') IOError: [Errno 2] No translation file found for domain: 'humanize' >>> humanize.i18n.activate('pt_BR', path='path/to/my/portuguese/translation/') How to add new phrases to existing locale files :: $ xgettext -o humanize.pot -k'_' -k'N_' -k'P_:1c,2' -l python humanize/*.py # extract new phrases $ msgmerge -U humanize/locale/ru_RU/LC_MESSAGES/humanize.po humanize.pot # add them to locale files $ msgfmt --check -o humanize/locale/ru_RU/LC_MESSAGES/humanize{.po,.mo} # compile to binary .mo How to add new locale :: $ msginit -i humanize.pot -o humanize/locale//LC_MESSAGES/humanize.po --locale Where is locale abbreviation, eg 'en_GB', 'pt_BR' or just 'ru', 'fr' etc. Keywords: humanize time size Platform: UNKNOWN Classifier: Development Status :: 4 - Beta Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: MIT License Classifier: Operating System :: POSIX Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python