Plugins/CheckerPlugins/CodeStyleChecker/translations.py

branch
Py2 comp.
changeset 3456
96232974dcdb
parent 3443
7d919fd299f6
child 3484
645c12de6b0c
equal deleted inserted replaced
3178:f25fc1364c88 3456:96232974dcdb
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2014 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing message translations for the code style plugin messages.
8 """
9
10 from PyQt4.QtCore import QCoreApplication
11
12 __all__ = ["getTranslatedMessage"]
13
14 _messages = {
15 "E101": QCoreApplication.translate(
16 "pep8",
17 "indentation contains mixed spaces and tabs"),
18 "E111": QCoreApplication.translate(
19 "pep8",
20 "indentation is not a multiple of four"),
21 "E112": QCoreApplication.translate(
22 "pep8",
23 "expected an indented block"),
24 "E113": QCoreApplication.translate(
25 "pep8",
26 "unexpected indentation"),
27 "E121": QCoreApplication.translate(
28 "pep8",
29 "continuation line indentation is not a multiple of four"),
30 "E122": QCoreApplication.translate(
31 "pep8",
32 "continuation line missing indentation or outdented"),
33 "E123": QCoreApplication.translate(
34 "pep8",
35 "closing bracket does not match indentation of opening"
36 " bracket's line"),
37 "E124": QCoreApplication.translate(
38 "pep8",
39 "closing bracket does not match visual indentation"),
40 "E125": QCoreApplication.translate(
41 "pep8",
42 "continuation line does not distinguish itself from next"
43 " logical line"),
44 "E126": QCoreApplication.translate(
45 "pep8",
46 "continuation line over-indented for hanging indent"),
47 "E127": QCoreApplication.translate(
48 "pep8",
49 "continuation line over-indented for visual indent"),
50 "E128": QCoreApplication.translate(
51 "pep8",
52 "continuation line under-indented for visual indent"),
53 "E133": QCoreApplication.translate(
54 "pep8",
55 "closing bracket is missing indentation"),
56 "W191": QCoreApplication.translate(
57 "pep8",
58 "indentation contains tabs"),
59 "E201": QCoreApplication.translate(
60 "pep8",
61 "whitespace after '{0}'"),
62 "E202": QCoreApplication.translate(
63 "pep8",
64 "whitespace before '{0}'"),
65 "E203": QCoreApplication.translate(
66 "pep8",
67 "whitespace before '{0}'"),
68 "E211": QCoreApplication.translate(
69 "pep8",
70 "whitespace before '{0}'"),
71 "E221": QCoreApplication.translate(
72 "pep8",
73 "multiple spaces before operator"),
74 "E222": QCoreApplication.translate(
75 "pep8",
76 "multiple spaces after operator"),
77 "E223": QCoreApplication.translate(
78 "pep8",
79 "tab before operator"),
80 "E224": QCoreApplication.translate(
81 "pep8",
82 "tab after operator"),
83 "E225": QCoreApplication.translate(
84 "pep8",
85 "missing whitespace around operator"),
86 "E226": QCoreApplication.translate(
87 "pep8",
88 "missing whitespace around arithmetic operator"),
89 "E227": QCoreApplication.translate(
90 "pep8",
91 "missing whitespace around bitwise or shift operator"),
92 "E228": QCoreApplication.translate(
93 "pep8",
94 "missing whitespace around modulo operator"),
95 "E231": QCoreApplication.translate(
96 "pep8",
97 "missing whitespace after '{0}'"),
98 "E241": QCoreApplication.translate(
99 "pep8",
100 "multiple spaces after '{0}'"),
101 "E242": QCoreApplication.translate(
102 "pep8",
103 "tab after '{0}'"),
104 "E251": QCoreApplication.translate(
105 "pep8",
106 "unexpected spaces around keyword / parameter equals"),
107 "E261": QCoreApplication.translate(
108 "pep8",
109 "at least two spaces before inline comment"),
110 "E262": QCoreApplication.translate(
111 "pep8",
112 "inline comment should start with '# '"),
113 "E271": QCoreApplication.translate(
114 "pep8",
115 "multiple spaces after keyword"),
116 "E272": QCoreApplication.translate(
117 "pep8",
118 "multiple spaces before keyword"),
119 "E273": QCoreApplication.translate(
120 "pep8",
121 "tab after keyword"),
122 "E274": QCoreApplication.translate(
123 "pep8",
124 "tab before keyword"),
125 "W291": QCoreApplication.translate(
126 "pep8",
127 "trailing whitespace"),
128 "W292": QCoreApplication.translate(
129 "pep8",
130 "no newline at end of file"),
131 "W293": QCoreApplication.translate(
132 "pep8",
133 "blank line contains whitespace"),
134 "E301": QCoreApplication.translate(
135 "pep8",
136 "expected 1 blank line, found 0"),
137 "E302": QCoreApplication.translate(
138 "pep8",
139 "expected 2 blank lines, found {0}"),
140 "E303": QCoreApplication.translate(
141 "pep8",
142 "too many blank lines ({0})"),
143 "E304": QCoreApplication.translate(
144 "pep8",
145 "blank lines found after function decorator"),
146 "W391": QCoreApplication.translate(
147 "pep8",
148 "blank line at end of file"),
149 "E401": QCoreApplication.translate(
150 "pep8",
151 "multiple imports on one line"),
152 "E501": QCoreApplication.translate(
153 "pep8",
154 "line too long ({0} > {1} characters)"),
155 "E502": QCoreApplication.translate(
156 "pep8",
157 "the backslash is redundant between brackets"),
158 "W601": QCoreApplication.translate(
159 "pep8",
160 ".has_key() is deprecated, use 'in'"),
161 "W602": QCoreApplication.translate(
162 "pep8",
163 "deprecated form of raising exception"),
164 "W603": QCoreApplication.translate(
165 "pep8",
166 "'<>' is deprecated, use '!='"),
167 "W604": QCoreApplication.translate(
168 "pep8",
169 "backticks are deprecated, use 'repr()'"),
170 "E701": QCoreApplication.translate(
171 "pep8",
172 "multiple statements on one line (colon)"),
173 "E702": QCoreApplication.translate(
174 "pep8",
175 "multiple statements on one line (semicolon)"),
176 "E703": QCoreApplication.translate(
177 "pep8",
178 "statement ends with a semicolon"),
179 "E711": QCoreApplication.translate(
180 "pep8",
181 "comparison to {0} should be {1}"),
182 "E712": QCoreApplication.translate(
183 "pep8",
184 "comparison to {0} should be {1}"),
185 "E721": QCoreApplication.translate(
186 "pep8",
187 "do not compare types, use 'isinstance()'"),
188 "E901": QCoreApplication.translate(
189 "pep8",
190 "{0}: {1}"),
191
192 # DocStyleChecker messages
193 "D101": QCoreApplication.translate(
194 "DocStyleChecker", "module is missing a docstring"),
195 "D102": QCoreApplication.translate(
196 "DocStyleChecker",
197 "public function/method is missing a docstring"),
198 "D103": QCoreApplication.translate(
199 "DocStyleChecker",
200 "private function/method may be missing a docstring"),
201 "D104": QCoreApplication.translate(
202 "DocStyleChecker", "public class is missing a docstring"),
203 "D105": QCoreApplication.translate(
204 "DocStyleChecker", "private class may be missing a docstring"),
205 "D111": QCoreApplication.translate(
206 "DocStyleChecker", 'docstring not surrounded by """'),
207 "D112": QCoreApplication.translate(
208 "DocStyleChecker",
209 'docstring containing \\ not surrounded by r"""'),
210 "D113": QCoreApplication.translate(
211 "DocStyleChecker",
212 'docstring containing unicode character not surrounded by u"""'),
213 "D121": QCoreApplication.translate(
214 "DocStyleChecker", "one-liner docstring on multiple lines"),
215 "D122": QCoreApplication.translate(
216 "DocStyleChecker", "docstring has wrong indentation"),
217 "D130": QCoreApplication.translate(
218 "DocStyleChecker", "docstring does not contain a summary"),
219 "D131": QCoreApplication.translate(
220 "DocStyleChecker", "docstring summary does not end with a period"),
221 "D132": QCoreApplication.translate(
222 "DocStyleChecker",
223 "docstring summary is not in imperative mood"
224 " (Does instead of Do)"),
225 "D133": QCoreApplication.translate(
226 "DocStyleChecker",
227 "docstring summary looks like a function's/method's signature"),
228 "D134": QCoreApplication.translate(
229 "DocStyleChecker",
230 "docstring does not mention the return value type"),
231 "D141": QCoreApplication.translate(
232 "DocStyleChecker",
233 "function/method docstring is separated by a blank line"),
234 "D142": QCoreApplication.translate(
235 "DocStyleChecker",
236 "class docstring is not preceded by a blank line"),
237 "D143": QCoreApplication.translate(
238 "DocStyleChecker",
239 "class docstring is not followed by a blank line"),
240 "D144": QCoreApplication.translate(
241 "DocStyleChecker",
242 "docstring summary is not followed by a blank line"),
243 "D145": QCoreApplication.translate(
244 "DocStyleChecker",
245 "last paragraph of docstring is not followed by a blank line"),
246
247 "D203": QCoreApplication.translate(
248 "DocStyleChecker",
249 "private function/method is missing a docstring"),
250 "D205": QCoreApplication.translate(
251 "DocStyleChecker", "private class is missing a docstring"),
252 "D221": QCoreApplication.translate(
253 "DocStyleChecker",
254 "leading quotes of docstring not on separate line"),
255 "D222": QCoreApplication.translate(
256 "DocStyleChecker",
257 "trailing quotes of docstring not on separate line"),
258 "D231": QCoreApplication.translate(
259 "DocStyleChecker", "docstring summary does not end with a period"),
260 "D234": QCoreApplication.translate(
261 "DocStyleChecker",
262 "docstring does not contain a @return line but function/method"
263 " returns something"),
264 "D235": QCoreApplication.translate(
265 "DocStyleChecker",
266 "docstring contains a @return line but function/method doesn't"
267 " return anything"),
268 "D236": QCoreApplication.translate(
269 "DocStyleChecker",
270 "docstring does not contain enough @param/@keyparam lines"),
271 "D237": QCoreApplication.translate(
272 "DocStyleChecker",
273 "docstring contains too many @param/@keyparam lines"),
274 "D238": QCoreApplication.translate(
275 "DocStyleChecker",
276 "keyword only arguments must be documented with @keyparam lines"),
277 "D239": QCoreApplication.translate(
278 "DocStyleChecker", "order of @param/@keyparam lines does"
279 " not match the function/method signature"),
280 "D242": QCoreApplication.translate(
281 "DocStyleChecker", "class docstring is preceded by a blank line"),
282 "D243": QCoreApplication.translate(
283 "DocStyleChecker", "class docstring is followed by a blank line"),
284 "D244": QCoreApplication.translate(
285 "DocStyleChecker",
286 "function/method docstring is preceded by a blank line"),
287 "D245": QCoreApplication.translate(
288 "DocStyleChecker",
289 "function/method docstring is followed by a blank line"),
290 "D246": QCoreApplication.translate(
291 "DocStyleChecker",
292 "docstring summary is not followed by a blank line"),
293 "D247": QCoreApplication.translate(
294 "DocStyleChecker",
295 "last paragraph of docstring is followed by a blank line"),
296 "D250": QCoreApplication.translate(
297 "DocStyleChecker",
298 "docstring does not contain a @exception line but function/method"
299 " raises an exception"),
300 "D251": QCoreApplication.translate(
301 "DocStyleChecker",
302 "docstring contains a @exception line but function/method doesn't"
303 " raise an exception"),
304
305 "D901": QCoreApplication.translate(
306 "DocStyleChecker", "{0}: {1}"),
307
308 # NamingStyleChecker messages
309 "N801": QCoreApplication.translate(
310 "NamingStyleChecker",
311 "class names should use CapWords convention"),
312 "N802": QCoreApplication.translate(
313 "NamingStyleChecker",
314 "function name should be lowercase"),
315 "N803": QCoreApplication.translate(
316 "NamingStyleChecker",
317 "argument name should be lowercase"),
318 "N804": QCoreApplication.translate(
319 "NamingStyleChecker",
320 "first argument of a class method should be named 'cls'"),
321 "N805": QCoreApplication.translate(
322 "NamingStyleChecker",
323 "first argument of a method should be named 'self'"),
324 "N806": QCoreApplication.translate(
325 "NamingStyleChecker",
326 "first argument of a static method should not be named"
327 " 'self' or 'cls"),
328 "N807": QCoreApplication.translate(
329 "NamingStyleChecker",
330 "module names should be lowercase"),
331 "N808": QCoreApplication.translate(
332 "NamingStyleChecker",
333 "package names should be lowercase"),
334 "N811": QCoreApplication.translate(
335 "NamingStyleChecker",
336 "constant imported as non constant"),
337 "N812": QCoreApplication.translate(
338 "NamingStyleChecker",
339 "lowercase imported as non lowercase"),
340 "N813": QCoreApplication.translate(
341 "NamingStyleChecker",
342 "camelcase imported as lowercase"),
343 "N814": QCoreApplication.translate(
344 "NamingStyleChecker",
345 "camelcase imported as constant"),
346 "N821": QCoreApplication.translate(
347 "NamingStyleChecker",
348 "variable in function should be lowercase"),
349 "N831": QCoreApplication.translate(
350 "NamingStyleChecker",
351 "names 'l', 'O' and 'I' should be avoided"),
352
353 # CodeStyleFixer messages
354 "FD111": QCoreApplication.translate(
355 'CodeStyleFixer',
356 "Triple single quotes converted to triple double quotes."),
357 'FD112': QCoreApplication.translate(
358 'CodeStyleFixer',
359 'Introductory quotes corrected to be {0}"""'),
360 "FD121": QCoreApplication.translate(
361 'CodeStyleFixer',
362 "Single line docstring put on one line."),
363 "FD131": QCoreApplication.translate(
364 'CodeStyleFixer',
365 "Period added to summary line."),
366 "FD141": QCoreApplication.translate(
367 'CodeStyleFixer',
368 "Blank line before function/method docstring removed."),
369 "FD142": QCoreApplication.translate(
370 'CodeStyleFixer',
371 "Blank line inserted before class docstring."),
372 "FD143": QCoreApplication.translate(
373 'CodeStyleFixer',
374 "Blank line inserted after class docstring."),
375 "FD144": QCoreApplication.translate(
376 'CodeStyleFixer',
377 "Blank line inserted after docstring summary."),
378 "FD145": QCoreApplication.translate(
379 'CodeStyleFixer',
380 "Blank line inserted after last paragraph of docstring."),
381 "FD221": QCoreApplication.translate(
382 'CodeStyleFixer',
383 "Leading quotes put on separate line."),
384 "FD222": QCoreApplication.translate(
385 'CodeStyleFixer',
386 "Trailing quotes put on separate line."),
387 "FD242": QCoreApplication.translate(
388 'CodeStyleFixer',
389 "Blank line before class docstring removed."),
390 "FD244": QCoreApplication.translate(
391 'CodeStyleFixer',
392 "Blank line before function/method docstring removed."),
393 "FD243": QCoreApplication.translate(
394 'CodeStyleFixer',
395 "Blank line after class docstring removed."),
396 "FD245": QCoreApplication.translate(
397 'CodeStyleFixer',
398 "Blank line after function/method docstring removed."),
399 "FD247": QCoreApplication.translate(
400 'CodeStyleFixer',
401 "Blank line after last paragraph removed."),
402 "FE101": QCoreApplication.translate(
403 'CodeStyleFixer',
404 "Tab converted to 4 spaces."),
405 "FE111": QCoreApplication.translate(
406 'CodeStyleFixer',
407 "Indentation adjusted to be a multiple of four."),
408 "FE121": QCoreApplication.translate(
409 'CodeStyleFixer',
410 "Indentation of continuation line corrected."),
411 "FE124": QCoreApplication.translate(
412 'CodeStyleFixer',
413 "Indentation of closing bracket corrected."),
414 "FE122": QCoreApplication.translate(
415 'CodeStyleFixer',
416 "Missing indentation of continuation line corrected."),
417 "FE123": QCoreApplication.translate(
418 'CodeStyleFixer',
419 "Closing bracket aligned to opening bracket."),
420 "FE125": QCoreApplication.translate(
421 'CodeStyleFixer',
422 "Indentation level changed."),
423 "FE126": QCoreApplication.translate(
424 'CodeStyleFixer',
425 "Indentation level of hanging indentation changed."),
426 "FE127": QCoreApplication.translate(
427 'CodeStyleFixer',
428 "Visual indentation corrected."),
429 "FE201": QCoreApplication.translate(
430 'CodeStyleFixer',
431 "Extraneous whitespace removed."),
432 "FE225": QCoreApplication.translate(
433 'CodeStyleFixer',
434 "Missing whitespace added."),
435 "FE221": QCoreApplication.translate(
436 'CodeStyleFixer',
437 "Extraneous whitespace removed."),
438 "FE231": QCoreApplication.translate(
439 'CodeStyleFixer',
440 "Missing whitespace added."),
441 "FE251": QCoreApplication.translate(
442 'CodeStyleFixer',
443 "Extraneous whitespace removed."),
444 "FE261": QCoreApplication.translate(
445 'CodeStyleFixer',
446 "Whitespace around comment sign corrected."),
447 "FE301": QCoreApplication.translate(
448 'CodeStyleFixer',
449 "One blank line inserted."),
450
451 "FE302+": lambda n=1: QCoreApplication.translate(
452 'CodeStyleFixer',
453 "%n blank line(s) inserted.", '', QCoreApplication.CodecForTr, n),
454 "FE302-": lambda n=1: QCoreApplication.translate(
455 'CodeStyleFixer',
456 "%n superfluous lines removed", '', QCoreApplication.CodecForTr, n),
457
458 "FE303": QCoreApplication.translate(
459 'CodeStyleFixer',
460 "Superfluous blank lines removed."),
461 "FE304": QCoreApplication.translate(
462 'CodeStyleFixer',
463 "Superfluous blank lines after function decorator removed."),
464 "FE401": QCoreApplication.translate(
465 'CodeStyleFixer',
466 "Imports were put on separate lines."),
467 "FE501": QCoreApplication.translate(
468 'CodeStyleFixer',
469 "Long lines have been shortened."),
470 "FE502": QCoreApplication.translate(
471 'CodeStyleFixer',
472 "Redundant backslash in brackets removed."),
473 "FE701": QCoreApplication.translate(
474 'CodeStyleFixer',
475 "Compound statement corrected."),
476 "FE702": QCoreApplication.translate(
477 'CodeStyleFixer',
478 "Compound statement corrected."),
479 "FE711": QCoreApplication.translate(
480 'CodeStyleFixer',
481 "Comparison to None/True/False corrected."),
482 "FN804": QCoreApplication.translate(
483 'CodeStyleFixer',
484 "'{0}' argument added."),
485 "FN806": QCoreApplication.translate(
486 'CodeStyleFixer',
487 "'{0}' argument removed."),
488 "FW291": QCoreApplication.translate(
489 'CodeStyleFixer',
490 "Whitespace stripped from end of line."),
491 "FW292": QCoreApplication.translate(
492 'CodeStyleFixer',
493 "newline added to end of file."),
494 "FW391": QCoreApplication.translate(
495 'CodeStyleFixer',
496 "Superfluous trailing blank lines removed from end of file."),
497 "FW603": QCoreApplication.translate(
498 'CodeStyleFixer',
499 "'<>' replaced by '!='."),
500
501 "FWRITE_ERROR": QCoreApplication.translate(
502 'CodeStyleFixer',
503 "Could not save the file! Skipping it. Reason: {0}"),
504 }
505
506 _messages_sample_args = {
507 "E201": ["([{"],
508 "E202": ["}])"],
509 "E203": [",;:"],
510 "E211": ["(["],
511 "E231": [",;:"],
512 "E241": [",;:"],
513 "E242": [",;:"],
514 "E302": [1],
515 "E303": [3],
516 "E501": [85, 79],
517 "E711": ["None", "'if cond is None:'"],
518 "E712": ["True", "'if cond is True:' or 'if cond:'"],
519 "E901": ["SyntaxError", "Invalid Syntax"],
520 "D901": ["SyntaxError", "Invalid Syntax"],
521 }
522
523
524 def getTranslatedMessage(message):
525 """
526 Module function to get a translated and formatted message for a
527 given pyflakes message ID.
528
529 @param message the message ID (string)
530 @return translated and formatted message (string)
531 """
532 if isinstance(message, list):
533 message, args = message
534 else:
535 args = []
536 if message in _messages:
537 if isinstance(args, int):
538 # Retranslate with correct plural form
539 return _messages[message](args)
540 else:
541 if message.startswith('F'):
542 prefix = ''
543 else:
544 prefix = message + ' '
545 return prefix + _messages[message].format(*args)
546 elif ' ' in message:
547 # already translated
548 return message
549 else:
550 return QCoreApplication.translate(
551 "CodeStyleFixer", " no message defined for code '{0}'")\
552 .format(message)

eric ide

mercurial