|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2014 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing message translations for pyflakes warning messages. |
|
8 """ |
|
9 |
|
10 from PyQt4.QtCore import QCoreApplication |
|
11 |
|
12 __all__ = ["getTranslatedFlakesMessage"] |
|
13 |
|
14 _messages = { |
|
15 'F01': QCoreApplication.translate( |
|
16 'pyFlakes', |
|
17 '{0!r} imported but unused.'), |
|
18 'F02': QCoreApplication.translate( |
|
19 'pyFlakes', |
|
20 'Redefinition of unused {0!r} from line {1!r}.'), |
|
21 'F03': QCoreApplication.translate( |
|
22 'pyFlakes', |
|
23 'Import {0!r} from line {1!r} shadowed by loop variable.'), |
|
24 'F04': QCoreApplication.translate( |
|
25 'pyFlakes', |
|
26 "'from {0} import *' used; unable to detect undefined names."), |
|
27 'F05': QCoreApplication.translate( |
|
28 'pyFlakes', |
|
29 'Undefined name {0!r}.'), |
|
30 'F06': QCoreApplication.translate( |
|
31 'pyFlakes', |
|
32 'Undefined name {0!r} in __all__.'), |
|
33 'F07': QCoreApplication.translate( |
|
34 'pyFlakes', |
|
35 "Local variable {0!r} (defined in enclosing scope on line {1!r})" |
|
36 " referenced before assignment."), |
|
37 'F08': QCoreApplication.translate( |
|
38 'pyFlakes', |
|
39 'Duplicate argument {0!r} in function definition.'), |
|
40 'F09': QCoreApplication.translate( |
|
41 'pyFlakes', |
|
42 'Redefinition of function {0!r} from line {1!r}.'), |
|
43 'F10': QCoreApplication.translate( |
|
44 'pyFlakes', |
|
45 'Future import(s) {0!r} after other statements.'), |
|
46 'F11': QCoreApplication.translate( |
|
47 'pyFlakes', |
|
48 'Local variable {0!r} is assigned to but never used.'), |
|
49 |
|
50 } |
|
51 |
|
52 |
|
53 def getTranslatedFlakesMessage(message_id, message_args): |
|
54 """ |
|
55 Module function to get a translated and formatted message for a |
|
56 given pyflakes message ID. |
|
57 |
|
58 @param message_id message ID (string) |
|
59 @param message_args arguments for a formatted message (list) |
|
60 @return translated and formatted message (string) |
|
61 """ |
|
62 if message_id in _messages: |
|
63 return QCoreApplication.translate( |
|
64 "pyFlakes", _messages[message_id]).format(*message_args) |
|
65 else: |
|
66 return QCoreApplication.translate( |
|
67 "pyFlakes", "no message defined for code '{0}'")\ |
|
68 .format(message_id) |