view MoinMoin/macro/ @ 6087:538b7d0119cd

tagged release 1.9.8
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Fri, 17 Oct 2014 21:53:46 +0200
parents d78c35783dd8
line wrap: on
line source

# -*- coding: iso-8859-1 -*-
    MoinMoin - Load I18N Text and substitute data.

    This macro has the main purpose of being used by extensions that write
    data to wiki pages but want to ensure that it is properly translated.

    @copyright: 2006 MoinMoin:AlexanderSchremmer,
                2009 MoinMoin:EugeneSyromyatnikov,
                2009 MoinMoin:ThomasWaldmann
    @license: GNU GPL, see COPYING for details.

from MoinMoin.packages import unpackLine

Dependencies = ["language"]

def execute(macro, args):
    """ args consists of a character specifiying the separator and then a
    packLine sequence describing a list. The first element of it is the message
    and the remaining elements are substituted in the message using string
    msg = u''
    if args:
        sep = args[0]
        args = unpackLine(args[1:], sep)
        if args:
            msg, args = args[0], tuple(args[1:])
            msg = macro.request.getText(msg)
                msg = msg % args
            except TypeError:
                # % operator will raise TypeError if msg has named placeholders
                msg = msg % dict([arg.split('=', 1) for arg in args if '=' in arg])
    return macro.formatter.text(msg)