Closed yajo closed 3 years ago
IIUC v14.0 supports passing arguments to translation lookup. https://www.odoo.com/documentation/14.0/reference/translations.html#variables
before 14 _("Your %s %s is shipping") % ("red", "car")
now is _("Your %s %s is shipping", "red", "car")
But the order question remains the same.
My note is for the PR #305, if it can adjust positional string formatting or passing arguments?
Test ok if: _("Your %(color)s %(product)s is shipping", color="red", product="car")
and ko _("Your %s %s is shipping", "red", "car")
Good, I didn't know of that new feature. Indeed we should fail if it's called with more than 1 *args
and ask to use **kwargs
instead.
As one can see in https://github.com/odoo/odoo/issues/29104 (not related to this proposal, but gives an example), there are some sentences which are hard to translate from English to other languages if you can't alter the order of words.
So, my proposal is that we add a linter that ensures that, when a translated string has more than 1 interpolation, it must be expanded with a dict and not a tuple.
Example:
It seems nice in English, but in Spanish you would have to use an unnatural sentence such as
"Su envío, que es de color %s y es un/a %s, está de camino"
.The original code should have been:
So you can translate that into
"Su %(item)s %(color)s está enviándose"
in Spanish.If there's just one
%s
or the string is not translatable, this is not an issue.