示例#1
0
def gettext_set_language(ln):
    """Set the _ gettext function in every caller function.

    Usage::
        _ = gettext_set_language(ln)
    """
    warnings.warn('"gettext_set_language" is going to be removed.',
                  DeprecationWarning)
    from invenio_ext.babel import set_locale
    with set_locale(ln):
        return gettext
示例#2
0
def gettext_set_language(ln):
    """Set the _ gettext function in every caller function.

    Usage::
        _ = gettext_set_language(ln)
    """
    warnings.warn('"gettext_set_language" is going to be removed.',
                  DeprecationWarning)
    from invenio_ext.babel import set_locale
    with set_locale(ln):
        return gettext
示例#3
0
def convert_datestruct_to_dategui(datestruct, ln=None):
    """Convert: (2005, 11, 16, 15, 11, 44, 2, 320, 0) => '16 nov 2005, 15:11'
    Month is internationalized
    """
    ln = default_ln(ln)
    with set_locale(ln):
        try:
            if datestruct[0] and datestruct[1] and datestruct[2]:
                output_format = "d MMM Y, H:mm"
                dt = datetime.fromtimestamp(time.mktime(datestruct))
                return babel_format_datetime(dt, output_format).encode('utf8')
            else:
                raise ValueError
        except:
            return _("N/A").encode('utf8')
示例#4
0
def convert_datetext_to_dategui(datetext, ln=None, secs=False):
    """Convert: '2005-11-16 15:11:57' => '16 nov 2005, 15:11'

    Or optionally with seconds:
    '2005-11-16 15:11:57' => '16 nov 2005, 15:11:57'
    Month is internationalized
    """
    ln = default_ln(ln)
    with set_locale(ln):
        try:
            datestruct = convert_datetext_to_datestruct(datetext)
            if datestruct == datestruct_default:
                raise ValueError

            if secs:
                output_format = "d MMM Y, H:mm:ss"
            else:
                output_format = "d MMM Y, H:mm"
            dt = datetime.fromtimestamp(time.mktime(datestruct))
            return babel_format_datetime(dt, output_format).encode('utf8')
        except ValueError:
            return _("N/A").encode('utf8')