Skip to content

translation-too-few-args (ODE8306)

Preview (since 0.16.2.9) · Related issues · View source

Derived from the odoo linter.

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

What it does

Checks for translation calls passing fewer values than the term's printf placeholders require, e.g. _("%s of %s", count).

The rule only applies from Odoo 14.0 on, the version whose translation functions take the interpolation arguments themselves; up to 13.0 translation-contains-variable covers the eager interpolation instead. Configure the version with the odoo-version setting; without it the rule stays enabled.

Why is this bad?

The translation function formats the term with %, and % formatting raises a TypeError at runtime when placeholders are left unfilled.

Example

_("%s of %s", count)

Use instead:

_("%s of %s", count, total)

A translation call given no values of its own is normally left alone: the term is used verbatim (_("100%")) or interpolated afterwards (_("Hello %s") % name). The exception is the lone argument of a raised exception, where neither can happen and the placeholders reach the user as they are:

raise UserError(_("record <%s: (%s)> can not be sent"))

There the count is all that is checked, and only placeholders that are unmistakably placeholders count: _("100% off") reads as prose even though % o is a valid space-flagged conversion.