[IMP] core: Environment._ for translations

odoo/odoo#174844

closes odoo/documentation#10421

Related: odoo/enterprise#67528
Signed-off-by: Krzysztof Magusiak (krma) <krma@odoo.com>
This commit is contained in:
Krzysztof Magusiak (krma)
2024-07-29 12:41:46 +00:00
parent 16c6c0f492
commit c6208a51ef
3 changed files with 45 additions and 12 deletions

View File

@@ -725,14 +725,10 @@ they can and will be removed !
Use translation method correctly
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Odoo uses a GetText-like method named "underscore" ``_( )`` to indicate that
a static string used in the code needs to be translated at runtime using the
language of the context. This pseudo-method is accessed within your code by
importing as follows:
.. code-block:: python
from odoo import _
Odoo uses a GetText-like method named "underscore" ``_()`` to indicate that
a static string used in the code needs to be translated at runtime.
That method is available at ``self.env._`` using the language of the
environment.
A few very important rules must be followed when using it, in order for it to
work and to avoid filling the translations with useless junk.
@@ -744,10 +740,12 @@ field.
The method accepts optional positional or named parameter
The rule is very simple: calls to the underscore method should always be in
the form ``_('literal string')`` and nothing else:
the form ``self.env._('literal string')`` and nothing else:
.. code-block:: python
_ = self.env._
# good: plain strings
error = _('This record is locked!')