Giter Club home page Giter Club logo

Comments (3)

ossimantylahti avatar ossimantylahti commented on June 18, 2024 3

@moylop260 Odoo has a built-in feature that will automatically update all Odoo core modules -- translations included. Therefore, you cannot really create your own customised translations and overwrite Odoo's own translation files with those. You should also be aware that Odoo regularly adds new strings to the modules, so your own translation files would start eventually to be really lagging from them.

Your best bet would be to create your own 3rd party module that inherits Odoo's models and overwrites them with your own functionality -- or in this case field names and their translations.

from odoo.

moylop260 avatar moylop260 commented on June 18, 2024

FYI I followed your advice

e.g. to translate the password message I have created a new module called dummy_i18n

With the following code:

from odoo import http

from odoo.addons.web.controllers.home import Home


class WebHome(Home):
    @http.route("/web/login", type="http", auth="none")
    def web_login(self, redirect=None, **kw):
        res = super().web_login(redirect, **kw)
        if res.qcontext.get("error") == "Wrong login/password":
            res.qcontext["error"] = "Incorrect username or password"
        return res

Another one is to translate the part of the attempts to login:

import contextlib

from odoo import _, models
from odoo.exceptions import AccessDenied, UserError


class ResUsers(models.Model):
    _inherit = "res.users"

    @contextlib.contextmanager
    def _assert_can_auth(self, user=None):
        try:
            with super()._assert_can_auth(user) as res:
                yield res
        except AccessDenied as e:
            if e.name == "Too many login failures, please wait a bit before trying again.":
                cfg = self.env["ir.config_parameter"].sudo()
                min_failures = int(cfg.get_param("base.login_cooldown_after", 5))
                raise AccessDenied(
                    _(
                        "Your account is temporarily locked as a security measure due to %s unsuccessful login attempts."
                        " Please allow 1 minute to pass before trying to login again.",
                        min_failures,
                    )
                )
            raise

Another one to translate the password:

   def _check_password_history(self, password):
        for user in self:
            try:
                res = super()._check_password_history(password)
                return res
            except UserError as e:
                if e.name == "Cannot use the most recent %d passwords" % user.company_id.password_history:
                    raise UserError(_("Please enter a new password, your most recent password cannot be reused"))
                raise

Well, Notice the last one has an issue, my translation team generated by mistake (because of uses self for the super but it needs to use the user variable because the message contains a value custom of the user)

Notice the other ones need a decorator and so on

It looks like an innocent change without logical change but even it could break the logic only to translate a term

Is this the right way to deal with this problem or did I misunderstand?

Your answer will be our guideline so I appreciate your answer here since that it for me is not a good choice

from odoo.

ossimantylahti avatar ossimantylahti commented on June 18, 2024

@moylop260 This is perhaps not the right place to have this discussion, and I'd need to see the whole code in order to dig deeper. But a couple of notes since this could be of public interest.

  1. In order to make an Odoo or your own moduld string translatable is to preceed it with underscore. So instead of raise AccessDenied ("Foobar"), you should write raise AccessDenied (_("Foobar")). And you have done that.
  2. In your code you are comparing values against whole error message text. I do not think this is a good idea. Example:
    if e.name == "Too many login failures, please wait a bit before trying again.":
    And this probably won't work at all:
    if e.name == "Cannot use the most recent %d passwords" % user.company_id.password_history:
  3. I am not sure if Odoo automatically translates http traffic to https traffic. If not, this code block has a problem.
    @http.route("/web/login", type="http", auth="none")
  4. And on the same code block, please note that the user is not authenticated. Thus Odoo does not know his language preferences and would default to system or site default language. Maybe that is the reason your translations do not seem to be working?

from odoo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.