Skip to Content
Menu
This question has been flagged

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}

   


Avatar
Discard
Best Answer

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

Avatar
Discard
Related Posts Replies Views Activity
1
Dec 15
12349
2
Mar 15
4484
1
Dec 22
5280
1
Nov 22
1812
0
Jun 21
2838