prefer-env-translation (ODOO024)
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 calls to the bare _()/_lt() translation functions.
Why is this bad?
Since Odoo 18.0, self.env._() is preferred over the bare _()/_lt() functions.
The rule only applies from Odoo 18.0 on: self.env._ does not exist in earlier versions,
so on an older codebase the bare _() is the only correct call. Configure the targeted
version with the odoo-version setting; without it the rule stays enabled.
Example
Use instead: