Comments (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.
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.
@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.
- 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 writeraise AccessDenied (_("Foobar"))
. And you have done that. - 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:
- 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")
- 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)
- [17.0] website: if there is invisble element in a page editor throwing the error in translation HOT 1
- [16.0] Stock: Delivery validation of 1000 lines takes too long and odoo.sh drops it after 15 minutes HOT 1
- [17.0] Project: task changes not auto saved when returning to tasks using keyboard shortcut
- [16.0/17.0] point_of_sale: rounding breaks invoice - $33.00 receipt = $32.99 Invoice (Reproduceable On Runbot)
- [15.0] account: Error computing credit, debit in res.partner when fields added in view with access group
- [17.0] account_accountant: reconciliation error #3949954 HOT 8
- [15.0/16.0] payment: Wire Transfer creates unlimited payment methods
- [15.0] documents : related model link dropped on replace - regression issue HOT 1
- [15.0] point of sale refund of discounted product does not consider the discount
- [17.0] Inventory: unlock and change the done quantity, error raised.
- [17.0] i10n_il: Wrong default tax for purchase
- [14.0] Dynamic domain on Many2many field: the filter does not work on Saved Records.
- [16.0] account: Validation of Xrechnung fails when exported from odoo HOT 1
- [17.0] module: z-index issue obscuring "Click to Start" button in user desktop view in Sign Module
- [17.0] stock: Replenishment slow open view
- [17.0] account_accountant: account_reconcile_wizard.py
- Marketing Mail image added as attatchemnt when sended
- [17.0] l10n_es: Taxes names are not user friendly HOT 9
- [17.0] module: description
- [17.0] module: website - traceback when redirect to website editor
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from odoo.