def ungettext(singular, plural, number):
    return plural if number > 1 else singular

def ugettext(s):
    return s

def pgettext(context, message):
    return ugettext(message)

try:
    unicode
except NameError:
    unicode = str

ugettext_lazy = lazy(ugettext, unicode)
pgettext_lazy = lazy(pgettext, unicode)

def to_locale(language, to_lower=False):
    """
    Copied from Django 1.4.
    Copyright (c) Django Software Foundation and individual contributors. All rights reserved.

    Turns a language name (en-us) into a locale name (en_US). If 'to_lower' is
    True, the last component is lower-cased (en_us).
    """
    p = language.find('-')
    if p >= 0:
        if to_lower:
            return language[:p].lower()+'_'+language[p+1:].lower()
        else:
示例#2
0
            lang = get_language()
        cache_key = (format_type, lang)
        try:
            return _format_cache[cache_key] or getattr(settings, format_type)
        except KeyError:
            for module in get_format_modules(lang):
                try:
                    val = getattr(module, format_type)
                    _format_cache[cache_key] = val
                    return val
                except AttributeError:
                    pass
            _format_cache[cache_key] = None
    return getattr(settings, format_type)

get_format_lazy = lazy(get_format, unicode, list, tuple)

def date_format(value, format=None, use_l10n=None):
    """
    Formats a datetime.date or datetime.datetime object using a
    localizable format

    If use_l10n is provided and is not None, that will force the value to
    be localized (or not), overriding the value of settings.USE_L10N.
    """
    return dateformat.format(value, get_format(format or 'DATE_FORMAT', use_l10n=use_l10n))

def time_format(value, format=None, use_l10n=None):
    """
    Formats a datetime.time object using a localizable format