Plugins/CheckerPlugins/SyntaxChecker/pyflakes/translations.py

branch
Py2 comp.
changeset 3484
645c12de6b0c
parent 3229
c8bbf88ae439
child 3544
431c842fd09a
equal deleted inserted replaced
3456:96232974dcdb 3484:645c12de6b0c
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 __future__ import unicode_literals
11
12 from PyQt4.QtCore import QCoreApplication
13
14 __all__ = ["getTranslatedFlakesMessage"]
15
16 _messages = {
17 'F01': QCoreApplication.translate(
18 'pyFlakes',
19 '{0!r} imported but unused.'),
20 'F02': QCoreApplication.translate(
21 'pyFlakes',
22 'Redefinition of unused {0!r} from line {1!r}.'),
23 'F03': QCoreApplication.translate(
24 'pyFlakes',
25 'Import {0!r} from line {1!r} shadowed by loop variable.'),
26 'F04': QCoreApplication.translate(
27 'pyFlakes',
28 "'from {0} import *' used; unable to detect undefined names."),
29 'F05': QCoreApplication.translate(
30 'pyFlakes',
31 'Undefined name {0!r}.'),
32 'F06': QCoreApplication.translate(
33 'pyFlakes',
34 'Undefined name {0!r} in __all__.'),
35 'F07': QCoreApplication.translate(
36 'pyFlakes',
37 "Local variable {0!r} (defined in enclosing scope on line {1!r})"
38 " referenced before assignment."),
39 'F08': QCoreApplication.translate(
40 'pyFlakes',
41 'Duplicate argument {0!r} in function definition.'),
42 'F09': QCoreApplication.translate(
43 'pyFlakes',
44 'Redefinition of {0!r} from line {1!r}.'),
45 'F10': QCoreApplication.translate(
46 'pyFlakes',
47 'Future import(s) {0!r} after other statements.'),
48 'F11': QCoreApplication.translate(
49 'pyFlakes',
50 'Local variable {0!r} is assigned to but never used.'),
51 'F12': QCoreApplication.translate(
52 'pyFlakes',
53 'List comprehension redefines {0!r} from line {1!r}.'),
54 'F13': QCoreApplication.translate(
55 'pyFlakes',
56 'Syntax error detected in doctest.'),
57 }
58
59
60 def getTranslatedFlakesMessage(message_id, message_args):
61 """
62 Module function to get a translated and formatted message for a
63 given pyflakes message ID.
64
65 @param message_id message ID (string)
66 @param message_args arguments for a formatted message (list)
67 @return translated and formatted message (string)
68 """
69 if message_id in _messages:
70 # Avoid leading "u" at Python2 unicode strings
71 msg = _messages[message_id].replace("{0!r}", "'{0}'")
72 msg = msg.replace("{1!r}", "'{1}'")
73 return msg.format(*message_args)
74 else:
75 return QCoreApplication.translate(
76 "pyFlakes", "no message defined for code '{0}'")\
77 .format(message_id)

eric ide

mercurial