Translating messages

EduLint enables translating defect messages to different (natural) languages. This feature can also be used to change wording of selected messages. Currently, EduLint does not provide prepared translations to any other language, but it is possible to create and use own translations. For the sake of keeping the documentation in English, the examples here will show reworded messages, not messages translated to another language.

Message translation format

Translations are specified as lines <message id or symbol> = <translated text>, for example unnecessary-pass = "You shall not (use) pass (here)" (the original message is Unnecessary pass statement).

For messages that show snippets of the checked code, EduLint is able to extract these snippets and place them into the translations at specified spots. For example, redefined-builtin detector could show message "Redefining built-in sum", where sum is the specific name of the redefined function used in the code. A translation for this message could be redefining-builtin = "Name {} shadows a built-in function. Choose another name to avoid bugs and confusion." The built-in name EduLint extracts from the original message will be put in place of the {} Python’s .format method is used to pass the extracts to the new message, so it is also possible to change the order, or use only some arguments.

Some messages do not only use code snippets to dynamically create the message, some also add words based on the code. For example, the message for identical-if-branches-part says Identical code inside all if's branches, move %d lines %s the if., where %s can be before or :code: after. In such case, the translation can look as follows:

identical-if-branches-part = "There are {} identical lines {} of the if branches."
translated_extracts.identical-if-branches-part.2 = { before = "at the start", after = "at the end" }

The number after the checker name indicates which of the extracts should the extract translation apply to. Here, the extracts are numbered from one.

Flake8’s rules do not have symbol, only ID, so the code is used to pair the translation, e.g., E501 = "line is definitely too long". Pylint’s message IDs can also be used for Pylint’s messages.

Setting language translations

The translations can either be specified in a dedicated language file, or directly inside a custom configuration file.

A dedicated language file is a TOML containing just translation pairs in the format described above, for example:

unnecessary-pass = "You shall not (use) pass (here)"
redefining-builtin = "Name {} shadows a built-in function. Choose another name to avoid bugs and confusion."
identical-if-branches-part = "There are {} identical lines {} of the if branches."
translated_extracts.identical-if-branches-part.2 = { before = "at the start", after = "at the end" }
E501 = "line is definitely too long"

A language file to use can be set using the language-file option. The option can be set by any of the means described in the configuration section.

The translations can also be placed directly into a configuration file. For example:

[pylint]
enable = ["unnecessary-pass", "redefining-builtin", "identical-if-branches-part"]

[flake8]
select = "E501"

[language-translations]
unnecessary-pass = "You shall not (use) pass (here)"
redefining-builtin = "Name {} shadows a built-in function. Choose another name to avoid bugs and confusion."
identical-if-branches-part = "There are {} identical lines {} of the if branches."
translated_extracts.identical-if-branches-part.2 = { before = "at the start", after = "at the end" }
E501 = "line is definitely too long"

To create the translations, it is useful to know the original message patterns. For EduLint, the patterns can be found in the checkers’ documentation. Pylint’s patterns can be found in Pylint’s documentation. Flake8’s patterns are not well documented, so the best resource is probably the list that EduLint uses internally.

Note

If EduLint emits a message for which it has no translation, it will use the original (English) message.

Note

Currently, it is not possible to set translations for explanations.