Back to index

moin  1.9.0~rc2
GetText2.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003     MoinMoin - Load I18N Text and substitute data.
00004 
00005     This macro has the main purpose of being used by extensions that write
00006     data to wiki pages but want to ensure that it is properly translated.
00007 
00008     @copyright: 2006 MoinMoin:AlexanderSchremmer,
00009                 2009 MoinMoin:EugeneSyromyatnikov,
00010                 2009 MoinMoin:ThomasWaldmann
00011     @license: GNU GPL, see COPYING for details.
00012 """
00013 
00014 from MoinMoin.packages import unpackLine
00015 
00016 Dependencies = ["language"]
00017 
00018 def execute(macro, args):
00019     """ args consists of a character specifiying the separator and then a
00020     packLine sequence describing a list. The first element of it is the message
00021     and the remaining elements are substituted in the message using string
00022     substitution.
00023     """
00024     msg = u''
00025     if args:
00026         sep = args[0]
00027         args = unpackLine(args[1:], sep)
00028         if args:
00029             msg, args = args[0], tuple(args[1:])
00030             msg = macro.request.getText(msg)
00031             try:
00032                 msg = msg % args
00033             except TypeError:
00034                 # % operator will raise TypeError if msg has named placeholders
00035                 msg = msg % dict([arg.split('=', 1) for arg in args if '=' in arg])
00036     return macro.formatter.text(msg)
00037