Description
GetText2 macro can't work with format string with named formats.
Steps to reproduce
Try to use GetText2 with translation string which has named formats.
Example
Trying to write something like <<GetText2(,Upload new attachment \"%(filename)s\",filename=file name)>>
Results to
<<GetText2: execution failed [format requires a mapping] (see also the log)>>
on page.
URL: http://master19.moinmo.in/ПомощьПоДействиям/AttachFile
Component selection
plugin: GetText2 macro
Details
Traceback:
Traceback (most recent call last): File "/data/programs/moin-1.9.0rc1/MoinMoin/macro/__init__.py", line 124, in execute return execute(self, args) File "/data/programs/moin-1.9.0rc1/MoinMoin/macro/GetText2.py", line 28, in execute message = translation % tuple(args[1:]) TypeError: format requires a mapping
MoinMoin Version |
tested 1.9rc1, earlier versions may also be affected |
OS and Version |
Linux deadcode 2.6.24-24-generic #1 SMP Tue Jul 7 19:46:39 UTC 2009 i686 GNU/Linux, this wiki |
Python Version |
Python 2.5.1, this wiki |
Server Setup |
Desktop Edition, this wiki |
Server Details |
|
Language you are using the wiki in (set in the browser/UserPreferences) |
English, Russian |
Workaround
applying this patch to macro/GetText2.py
--- GetText2.py.old 2009-11-04 12:43:24.000000000 +0300 +++ GetText2.py 2009-11-12 14:07:44.000000000 +0300 @@ -21,11 +21,12 @@ """ sep = args[0] args = unpackLine(args[1:], sep) - if args: - translation = macro.request.getText(args[0]) - else: - translation = u"" - message = translation % tuple(args[1:]) + translation = args and macro.request.getText(args[0]) or u"" + try: + message = translation % tuple(args[1:]) + except TypeError: + message = translation % dict([i.split('=',1) for i in args[1:] if '=' in i]) + return macro.formatter.text(message)
solves problem. It tries to interpret remaining args as tuple (as originally was), and, if fails with TypeError, interpret arguments as equal sign-separated pairs of keys and values. It supposes that there's no format names which containing equal sign, but, i think, it's rather reasonable assumption.
Discussion
Next time please do an unified diff.
Done. -- EugeneSyromyatnikov 2009-11-04 11:47:56
Plan
- Priority:
- Assigned to:
Status: slightly modified patch applied by http://hg.moinmo.in/moin/1.8/rev/d78c35783dd8, merged into 1.9