Odoo Help

0

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

By
Morteza
on 4/20/17, 9:50 AM 134 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):

    _inherit="res.users"

    _columns={                

              '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]',

                                    "decimal_point":u'.',

                                    "thousands_sep":u'‚',

                                    "direction":u'rtl'})

            

        # 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),

                                               ('comments','like','openerp-web'),('value','!=',False),

                                               ('value','!=','')],

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

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

            translations_per_module.setdefault(mod,{'messages':[]})

            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}

   


0

IT Libertas

--IT Libertas--
813
| 4 3 7
Saint Petersburg, Russian Federation
--IT Libertas--

Visit us: itlibertas.com

IT Libertas is a team of developers and automation experts to help you to unlock Odoo ERP system's potential. We have been communicating with end users to whom the software became a main business tool since 2012. As a result, we are proud of dozens of successful implementations.

IT Libertas guarantees deadlines predictability and transparent pricing. We rely upon the best international practices and invest in local markets' study. That is why the company's services are in demand of European, Asian, American and African entrepreneurs.

We are open for cooperation and keep searching for new solutions to the end that IT Libertas clients go ahead of the curve, deal with less routine and generate more profit.

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.

Register

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)

Stats

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