Skip to content

translation-field (ODW8103)

Preview (since 0.16.2.2) · Related issues · View source

Derived from the odoo linter.

Fix is sometimes available.

This rule is unstable and in preview. The --preview flag is required for use.

What it does

Checks for _() translation calls inside field definitions.

Why is this bad?

Field attribute strings (like string= and help=) are translated automatically by Odoo's export machinery; wrapping them in _() is unnecessary and translates them at module-load time, before the user's language is even known.

Example

name = fields.Char(string=_("Name"))

Use instead:

name = fields.Char(string="Name")

Fix safety

The fix unwraps the call, keeping its only argument. It is marked as unsafe because the attribute value changes from a string translated at module-load time to the plain string; that is the point of the rule, but code comparing the value against a translated string would change behavior. No fix is offered when the call takes anything but a single positional argument.