This question has been flagged
2 Replies
3393 Views

what's the _() function means in  lambda s: _('Blocked')

It's import in:    from odoo import api, fields, models, tools, SUPERUSER_ID, _

Avatar
Discard
Author Best Answer

Thank you!

I find it define in odoo/tools/translate.py as:
_ = GettextAlias()

But GettextAlias is define as a class, not a string type, How can it translate a class to string?


class GettextAlias(object):
    def _get_db(self):
        # find current DB based on thread/worker db name (see netsvc)
        db_name = getattr(threading.currentThread(), 'dbname', None)
        if db_name:
            return odoo.sql_db.db_connect(db_name)
...............
 

Best Regards
Avatar
Discard
Best Answer

Odoo cannot automatically export translatable terms so they must be marked explicitly for export. This is done by wrapping a literal string in a function call. so for python, the wrapping function is odoo._().

NB:
Only literal strings can be marked for exports, not expressions or variables. For situations where strings are formatted, this means the format string must be marked, not the formatted string


Avatar
Discard