Odoo 10 Odoo-ORM从product.template检索翻译后的名称

Odoo 10 Odoo-ORM从product.template检索翻译后的名称,odoo-10,Odoo 10,我想从product.template检索名称: print self.env['product.template'].search([("id", "=", id), ]).name 如何在ORM中获取翻译后的名称?您可以在上下文中传递语言代码,以获取该语言中的特定产品名称。在使用服务器之前,请确保该语言已加载到服务器中。我在您的代码中做了一些更改,以获得德语/Duetsch语言的产品名称 print self.env['product.template'].with_context({'l

我想从product.template检索名称:

print self.env['product.template'].search([("id", "=", id), ]).name

如何在ORM中获取翻译后的名称?

您可以在上下文中传递语言代码,以获取该语言中的特定产品名称。在使用服务器之前,请确保该语言已加载到服务器中。我在您的代码中做了一些更改,以获得德语/Duetsch语言的产品名称

print self.env['product.template'].with_context({'lang': 'de_DE'}).search([("id", "=", id)]).name

我希望这对你有帮助。:)

我认为应该首先在数据库中加载语言。只有加载的语言才能在建议的代码中使用。@AjayChauhan感谢您提出的改进答案的建议。:)