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.
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Akuntansi
- Inventaris
- PoS
- Project
- MRP
Pertanyaan ini telah diberikan tanda
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
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=""
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?
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.
Menikmati diskusi? Jangan hanya membaca, ikuti!
Buat akun sekarang untuk menikmati fitur eksklufi dan agar terlibat dengan komunitas kami!
DaftarPost Terkait | Replies | Tampilan | Aktivitas | |
---|---|---|---|---|
|
1
Mar 25
|
1356 | ||
|
1
Feb 25
|
2842 | ||
product name not changed for all users
Diselesaikan
|
|
2
Feb 25
|
1893 | |
|
1
Mar 24
|
1427 | ||
|
1
Apr 22
|
2343 |