Ejemplo n.º 1
0
def test_strings():

    # NOTE: part a1
    comment_test = _(u'first part')

    # NOTE: part b1
    comment_test_2 = _(u'second part')

    context_test = pgettext(u'Three', u'first part')
    context_test2 = pgettext(u'Four', u'second part')
Ejemplo n.º 2
0
def test_strings():

    # NOTE: part a1
    comment_test = _(u'first part')

    # NOTE: part b1
    comment_test_2 = _(u'second part')

    context_test = pgettext(u'Three', u'first part')
    context_test2 = pgettext(u'Four', u'second part')
Ejemplo n.º 3
0
def num_format(number, key=None, labels=True, suffix_html=False):

    if key == "ordinal":

        ordinals = (pgettext('0', 'th'), pgettext('1', 'st'),
                    pgettext('2', 'nd'), pgettext('3', 'rd'),
                    pgettext('4', 'th'), pgettext('5',
                                                  'th'), pgettext('6', 'th'),
                    pgettext('7', 'th'), pgettext('8',
                                                  'th'), pgettext('9', 'th'))

        n = int(number)
        if n % 100 in (11, 12, 13):
            return u"{0}{1}".format(n, ordinals[0])
        return u"{0}{1}".format(n, ordinals[n % 10])

    # Converts the number to a float.
    n = float(number)
    label = None
    suffix = None

    # Determines which index of "groups" to move the decimal point to.
    if n:

        groups = ["", "k", "M", "B", "T"]
        m = max(0,
                min(len(groups) - 1, int(math.floor(math.log10(abs(n)) / 3))))

        # Moves the decimal point and rounds the new number to specific decimals.
        n = n / 10**(3 * m)
        if key and key == "eci":
            n = round(n, 2)
        elif n > 99:
            n = int(n)
        elif n > 9:
            n = round(n, 1)
        elif n > 1:
            n = round(n, 2)
        else:
            n = round(n, 3)

        # Initializes the number suffix based on the group.
        suffix = groups[m]

    raw_n = n
    n = format_decimal(n, locale=g.locale)

    if key and key == "eci":
        n = str(n)
        if len(n) == 3:
            n = "{}0".format(n)

    # If the language is not English, translate the suffix.
    if suffix:
        if g.locale != "en":
            suffix = u"{0}".format(plurals(key=suffix, n=raw_n))
            # suffix = u"{0}".format(suffix)
        if len(suffix) > 1:
            n = u"{0} <span class='suffix'>{1}</span>".format(n, suffix)
        else:
            n = u"{0}{1}".format(n, suffix)

    if key and labels:
        affix = affixes(key)
        if affix:
            return u"{0}{1}{2}".format(unicode(affix[0]), n, unicode(affix[1]))
        elif "growth" in key:
            return "{0}%".format(n)

    return n
Ejemplo n.º 4
0
def num_format(number, key=None, labels=True, suffix_html=False):

    if key == "ordinal":

        ordinals = (pgettext('0', 'th'),
                    pgettext('1', 'st'),
                    pgettext('2', 'nd'),
                    pgettext('3', 'rd'),
                    pgettext('4', 'th'),
                    pgettext('5', 'th'),
                    pgettext('6', 'th'),
                    pgettext('7', 'th'),
                    pgettext('8', 'th'),
                    pgettext('9', 'th'))

        n = int(number)
        if n % 100 in (11, 12, 13):
            return u"{0}{1}".format(n, ordinals[0])
        return u"{0}{1}".format(n, ordinals[n % 10])

    # Converts the number to a float.
    n = float(number)
    label  = None
    suffix = None

    # Determines which index of "groups" to move the decimal point to.
    if n:

        groups = ["", "k", "M", "B", "T"]
        m = max(0,min(len(groups)-1, int(math.floor(math.log10(abs(n))/3))))

        # Moves the decimal point and rounds the new number to specific decimals.
        n = n/10**(3*m)
        if key and key == "eci":
            n = round(n, 2)
        elif n > 99:
            n = int(n)
        elif n > 9:
            n = round(n, 1)
        elif n > 1:
            n = round(n, 2)
        else:
            n = round(n, 3)

        # Initializes the number suffix based on the group.
        suffix = groups[m]

    raw_n = n
    n = format_decimal(n, locale=g.locale)

    if key and key == "eci":
        n = str(n)
        if len(n) == 3:
            n = "{}0".format(n)

    # If the language is not English, translate the suffix.
    if suffix:
        if g.locale != "en":
            suffix = u"{0}".format(plurals(key=suffix, n=raw_n))
            # suffix = u"{0}".format(suffix)
        if len(suffix) > 1:
            n = u"{0} <span class='suffix'>{1}</span>".format(n,suffix)
        else:
            n = u"{0}{1}".format(n,suffix)

    if key and labels:
        affix = affixes(key)
        if affix:
            return u"{0}{1}{2}".format(unicode(affix[0]), n, unicode(affix[1]))
        elif "growth" in key:
            return "{0}%".format(n)

    return n
Ejemplo n.º 5
0
def num_format(number, key = None, labels = True):

    if key == "ordinal":

        ordinals = (pgettext('0', 'th'),
                    pgettext('1', 'st'),
                    pgettext('2', 'nd'),
                    pgettext('3', 'rd'),
                    pgettext('4', 'th'),
                    pgettext('5', 'th'),
                    pgettext('6', 'th'),
                    pgettext('7', 'th'),
                    pgettext('8', 'th'),
                    pgettext('9', 'th'))

        n = int(number)
        if n % 100 in (11, 12, 13):
            return "{0}{1}".format(n, ordinals[0])
        return "{0}{1}".format(n, ordinals[n % 10])

    # Converts the number to a float.
    try:
        n = float(number)
    except ValueError:
        return number
    label  = None
    suffix = None

    # Determines which index of "groups" to move the decimal point to.
    if n:

        groups = ["", "k", "M", "B", "T"]
        m = max(0,min(len(groups)-1, int(math.floor(math.log10(abs(n))/3))))

        # Moves the decimal point and rounds the new number to specific decimals.
        n = n/10**(3*m)
        if n > 99:
            n = int(n)
        elif n > 9:
            n = round(n, 1)
        elif n > 1:
            n = round(n, 2)
        else:
            n = round(n, 3)

        # Initializes the number suffix based on the group.
        suffix = groups[m]

    arrow = False
    if "growth" in key or key == "share":
        if n > 0:
            arrow = "up"
        elif n < 0:
            arrow = "down"
        n = float(n)*100

    if "age" in key:
        n = int(round(n))
    else:
        n = format_decimal(n, locale=g.locale)

    # If the language is not English, translate the suffix.
    if suffix:
        if g.locale != "en":
            suffix = u" {0}".format(plurals(key=suffix, n=n))
        n = u"{0}{1}".format(n,suffix)

    if key and labels:
        affix = affixes(key)
        if affix:
            return u"{0}{1}{2}".format(unicode(affix[0]), n, unicode(affix[1]))
        elif "growth" in key:
            if arrow:
                arrow = "<i class='growth-arrow {0} fa fa-arrow-circle-{0}'></i>".format(arrow)
            else:
                arrow = ""
            return "{}%{}".format(n, arrow)
        elif key == "share":
            return "{}%".format(n)

    return n