예제 #1
0
파일: extract.py 프로젝트: ozten/tower
def tweak_message(message):
    """We piggyback on jinja2's babel_extract() (really, Babel's extract_*
    functions) but they don't support some things we need so this function will
    tweak the message.  Specifically:

        1) We strip whitespace from the msgid.  Jinja2 will only strip
            whitespace from the ends of a string so linebreaks show up in
            your .po files still.

        2) Babel doesn't support context (msgctxt).  We hack that in ourselves
            here.
    """
    if isinstance(message, basestring):
        message = strip_whitespace(message)
    elif isinstance(message, tuple):
        # A tuple of 2 has context, 3 is plural, 4 is plural with context
        if len(message) == 2:
            message = add_context(message[1], message[0])
        elif len(message) == 3:
            singular, plural, num = message
            message = (strip_whitespace(singular),
                       strip_whitespace(plural),
                       num)
        elif len(message) == 4:
            singular, plural, num, ctxt = message
            message = (add_context(ctxt, strip_whitespace(singular)),
                       add_context(ctxt, strip_whitespace(plural)),
                       num)
    return message
예제 #2
0
파일: test_l10n.py 프로젝트: stasm/tower
def test_add_context():
    eq_("nacho\x04testo", tower.add_context("nacho", "testo"))
예제 #3
0
파일: test_l10n.py 프로젝트: xethorn/tower
def test_add_context():
    eq_("nacho\x04testo", tower.add_context("nacho", "testo"))