Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
4612 Lượt xem

How can I display Product Name in two languages that we use simultaneously in the Product Card of the Inventory App?

For the default language I placed Related Field - product_variant_id.name.

Now I want to place next to the Product Name translated into the second language.


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi isteq1,

Step 1)Install the package googletrans(Alpha version) using the following command:
pip install googletrans==3.1.0a0

Below is the output :- 



Note: You can set the source and destination language per your requirement.
Check googletrans package for all language codes.

Please find code in comment.

I hope this will be helpful. 

Thanks & Regards,
Email: odoo@aktivsoftware.com
Skype: kalpeshmaheshwari

Ảnh đại diện
Huỷ bỏ

Find code here :-

Step 2)
Create an XML File for your new field to be placed in the product view-Below is the code:

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="product_inherit_view" model="ir.ui.view">
<field name="name">product.inherit.view</field>
<field name="model">product.template</field>
<field name="inherit_id" ref="product.product_template_form_view"/>
<field name="arch" type="xml">
<data>
<xpath expr="//field[@name='name']" position="after">
<field name="translated_product"/>
</xpath>
</data>
</field>
</record>
</data>
</odoo>

Step 3)
Create Python File for the logic-Below is the code:

from googletrans import Translator
from odoo import fields, models,api

class Product(models.Model):
_inherit = "product.template"

translated_product = fields.Char(string="",compute="_compute_product_name")

@api.depends('name')
def _compute_product_name(self):
source_language = 'en'
destination_language = 'ar'
main_product_name = self.name
translator = Translator()
result = translator.translate(main_product_name, src=source_language, dest=destination_language)
if main_product_name:
self.translated_product = result.text
else:
self.translated_product=""

Câu trả lời hay nhất

Hi! I want to join this discussion. I produce plants, and for production purposes, I need to display two names: one in my language and one in Latin. My customers use both types of names, so I need the ability to display, sort, and filter in both language variants. Can You help me?

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

Thank you for the detailed response. I would like to clarify some details.
1) I don't need an automatic translation. The bilingual product names are already in the base.
2) I just need to include an additional field with the translated name in the General Information tab of the Product Card.
3) After that, I want to add the Translated Product Name field in the Products list, instead of the Product Name field. This will allow me to sort the products by this field.
4) I would like to see a search by Translated Product Name work as well.
5) Unfortunately I only have a basic knowledge of database editing, so I don't want to put an additional apps and edit the HTML code. I planned to make changes only with the help of Odoo Studio.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 3 25
1627
1
thg 2 25
3081
2
thg 2 25
2040
1
thg 3 24
1593
1
thg 4 22
2451