Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

web_debranding on odoo 17 prevents loading the python code translations #78

Open
Mhnd3 opened this issue Jul 22, 2024 · 1 comment
Open

Comments

@Mhnd3
Copy link

Mhnd3 commented Jul 22, 2024

inheriting the "_get_translation" of the "_" object, makes the odoo.http.request.env to be "None" as will as the "cursor" and the "uid", which is used in the "_get_lang" and "_get_cr" methods as one of the ways to lookup the language and the cursor. which eventually leads for the python code translations to not be loaded and logs the following "_logger.debug('translation went wrong for "%r", skipped', source)".
I Tried to comment out the import of the "translate.py" and the translations work fine.

@Mhnd3
Copy link
Author

Mhnd3 commented Jul 30, 2024

@yelizariev This is the fix that worked for me:

import odoo
from odoo.tools.translate import _ ,code_translations, GettextAlias
from .models.ir_translation import debrand
import inspect
import logging
_logger = logging.getLogger(__name__)

def _get_translation(self, source, module=None):
    try:
        frame = inspect.currentframe().f_back.f_back
        lang = self._get_lang(frame)
        if lang and lang != 'en_US':
            if not module:
                path = inspect.getfile(frame)
                path_info = odoo.modules.get_resource_from_path(path)
                module = path_info[0] if path_info else 'base'
            gpt = code_translations.get_python_translations(module, lang).get(source, source)
            return gpt
        else:
            _logger.debug('no translation language detected, skipping translation for "%r" ', source)
    except Exception:
        _logger.debug('translation went wrong for "%r", skipped', source)

    frame = inspect.currentframe().f_back.f_back
    
    try:
        (cr, dummy) = _._get_cr(frame, allow_create=False)
    except AttributeError:
        return source
    try:
        uid = self._get_uid(frame)
    except Exception:
        return source
    if cr and uid:
        env = odoo.api.Environment(cr, uid, {})
        source = debrand(env, source)

    return source


_._get_translation = _get_translation.__get__(_, GettextAlias)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant