Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Knjigovodstvo
  • Zaloga
  • PoS
  • Projekt
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

How to load translated fields through the web services ?

Naroči se

Get notified when there's activity on this post

This question has been flagged
producttranslationwebservices
1 Odgovori
6477 Prikazi
Avatar
Chloé Desoutter

Hello,

We're working on integrating OpenERP as backoffice for e-commerce solutions. One important point is to be able to load product descriptions from OpenERP to the multilingual e-commerce website.

For the moment my code looks like

products = o.join(o.search_and_load('product.product', None, None, product_structure()), 'product_tmpl_id', 'product.template', product_template_structure())

which, basically, performs a join between product.product and product.template to load the full product informations and returns a dictionary.

Is there any facility in the webservices to load the translated fields directly or should we implement it ourselves?

If that'd be so, we'd load a translation cache in our middleware and perform string replacements when we get the dictionary.

Any hint?

0
Avatar
Opusti
Avatar
Chloé Desoutter
Avtor Best Answer

Since no one seems to have a hint at hand, I have produced some (quick & dirty) code to perform this operation.

It's not universal, but it is quite straightforward and can be adapted easily to your needs. Its weak point is that it does not translate recursively "join"ed structures.

This code is not at all production-ready! as it does not cache locally the translations. A cache should be added to be ready for production.

  def translate(self, dataset, language_code, model):
    if self.__transcache == None: self._load_tcache()
    langset = self.__transcache[language_code][model]
    for i in dataset:
      id_ = i['id']
      for field in i:
#        print "Seeking field %s with ID %s" % (field, id_)
        if field in langset:
          sid_ = str(id_)
          if sid_ in langset[field]:
#            print "Found translation for %s[%s]:%s" % (model, field, id_)
            i[field] = langset[field][sid_]
    return dataset

  def _load_tcache(self):
    r = self.search_and_load('ir.translation', fields = ['lang', 'module', 'name', 'res_id', 'value'])
    l = {}
    for i in r:
      lng = i['lang']
      nam = i['name'].split(',')
      if (len(nam)<2): continue
      module = nam[0]
      field = nam[1]

      if not lng in l: l[lng] = {}
      if not module in l[lng]: l[lng][module] = {}
      if not field in l[lng][module]: l[lng][module][field] = {}
#      print "Added cache for %s[%s][%s][%s]: %s" % (lng, module, field, i['res_id'], unicode(i['value']).encode('utf-8'))
      l[lng][module][field][str(i['res_id'])] = i['value']
    self.__transcache = l
0
Avatar
Opusti
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Prijavi
Related Posts Odgovori Prikazi Aktivnost
Translate product names
product translation report
Avatar
Avatar
1
apr. 15
8271
How can I translate products name and description?
language product translation
Avatar
Avatar
1
mar. 15
16476
Product Name in two languages simultaneously
product inventory translation Products
Avatar
Avatar
Avatar
3
feb. 25
5463
(^_-)Contacto~Volaris~Directo(-_^)¿Cómo hablar directamente en Volaris?
webservices
Avatar
0
okt. 25
7
How to disable product autocomplete?
product
Avatar
Avatar
Avatar
2
sep. 25
846
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now