Odoo Help


odoo 8: How to get list of languages in module WebClient class

on 4/20/17, 9:50 AM 82 views

I've installed a module that should works with translations defined in the odoo 8. But when i checked the path, there is no defined directories. 

class WebClient(openerpweb.Controller):
    @http.route('/web/webclient/translations', type='json', auth="none")
    def translations(self, mods=None, lang=None):

In the /web/ directory only i18n directory exists and only contains .po files. because i'm new in odoo i think it is not correct in the module. so how i could change this request and fix the problem?

The full source code:

from openerp.osv import osv,fields

from openerp.addons.web import http

import os, platform

from datetime import datetime

openerpweb = http

import werkzeug.local

import itertools

_request_stack = werkzeug.local.LocalStack()

request = _request_stack()

import openerp

class res_users(osv.osv):



              'context_jcalendar': fields.boolean('Jalali Calendar?', help="Using persian numbers and jalali calendar throughout views.")


    _defaults = {

        'context_jcalendar': True,


class WebClient(openerpweb.Controller):

    @http.route('/web/webclient/translations', type='json', auth="none")

    def translations(self, mods=None, lang=None):

        request.disable_db = False

        uid = openerp.SUPERUSER_ID

        if mods is None:

            m = request.registry.get('ir.module.module')

            mods = [x['name'] for x in m.search_read(request.cr, uid,

                [('state','=','installed')], ['name'])]

        if lang is None:

            lang = request.context["lang"]

        res_lang = request.registry.get('res.lang')

        ids = res_lang.search(request.cr, uid, [("code", "=", lang)])

        lang_params = None

        if ids:

            lang_params = res_lang.read(request.cr, uid, ids[0], ["direction", "date_format", "time_format",

                                                "grouping", "decimal_point", "thousands_sep"])

            user_context = request.session.get_context() if request.session._uid else {}

            jcalendar = user_context.get('jcalendar',True)


            lang_params.update({'jcalendar': jcalendar,})

            if jcalendar == True:

                lang_params.update({"grouping" : '[3,0]',





        # Regional languages (ll_CC) must inherit/override their parent lang (ll), but this is

        # done server-side when the language is loaded, so we only need to load the user's lang.

        ir_translation = request.registry.get('ir.translation')

        translations_per_module = {}

        messages = ir_translation.search_read(request.cr, uid, [('module','in',mods),('lang','=',lang),



                                              ['module','src','value','lang'], order='module')

        for mod, msg_group in itertools.groupby(messages, key=operator.itemgetter('module')):


            translations_per_module[mod]['messages'].extend({'id': m['src'],

                                                             'string': m['value']} \

                                                                for m in msg_group)

        return {"modules": translations_per_module,

                "lang_parameters": lang_params}


IT Libertas
On 4/21/17, 6:50 AM

The controller path is not a path on the server: it is just a json request to use.

What are you trying to achieve? Would you like to get the list of languages? If so, you may just search them as self.env['res.lang'].search([]). Have also look at base_update_translations in the base module

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 4/20/17, 9:50 AM
Seen: 82 times
Last updated: 4/21/17, 6:50 AM